





import unittest

from transformers import EsmConfig, is_torch_available
from transformers.testing_utils import TestCasePlus, require_torch, slow, torch_device

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
    import torch

    from transformers.models.esm.modeling_esmfold import EsmForProteinFolding







class    __snake_case	:





       '''simple docstring'''







       def __init__(  self			:   List[str]							,    A			:   Any							,    A			:   List[Any]=13							,    A			:   str=7							,    A			:   List[str]=False							,    A			:   Union[str, Any]=True							,    A			:   int=False							,    A			:   List[Any]=False							,    A			:   Optional[Any]=19							,    A			:   int=32							,    A			:   Union[str, Any]=5							,    A			:   List[str]=4							,    A			:   Optional[Any]=37							,    A			:   List[Any]="gelu"							,    A			:   Any=0.1							,    A			:   Any=0.1							,    A			:   List[Any]=512							,    A			:   Dict=16							,    A			:   Union[str, Any]=2							,    A			:   Tuple=0.02							,    A			:   List[str]=3							,    A			:   int=4							,    A			:   Dict=None							,    ):
         __snake_case:						Any			  =						parent
         __snake_case:						List[Any]			  =						batch_size
         __snake_case:						Tuple			  =						seq_length
         __snake_case:						Optional[int]			  =						is_training
         __snake_case:						Tuple			  =						use_input_mask
         __snake_case:						Any			  =						use_token_type_ids
         __snake_case:						Union[str, Any]			  =						use_labels
         __snake_case:						Optional[Any]			  =						vocab_size
         __snake_case:						List[str]			  =						hidden_size
         __snake_case:						int			  =						num_hidden_layers
         __snake_case:						int			  =						num_attention_heads
         __snake_case:						int			  =						intermediate_size
         __snake_case:						Dict			  =						hidden_act
         __snake_case:						Dict			  =						hidden_dropout_prob
         __snake_case:						int			  =						attention_probs_dropout_prob
         __snake_case:						List[Any]			  =						max_position_embeddings
         __snake_case:						str			  =						type_vocab_size
         __snake_case:						Dict			  =						type_sequence_label_size
         __snake_case:						Optional[Any]			  =						initializer_range
         __snake_case:						List[str]			  =						num_labels
         __snake_case:						Any			  =						num_choices
         __snake_case:						List[str]			  =						scope




       def 							UpperCAmelCase__			(  self			:   str		):
         __snake_case:						List[str]			  =						ids_tensor([self.batch_size, self.seq_length]							,    self.vocab_size		)

         __snake_case:						List[Any]			  =						None
         if self.use_input_mask:
           __snake_case:						Union[str, Any]			  =						random_attention_mask([self.batch_size, self.seq_length]		)

         __snake_case:						str			  =						None
         __snake_case:						List[Any]			  =						None
         __snake_case:						Any			  =						None
         if self.use_labels:
           __snake_case:						List[Any]			  =						ids_tensor([self.batch_size]							,    self.type_sequence_label_size		)
           __snake_case:						str			  =						ids_tensor([self.batch_size, self.seq_length]							,    self.num_labels		)
           __snake_case:						Dict			  =						ids_tensor([self.batch_size]							,    self.num_choices		)

         __snake_case:						Dict			  =						self.get_config()

         return config, input_ids, input_mask, sequence_labels, token_labels, choice_labels




       def 							UpperCAmelCase__			(  self			:   Optional[int]		):
         __snake_case:						int			  =						EsmConfig(
             vocab_size=33							,    hidden_size=self.hidden_size							,    pad_token_id=1							,    num_hidden_layers=self.num_hidden_layers							,    num_attention_heads=self.num_attention_heads							,    intermediate_size=self.intermediate_size							,    hidden_act=self.hidden_act							,    hidden_dropout_prob=self.hidden_dropout_prob							,    attention_probs_dropout_prob=self.attention_probs_dropout_prob							,    max_position_embeddings=self.max_position_embeddings							,    type_vocab_size=self.type_vocab_size							,    initializer_range=self.initializer_range							,    is_folding_model=snake_case__							,    esmfold_config={"""trunk""": {"""num_blocks""": 2}, """fp16_esm""": False}							,    )
         return config




       def 							UpperCAmelCase__			(  self			:   int							,    A			:   List[Any]							,    A			:   str							,    A			:   Tuple							,    A			:   Any							,    A			:   Optional[int]							,    A			:   List[str]		):
         __snake_case:						Dict			  =						EsmForProteinFolding(config=snake_case__		).float()
         model.to(snake_case__		)
         model.eval()
         __snake_case:						Optional[Any]			  =						model(snake_case__							,    attention_mask=snake_case__		)
         __snake_case:						Optional[Any]			  =						model(snake_case__		)
         __snake_case:						Dict			  =						model(snake_case__		)

         self.parent.assertEqual(result.positions.shape							,    (8, self.batch_size, self.seq_length, 14, 3)		)
         self.parent.assertEqual(result.angles.shape							,    (8, self.batch_size, self.seq_length, 7, 2)		)






       def 							UpperCAmelCase__			(  self			:   Optional[int]		):
         __snake_case:						Any			  =						self.prepare_config_and_inputs()
         (
             __snake_case 
         ):						Optional[int]			  =						config_and_inputs
         __snake_case:						Union[str, Any]			  =						{"input_ids": input_ids, "attention_mask": input_mask}
         return config, inputs_dict







