




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 						__lowercase		:




      """simple docstring"""





      def __init__(				self    ,				A    ,				A=1_3    ,				A=7    ,				A=False    ,				A=True    ,				A=False    ,				A=False    ,				A=1_9    ,				A=3_2    ,				A=5    ,				A=4    ,				A=3_7    ,				A="gelu"    ,				A=0.1    ,				A=0.1    ,				A=5_1_2    ,				A=1_6    ,				A=2    ,				A=0.02    ,				A=3    ,				A=4    ,				A=None    ,				)		->    Optional[int]:
         snake_case				:    List[Any]           =	parent
         snake_case				:    Dict           =	batch_size
         snake_case				:    Any           =	seq_length
         snake_case				:    str           =	is_training
         snake_case				:    str           =	use_input_mask
         snake_case				:    Any           =	use_token_type_ids
         snake_case				:    Dict           =	use_labels
         snake_case				:    Tuple           =	vocab_size
         snake_case				:    Any           =	hidden_size
         snake_case				:    List[Any]           =	num_hidden_layers
         snake_case				:    Dict           =	num_attention_heads
         snake_case				:    Dict           =	intermediate_size
         snake_case				:    str           =	hidden_act
         snake_case				:    List[Any]           =	hidden_dropout_prob
         snake_case				:    str           =	attention_probs_dropout_prob
         snake_case				:    List[str]           =	max_position_embeddings
         snake_case				:    Optional[Any]           =	type_vocab_size
         snake_case				:    Dict           =	type_sequence_label_size
         snake_case				:    Tuple           =	initializer_range
         snake_case				:    List[str]           =	num_labels
         snake_case				:    str           =	num_choices
         snake_case				:    Tuple           =	scope

      def      UpperCAmelCase				(				self     )		->    Optional[Any]:
         snake_case				:    Optional[Any]           =	ids_tensor([self.batch_size, self.seq_length]    ,				self.vocab_size     )

         snake_case				:    Dict           =	None
         if self.use_input_mask:
            snake_case				:    List[Any]           =	random_attention_mask([self.batch_size, self.seq_length]     )

         snake_case				:    List[Any]           =	None
         snake_case				:    Tuple           =	None
         snake_case				:    str           =	None
         if self.use_labels:
            snake_case				:    str           =	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				:    Optional[Any]           =	ids_tensor([self.batch_size]    ,				self.num_choices     )

         snake_case				:    Optional[int]           =	self.get_config()

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

      def      UpperCAmelCase				(				self     )		->    int:
         snake_case				:    Any           =	EsmConfig(
             vocab_size=3_3    ,				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=A    ,				esmfold_config={"""trunk""": {"""num_blocks""": 2}, """fp16_esm""": False}    ,				)
         return config

      def      UpperCAmelCase				(				self    ,				A    ,				A    ,				A    ,				A    ,				A    ,				A     )		->    List[str]:
         snake_case				:    Tuple           =	EsmForProteinFolding(config=A     ).float()
         model.to(A     )
         model.eval()
         snake_case				:    List[str]           =	model(A    ,				attention_mask=A     )
         snake_case				:    str           =	model(A     )
         snake_case				:    List[Any]           =	model(A     )

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

      def      UpperCAmelCase				(				self     )		->    List[Any]:
         snake_case				:    int           =	self.prepare_config_and_inputs()
         (
             (
             snake_case
         )     , (
             snake_case
         )     , (
             snake_case
         )     , (
             snake_case
         )     , (
             snake_case
         )     , (
             snake_case
         )     , 
         )				:    List[str]           =	config_and_inputs
         snake_case				:    List[Any]           =	{"""input_ids""": input_ids, """attention_mask""": input_mask}
         return config, inputs_dict




@require_torch
class 						__lowercase		(UpperCamelCase__					,		UpperCamelCase__					,		unittest.TestCase							):




      """simple docstring"""





      _snake_case												=						False

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

      def      UpperCAmelCase				(				self     )		->    Union[str, Any]:
         snake_case				:    List[Any]           =	EsmFoldModelTester(self     )
         snake_case				:    Tuple           =	ConfigTester(self    ,				config_class=A    ,				hidden_size=3_7     )

      def      UpperCAmelCase				(				self     )		->    Dict:
         self.config_tester.run_common_tests()

      def      UpperCAmelCase				(				self     )		->    Union[str, Any]:
         snake_case				:    int           =	self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_model(*A     )

      @unittest.skip("""Does not support attention outputs"""     )
      def      UpperCAmelCase				(				self     )		->    Optional[int]:
         pass

      @unittest.skip
      def      UpperCAmelCase				(				self     )		->    Optional[int]:
         pass

      @unittest.skip("""Esm does not support embedding resizing"""     )
      def      UpperCAmelCase				(				self     )		->    Dict:
         pass

      @unittest.skip("""Esm does not support embedding resizing"""     )
      def      UpperCAmelCase				(				self     )		->    Optional[Any]:
         pass

      @unittest.skip("""ESMFold does not support passing input embeds!"""     )
      def      UpperCAmelCase				(				self     )		->    List[Any]:
         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     )		->    Optional[Any]:
         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     )		->    List[str]:
         pass

      @unittest.skip("""ESMFold does not support head pruning."""     )
      def      UpperCAmelCase				(				self     )		->    Optional[Any]:
         pass

      @unittest.skip("""ESMFold does not output hidden states in the normal way."""     )
      def      UpperCAmelCase				(				self     )		->    List[Any]:
         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[int]:
         pass

      @unittest.skip("""This test doesn't work for ESMFold and doesn't test core functionality"""     )
      def      UpperCAmelCase				(				self     )		->    Dict:
         pass

      @unittest.skip("""ESMFold does not support input chunking."""     )
      def      UpperCAmelCase				(				self     )		->    int:
         pass

      @unittest.skip("""ESMFold doesn't respect you and it certainly doesn't respect your initialization arguments."""     )
      def      UpperCAmelCase				(				self     )		->    int:
         pass

      @unittest.skip("""ESMFold doesn't support torchscript compilation."""     )
      def      UpperCAmelCase				(				self     )		->    str:
         pass

      @unittest.skip("""ESMFold doesn't support torchscript compilation."""     )
      def      UpperCAmelCase				(				self     )		->    Any:
         pass

      @unittest.skip("""ESMFold doesn't support torchscript compilation."""     )
      def      UpperCAmelCase				(				self     )		->    Tuple:
         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     )		->    Dict:
         pass




