

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			:

  def __init__(  self		:			Union[str, Any]					,A		:			str					,A		:			int=13					,A		:			Union[str, Any]=7					,A		:			str=False					,A		:			Union[str, Any]=True					,A		:			Optional[Any]=False					,A		:			str=False					,A		:			List[str]=19					,A		:			str=32					,A		:			str=5					,A		:			str=4					,A		:			Optional[int]=37					,A		:			Any="gelu"					,A		:			Optional[int]=0.1					,A		:			Optional[Any]=0.1					,A		:			Tuple=512					,A		:			str=16					,A		:			int=2					,A		:			Union[str, Any]=0.0_2					,A		:			Union[str, Any]=3					,A		:			str=4					,A		:			List[str]=None					,):






   '''simple docstring'''
   UpperCAmelCase__					:  Any					   =					parent
   UpperCAmelCase__					:  Tuple					   =					batch_size
   UpperCAmelCase__					:  Tuple					   =					seq_length
   UpperCAmelCase__					:  Any					   =					is_training
   UpperCAmelCase__					:  Optional[int]					   =					use_input_mask
   UpperCAmelCase__					:  Any					   =					use_token_type_ids
   UpperCAmelCase__					:  Tuple					   =					use_labels
   UpperCAmelCase__					:  Optional[Any]					   =					vocab_size
   UpperCAmelCase__					:  str					   =					hidden_size
   UpperCAmelCase__					:  Optional[Any]					   =					num_hidden_layers
   UpperCAmelCase__					:  Optional[Any]					   =					num_attention_heads
   UpperCAmelCase__					:  List[Any]					   =					intermediate_size
   UpperCAmelCase__					:  Tuple					   =					hidden_act
   UpperCAmelCase__					:  List[str]					   =					hidden_dropout_prob
   UpperCAmelCase__					:  Optional[int]					   =					attention_probs_dropout_prob
   UpperCAmelCase__					:  List[str]					   =					max_position_embeddings
   UpperCAmelCase__					:  Any					   =					type_vocab_size
   UpperCAmelCase__					:  List[Any]					   =					type_sequence_label_size
   UpperCAmelCase__					:  str					   =					initializer_range
   UpperCAmelCase__					:  List[Any]					   =					num_labels
   UpperCAmelCase__					:  List[str]					   =					num_choices
   UpperCAmelCase__					:  List[Any]					   =					scope

  def    __lowercase       (  self		:			int    ):






   '''simple docstring'''
   UpperCAmelCase__					:  Tuple					   =					ids_tensor([self.batch_size, self.seq_length]					,self.vocab_size    )

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

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

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

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

  def    __lowercase       (  self		:			Optional[Any]    ):






   '''simple docstring'''
   UpperCAmelCase__					:  str					   =					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=A					,esmfold_config={"""trunk""": {"""num_blocks""": 2}, """fp16_esm""": False}					,)
   return config

  def    __lowercase       (  self		:			Union[str, Any]					,A		:			Tuple					,A		:			int					,A		:			Tuple					,A		:			Optional[Any]					,A		:			Optional[Any]					,A		:			Tuple    ):






   '''simple docstring'''
   UpperCAmelCase__					:  Tuple					   =					EsmForProteinFolding(config=A    ).float()
   model.to(A    )
   model.eval()
   UpperCAmelCase__					:  Dict					   =					model(A					,attention_mask=A    )
   UpperCAmelCase__					:  List[Any]					   =					model(A    )
   UpperCAmelCase__					:  int					   =					model(A    )

   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    __lowercase       (  self		:			str    ):






   '''simple docstring'''
   UpperCAmelCase__					:  List[str]					   =					self.prepare_config_and_inputs()
   (
       UpperCAmelCase__      
   )					:  Union[str, Any]					   =					config_and_inputs
   UpperCAmelCase__					:  Tuple					   =					{"""input_ids""": input_ids, """attention_mask""": input_mask}
   return config, inputs_dict