@require_torch
class    __snake_case	(							A_       ,      A_       ,      unittest.TestCase      ):





       '''simple docstring'''







       lowerCAmelCase__						=					False

       lowerCAmelCase__						=					(EsmForProteinFolding,) if is_torch_available() else ()
       lowerCAmelCase__						=					()
       lowerCAmelCase__						=					{} if is_torch_available() else {}
       lowerCAmelCase__						=					False




       def 							UpperCAmelCase__			(  self			:   Union[str, Any]		):
         __snake_case:						str			  =						EsmFoldModelTester(self		)
         __snake_case:						Any			  =						ConfigTester(self							,    config_class=snake_case__							,    hidden_size=37		)




       def 							UpperCAmelCase__			(  self			:   List[str]		):
         self.config_tester.run_common_tests()




       def 							UpperCAmelCase__			(  self			:   Optional[int]		):
         __snake_case:						Tuple			  =						self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_model(*snake_case__		)




       @unittest.skip("""Does not support attention outputs"""		)
       def 							UpperCAmelCase__			(  self			:   Tuple		):
         pass




       @unittest.skip
       def 							UpperCAmelCase__			(  self			:   str		):
         pass




       @unittest.skip("""Esm does not support embedding resizing"""		)
       def 							UpperCAmelCase__			(  self			:   str		):
         pass




       @unittest.skip("""Esm does not support embedding resizing"""		)
       def 							UpperCAmelCase__			(  self			:   Union[str, Any]		):
         pass




       @unittest.skip("""ESMFold does not support passing input embeds!"""		)
       def 							UpperCAmelCase__			(  self			:   Any		):
         pass




       @unittest.skip("""ESMFold does not support head pruning."""		)
       def 							UpperCAmelCase__			(  self			:   List[str]		):
         pass




       @unittest.skip("""ESMFold does not support head pruning."""		)
       def 							UpperCAmelCase__			(  self			:   int		):
         pass




       @unittest.skip("""ESMFold does not support head pruning."""		)
       def 							UpperCAmelCase__			(  self			:   Optional[int]		):
         pass




       @unittest.skip("""ESMFold does not support head pruning."""		)
       def 							UpperCAmelCase__			(  self			:   Dict		):
         pass




       @unittest.skip("""ESMFold does not support head pruning."""		)
       def 							UpperCAmelCase__			(  self			:   List[Any]		):
         pass




       @unittest.skip("""ESMFold does not output hidden states in the normal way."""		)
       def 							UpperCAmelCase__			(  self			:   List[str]		):
         pass




       @unittest.skip("""ESMfold does not output hidden states in the normal way."""		)
       def 							UpperCAmelCase__			(  self			:   Any		):
         pass




       @unittest.skip("""ESMFold only has one output format."""		)
       def 							UpperCAmelCase__			(  self			:   Optional[Any]		):
         pass




       @unittest.skip("""This test doesn't work for ESMFold and doesn't test core functionality"""		)
       def 							UpperCAmelCase__			(  self			:   Optional[int]		):
         pass




       @unittest.skip("""ESMFold does not support input chunking."""		)
       def 							UpperCAmelCase__			(  self			:   Any		):
         pass




       @unittest.skip("""ESMFold doesn't respect you and it certainly doesn't respect your initialization arguments."""		)
       def 							UpperCAmelCase__			(  self			:   Dict		):
         pass




       @unittest.skip("""ESMFold doesn't support torchscript compilation."""		)
       def 							UpperCAmelCase__			(  self			:   List[str]		):
         pass




       @unittest.skip("""ESMFold doesn't support torchscript compilation."""		)
       def 							UpperCAmelCase__			(  self			:   List[Any]		):
         pass




       @unittest.skip("""ESMFold doesn't support torchscript compilation."""		)
       def 							UpperCAmelCase__			(  self			:   Optional[int]		):
         pass




       @unittest.skip("""ESMFold doesn't support data parallel."""		)
       def 							UpperCAmelCase__			(  self			:   str		):
         pass






       @unittest.skip("""Will be fixed soon by reducing the size of the model used for common tests."""		)
       def 							UpperCAmelCase__			(  self			:   Union[str, Any]		):
         pass







