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

       lowerCamelCase		:	int							=      None
       if self.use_input_mask:
        lowerCamelCase		:	int							=      random_attention_mask([self.batch_size, self.seq_length]      )

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

       lowerCamelCase		:	int							=      self.get_config()

       return config, input_ids, input_mask, sequence_labels, token_labels, choice_labels
      def 						UpperCamelCase__							(      self      ):
       lowerCamelCase		:	str							=      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=__magic_name__    ,  esmfold_config={"""trunk""": {"""num_blocks""": 2}, """fp16_esm""": False}    ,  )
       return config
      def 						UpperCamelCase__							(      self    ,  __magic_name__    ,  __magic_name__    ,  __magic_name__    ,  __magic_name__    ,  __magic_name__    ,  __magic_name__      ):
       lowerCamelCase		:	Optional[int]							=      EsmForProteinFolding(config=__magic_name__      ).float()
       model.to(__magic_name__      )
       model.eval()
       lowerCamelCase		:	Any							=      model(__magic_name__    ,  attention_mask=__magic_name__      )
       lowerCamelCase		:	List[str]							=      model(__magic_name__      )
       lowerCamelCase		:	str							=      model(__magic_name__      )

       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      ):
       lowerCamelCase		:	str							=      self.prepare_config_and_inputs()
       (
           (
           lowerCamelCase
       )			,    (
           lowerCamelCase
       )			,    (
           lowerCamelCase
       )			,    (
           lowerCamelCase
       )			,    (
           lowerCamelCase
       )			,    (
           lowerCamelCase
       )			,    
       )		:	Union[str, Any]							=      config_and_inputs
       lowerCamelCase		:	List[str]							=      {"""input_ids""": input_ids, """attention_mask""": input_mask}
       return config, inputs_dict





@require_torch
class 							A__		(	__SCREAMING_SNAKE_CASE  ,   __SCREAMING_SNAKE_CASE  ,   unittest.TestCase):
      _UpperCAmelCase				:    List[Any]           =			False

      _UpperCAmelCase				:    Optional[int]           =			(EsmForProteinFolding,) if is_torch_available() else ()
      _UpperCAmelCase				:    List[Any]           =			()
      _UpperCAmelCase				:    Optional[int]           =			{} if is_torch_available() else {}
      _UpperCAmelCase				:    Dict           =			False
      def 						UpperCamelCase__							(      self      ):
       lowerCamelCase		:	str							=      EsmFoldModelTester(self      )
       lowerCamelCase		:	List[Any]							=      ConfigTester(self    ,  config_class=__magic_name__    ,  hidden_size=3_7      )
      def 						UpperCamelCase__							(      self      ):
       self.config_tester.run_common_tests()
      def 						UpperCamelCase__							(      self      ):
       lowerCamelCase		:	str							=      self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_model(*__magic_name__      )
      @unittest.skip("""Does not support attention outputs"""      )
      def 						UpperCamelCase__							(      self      ):
       pass
      @unittest.skip
      def 						UpperCamelCase__							(      self      ):
       pass
      @unittest.skip("""Esm does not support embedding resizing"""      )
      def 						UpperCamelCase__							(      self      ):
       pass
      @unittest.skip("""Esm does not support embedding resizing"""      )
      def 						UpperCamelCase__							(      self      ):
       pass
      @unittest.skip("""ESMFold does not support passing input embeds!"""      )
      def 						UpperCamelCase__							(      self      ):
       pass
      @unittest.skip("""ESMFold does not support head pruning."""      )
      def 						UpperCamelCase__							(      self      ):
       pass
      @unittest.skip("""ESMFold does not support head pruning."""      )
      def 						UpperCamelCase__							(      self      ):
       pass
      @unittest.skip("""ESMFold does not support head pruning."""      )
      def 						UpperCamelCase__							(      self      ):
       pass
      @unittest.skip("""ESMFold does not support head pruning."""      )
      def 						UpperCamelCase__							(      self      ):
       pass
      @unittest.skip("""ESMFold does not support head pruning."""      )
      def 						UpperCamelCase__							(      self      ):
       pass
      @unittest.skip("""ESMFold does not output hidden states in the normal way."""      )
      def 						UpperCamelCase__							(      self      ):
       pass
      @unittest.skip("""ESMfold does not output hidden states in the normal way."""      )
      def 						UpperCamelCase__							(      self      ):
       pass
      @unittest.skip("""ESMFold only has one output format."""      )
      def 						UpperCamelCase__							(      self      ):
       pass
      @unittest.skip("""This test doesn't work for ESMFold and doesn't test core functionality"""      )
      def 						UpperCamelCase__							(      self      ):
       pass
      @unittest.skip("""ESMFold does not support input chunking."""      )
      def 						UpperCamelCase__							(      self      ):
       pass
      @unittest.skip("""ESMFold doesn't respect you and it certainly doesn't respect your initialization arguments."""      )
      def 						UpperCamelCase__							(      self      ):
       pass
      @unittest.skip("""ESMFold doesn't support torchscript compilation."""      )
      def 						UpperCamelCase__							(      self      ):
       pass
      @unittest.skip("""ESMFold doesn't support torchscript compilation."""      )
      def 						UpperCamelCase__							(      self      ):
       pass
      @unittest.skip("""ESMFold doesn't support torchscript compilation."""      )
      def 						UpperCamelCase__							(      self      ):
       pass
      @unittest.skip("""ESMFold doesn't support data parallel."""      )
      def 						UpperCamelCase__							(      self      ):
       pass






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





@require_torch
class 							A__		(	__SCREAMING_SNAKE_CASE):
      @slow
      def 						UpperCamelCase__							(      self      ):
       lowerCamelCase		:	List[Any]							=      EsmForProteinFolding.from_pretrained("""facebook/esmfold_v1"""      ).float()
       model.eval()
       lowerCamelCase		:	List[str]							=      torch.tensor([[0, 6, 4, 1_3, 5, 4, 1_6, 1_2, 1_1, 7, 2]]      )
       lowerCamelCase		:	List[Any]							=      model(__magic_name__      )["""positions"""]
       lowerCamelCase		:	Tuple							=      torch.tensor([2.5_828, 0.7_993, -10.9_334]    ,  dtype=torch.floataa      )
       self.assertTrue(torch.allclose(position_outputs[0, 0, 0, 0]    ,  __magic_name__    ,  atol=1e-4      )      )






def     _a					(						lowerCamelCase							):

 if p < 2:
  raise ValueError("""p should not be less than 2!"""							)
 elif p == 2:
  return True

 lowerCamelCase		:	Any							=      4
 lowerCamelCase		:	List[str]							=      (1 << p) - 1
 for _ in range(p - 2							):
  lowerCamelCase		:	List[Any]							=      ((s * s) - 2) % m
 return s == 0


if __name__ == "__main__":
      print(lucas_lehmer_test(7))
      print(lucas_lehmer_test(1_1))