@require_torch
class      __lowercase			(    __lowerCamelCase	,			__lowerCamelCase	,			unittest.TestCase					):
  snake_case_				       =       False

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

  def    __lowercase       (  self		:			Union[str, Any]    ):






   '''simple docstring'''
   UpperCAmelCase__					:  Tuple					   =					EsmFoldModelTester(self    )
   UpperCAmelCase__					:  int					   =					ConfigTester(self					,config_class=A					,hidden_size=37    )

  def    __lowercase       (  self		:			int    ):






   '''simple docstring'''
   self.config_tester.run_common_tests()

  def    __lowercase       (  self		:			Any    ):






   '''simple docstring'''
   UpperCAmelCase__					:  Dict					   =					self.model_tester.prepare_config_and_inputs()
   self.model_tester.create_and_check_model(*A    )

  @unittest.skip("""Does not support attention outputs"""    )
  def    __lowercase       (  self		:			str    ):






   '''simple docstring'''
   pass

  @unittest.skip
  def    __lowercase       (  self		:			Any    ):






   '''simple docstring'''
   pass

  @unittest.skip("""Esm does not support embedding resizing"""    )
  def    __lowercase       (  self		:			Tuple    ):






   '''simple docstring'''
   pass

  @unittest.skip("""Esm does not support embedding resizing"""    )
  def    __lowercase       (  self		:			List[str]    ):






   '''simple docstring'''
   pass

  @unittest.skip("""ESMFold does not support passing input embeds!"""    )
  def    __lowercase       (  self		:			Union[str, Any]    ):






   '''simple docstring'''
   pass

  @unittest.skip("""ESMFold does not support head pruning."""    )
  def    __lowercase       (  self		:			str    ):






   '''simple docstring'''
   pass

  @unittest.skip("""ESMFold does not support head pruning."""    )
  def    __lowercase       (  self		:			str    ):






   '''simple docstring'''
   pass

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






   '''simple docstring'''
   pass

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






   '''simple docstring'''
   pass

  @unittest.skip("""ESMFold does not support head pruning."""    )
  def    __lowercase       (  self		:			Any    ):






   '''simple docstring'''
   pass

  @unittest.skip("""ESMFold does not output hidden states in the normal way."""    )
  def    __lowercase       (  self		:			str    ):






   '''simple docstring'''
   pass

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






   '''simple docstring'''
   pass

  @unittest.skip("""ESMFold only has one output format."""    )
  def    __lowercase       (  self		:			str    ):






   '''simple docstring'''
   pass

  @unittest.skip("""This test doesn't work for ESMFold and doesn't test core functionality"""    )
  def    __lowercase       (  self		:			int    ):






   '''simple docstring'''
   pass

  @unittest.skip("""ESMFold does not support input chunking."""    )
  def    __lowercase       (  self		:			int    ):






   '''simple docstring'''
   pass

  @unittest.skip("""ESMFold doesn't respect you and it certainly doesn't respect your initialization arguments."""    )
  def    __lowercase       (  self		:			List[str]    ):






   '''simple docstring'''
   pass

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






   '''simple docstring'''
   pass

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






   '''simple docstring'''
   pass

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






   '''simple docstring'''
   pass

  @unittest.skip("""ESMFold doesn't support data parallel."""    )
  def    __lowercase       (  self		:			Optional[Any]    ):






   '''simple docstring'''
   pass




  @unittest.skip("""Will be fixed soon by reducing the size of the model used for common tests."""    )
  def    __lowercase       (  self		:			int    ):






   '''simple docstring'''
   pass







@require_torch
class      __lowercase			(    __lowerCamelCase					):

  @slow
  def    __lowercase       (  self		:			List[Any]    ):






   '''simple docstring'''
   UpperCAmelCase__					:  Any					   =					EsmForProteinFolding.from_pretrained("""facebook/esmfold_v1"""    ).float()
   model.eval()
   UpperCAmelCase__					:  Optional[Any]					   =					torch.tensor([[0, 6, 4, 13, 5, 4, 16, 12, 11, 7, 2]]    )
   UpperCAmelCase__					:  Tuple					   =					model(A    )["""positions"""]
   UpperCAmelCase__					:  Optional[int]					   =					torch.tensor([2.5_8_2_8, 0.7_9_9_3, -10.9_334]					,dtype=torch.floataa    )
   self.assertTrue(torch.allclose(position_outputs[0, 0, 0, 0]					,A					,atol=1e-4    )    )








"""simple docstring"""




import random
from typing import Any
def   lowerCAmelCase						(					__UpperCamelCase      ):
 '''simple docstring'''





 for _ in range(len(__UpperCamelCase      )      ):
  UpperCAmelCase__					:  Dict					   =					random.randint(0							,    len(__UpperCamelCase      ) - 1      )
  UpperCAmelCase__					:  Tuple					   =					random.randint(0							,    len(__UpperCamelCase      ) - 1      )
  UpperCAmelCase__   ,      UpperCAmelCase__					:  int					   =					data[b], data[a]
 return data


if __name__ == "__main__":
      __UpperCAmelCase =				[0, 1, 2, 3, 4, 5, 6, 7]
      __UpperCAmelCase =				['python', 'says', 'hello', '!']
      print('Fisher-Yates Shuffle:')
      print('List', integers, strings)
      print('FY Shuffle', fisher_yates_shuffle(integers), fisher_yates_shuffle(strings))