@require_torch
class    __snake_case	(							A_      ):





       '''simple docstring'''







       @slow
       def 							UpperCAmelCase__			(  self			:   Any		):
         __snake_case:						List[Any]			  =						EsmForProteinFolding.from_pretrained("""facebook/esmfold_v1"""		).float()
         model.eval()
         __snake_case:						List[Any]			  =						torch.tensor([[0, 6, 4, 13, 5, 4, 16, 12, 11, 7, 2]]		)
         __snake_case:						Optional[Any]			  =						model(snake_case__		)["positions"]
         __snake_case:						List[str]			  =						torch.tensor([2.5828, 0.7993, -10.9334]							,    dtype=torch.floataa		)
         self.assertTrue(torch.allclose(position_outputs[0, 0, 0, 0]							,    snake_case__							,    atol=1E-4		)		)













import math







def       A__							(   SCREAMING_SNAKE_CASE__)       ->   int:

  if not isinstance(SCREAMING_SNAKE_CASE__ , SCREAMING_SNAKE_CASE__):
    __snake_case:						Optional[int]			  =						F'''Input value of [number={number}] must be an integer'''
    raise TypeError(SCREAMING_SNAKE_CASE__)

  if number < 1:
    __snake_case:						Optional[int]			  =						F'''Input value of [number={number}] must be > 0'''
    raise ValueError(SCREAMING_SNAKE_CASE__)
  elif number == 1:
    return 3
  elif number == 2:
    return 5
  else:
    __snake_case:						List[Any]			  =						int(math.log(number // 3 , 2)) + 2

    __snake_case:						str			  =						[3, 5]
    __snake_case:						int			  =						2
    __snake_case:						List[str]			  =						3
    for block in range(1 , SCREAMING_SNAKE_CASE__):
      for _ in range(SCREAMING_SNAKE_CASE__):
        proth_list.append(2 ** (block + 1) + proth_list[proth_index - 1])
        proth_index += 1
      increment *= 2

  return proth_list[number - 1]


if __name__ == "__main__":
      import doctest

      doctest.testmod()

      for number in range(11):
            __UpperCAmelCase	:       Optional[int]    	=							0
            try:
                  __UpperCAmelCase	:       int    	=							proth(number)
            except ValueError:
                  print(f'ValueError: there is no {number}th Proth number')
                  continue

            print(f'The {number}th Proth number: {value}')