@require_torch
class 						__lowercase		(UpperCamelCase__							):




      """simple docstring"""





      @slow
      def      UpperCAmelCase				(				self     )		->    List[str]:
         snake_case				:    int           =	EsmForProteinFolding.from_pretrained("""facebook/esmfold_v1"""     ).float()
         model.eval()
         snake_case				:    Any           =	torch.tensor([[0, 6, 4, 1_3, 5, 4, 1_6, 1_2, 1_1, 7, 2]]     )
         snake_case				:    Dict           =	model(A     )["""positions"""]
         snake_case				:    Tuple           =	torch.tensor([2.58_28, 0.79_93, -10.93_34]    ,				dtype=torch.floataa     )
         self.assertTrue(torch.allclose(position_outputs[0, 0, 0, 0]    ,				A    ,				atol=1e-4     )     )











# using dfs for finding eulerian path traversal




def 						SCREAMING_SNAKE_CASE__ (   lowercase						,lowercase						,lowercase						,lowercase=None					)  ->       Any:
   snake_case				:    Union[str, Any]           =	(path or []) + [u]
   for v in graph[u]:
      if visited_edge[u][v] is False:
         snake_case     , snake_case				:    int           =	True, True
         snake_case				:    List[Any]           =	dfs(lowercase						,lowercase						,lowercase						,lowercase					)
   return path




def 						SCREAMING_SNAKE_CASE__ (   lowercase						,lowercase					)  ->       Tuple:
   snake_case				:    Union[str, Any]           =	0
   snake_case				:    Union[str, Any]           =	-1
   for i in range(lowercase					):
      if i not in graph.keys():
         continue
      if len(graph[i]					) % 2 == 1:
         odd_degree_nodes += 1
         snake_case				:    str           =	i
   if odd_degree_nodes == 0:
      return 1, odd_node
   if odd_degree_nodes == 2:
      return 2, odd_node
   return 3, odd_node




def 						SCREAMING_SNAKE_CASE__ (   lowercase						,lowercase					)  ->       List[str]:
   snake_case				:    Tuple           =	[[False for _ in range(max_node + 1					)] for _ in range(max_node + 1					)]
   snake_case     , snake_case				:    Any           =	check_circuit_or_path(lowercase						,lowercase					)
   if check == 3:
      print("""graph is not Eulerian"""					)
      print("""no path"""					)
      return
   snake_case				:    str           =	1
   if check == 2:
      snake_case				:    Optional[int]           =	odd_node
      print("""graph has a Euler path"""					)
   if check == 1:
      print("""graph has a Euler cycle"""					)
   snake_case				:    Dict           =	dfs(lowercase						,lowercase						,lowercase					)
   print(lowercase					)




def 						SCREAMING_SNAKE_CASE__ (   )  ->       Optional[Any]:
   snake_case				:    Union[str, Any]           =	{1: [2, 3, 4], 2: [1, 3], 3: [1, 2], 4: [1, 5], 5: [4]}
   snake_case				:    Optional[int]           =	{1: [2, 3, 4, 5], 2: [1, 3], 3: [1, 2], 4: [1, 5], 5: [1, 4]}
   snake_case				:    Optional[int]           =	{1: [2, 3, 4], 2: [1, 3, 4], 3: [1, 2], 4: [1, 2, 5], 5: [4]}
   snake_case				:    List[Any]           =	{1: [2, 3], 2: [1, 3], 3: [1, 2]}
   snake_case				:    Tuple           =	{
       1: [],
       2: []
       # all degree is zero
   }
   snake_case				:    Tuple           =	10
   check_euler(lowercase						,lowercase					)
   check_euler(lowercase						,lowercase					)
   check_euler(lowercase						,lowercase					)
   check_euler(lowercase						,lowercase					)
   check_euler(lowercase						,lowercase					)


if __name__ == "__main__":
       main()





