



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






     def    lowercase_   (       self  :  Dict					)   ->int:
            snake_case__							:	List[Any]   	=	ids_tensor([self.batch_size, self.seq_length], self.vocab_size					)

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

            snake_case__							:	Optional[Any]   	=	None
            snake_case__							:	Optional[int]   	=	None
            snake_case__							:	str   	=	None
            if self.use_labels:
                   snake_case__							:	Optional[Any]   	=	ids_tensor([self.batch_size], self.type_sequence_label_size					)
                   snake_case__							:	List[Any]   	=	ids_tensor([self.batch_size, self.seq_length], self.num_labels					)
                   snake_case__							:	int   	=	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    lowercase_   (       self  :  Union[str, Any]					)   ->Optional[Any]:
            snake_case__							:	Tuple   	=	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=_snake_case, esmfold_config={'trunk': {'num_blocks': 2}, 'fp16_esm': False}, )
            return config






     def    lowercase_   (       self  :  List[str], _snake_case  :  Optional[Any], _snake_case  :  Tuple, _snake_case  :  Optional[int], _snake_case  :  int, _snake_case  :  Any, _snake_case  :  Optional[int]					)   ->str:
            snake_case__							:	Optional[int]   	=	EsmForProteinFolding(config=_snake_case					).float()
            model.to(_snake_case					)
            model.eval()
            snake_case__							:	int   	=	model(_snake_case, attention_mask=_snake_case					)
            snake_case__							:	Tuple   	=	model(_snake_case					)
            snake_case__							:	Dict   	=	model(_snake_case					)

            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    lowercase_   (       self  :  Optional[int]					)   ->Any:
            snake_case__							:	Tuple   	=	self.prepare_config_and_inputs()
            (
                (
                snake_case__
            )	,				(
                snake_case__
            )	,				(
                snake_case__
            )	,				(
                snake_case__
            )	,				(
                snake_case__
            )	,				(
                snake_case__
            )	,				
            )							:	str   	=	config_and_inputs
            snake_case__							:	int   	=	{'input_ids': input_ids, 'attention_mask': input_mask}
            return config, inputs_dict




@require_torch
class 					snake_case__						(       lowerCAmelCase_				,     lowerCAmelCase_				,     unittest.TestCase     ):






     """simple docstring"""


     _SCREAMING_SNAKE_CASE						=	False

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






     def    lowercase_   (       self  :  Dict					)   ->Optional[Any]:
            snake_case__							:	Tuple   	=	EsmFoldModelTester(self					)
            snake_case__							:	int   	=	ConfigTester(self, config_class=_snake_case, hidden_size=3_7					)






     def    lowercase_   (       self  :  str					)   ->List[Any]:
            self.config_tester.run_common_tests()






     def    lowercase_   (       self  :  int					)   ->Tuple:
            snake_case__							:	Dict   	=	self.model_tester.prepare_config_and_inputs()
            self.model_tester.create_and_check_model(*_snake_case					)






     @unittest.skip('Does not support attention outputs'					)
     def    lowercase_   (       self  :  int					)   ->Dict:
            pass






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






     @unittest.skip('Esm does not support embedding resizing'					)
     def    lowercase_   (       self  :  str					)   ->Dict:
            pass






     @unittest.skip('Esm does not support embedding resizing'					)
     def    lowercase_   (       self  :  Optional[int]					)   ->List[Any]:
            pass






     @unittest.skip('ESMFold does not support passing input embeds!'					)
     def    lowercase_   (       self  :  str					)   ->List[str]:
            pass






     @unittest.skip('ESMFold does not support head pruning.'					)
     def    lowercase_   (       self  :  Union[str, Any]					)   ->Union[str, Any]:
            pass






     @unittest.skip('ESMFold does not support head pruning.'					)
     def    lowercase_   (       self  :  Union[str, Any]					)   ->Union[str, Any]:
            pass






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






     @unittest.skip('ESMFold does not support head pruning.'					)
     def    lowercase_   (       self  :  Optional[Any]					)   ->Union[str, Any]:
            pass






     @unittest.skip('ESMFold does not support head pruning.'					)
     def    lowercase_   (       self  :  Union[str, Any]					)   ->Optional[int]:
            pass






     @unittest.skip('ESMFold does not output hidden states in the normal way.'					)
     def    lowercase_   (       self  :  List[str]					)   ->Optional[Any]:
            pass






     @unittest.skip('ESMfold does not output hidden states in the normal way.'					)
     def    lowercase_   (       self  :  Any					)   ->Union[str, Any]:
            pass






     @unittest.skip('ESMFold only has one output format.'					)
     def    lowercase_   (       self  :  Tuple					)   ->Tuple:
            pass






     @unittest.skip('This test doesn\'t work for ESMFold and doesn\'t test core functionality'					)
     def    lowercase_   (       self  :  Optional[int]					)   ->Dict:
            pass






     @unittest.skip('ESMFold does not support input chunking.'					)
     def    lowercase_   (       self  :  Union[str, Any]					)   ->List[str]:
            pass






     @unittest.skip('ESMFold doesn\'t respect you and it certainly doesn\'t respect your initialization arguments.'					)
     def    lowercase_   (       self  :  Dict					)   ->Optional[Any]:
            pass






     @unittest.skip('ESMFold doesn\'t support torchscript compilation.'					)
     def    lowercase_   (       self  :  List[str]					)   ->List[Any]:
            pass






     @unittest.skip('ESMFold doesn\'t support torchscript compilation.'					)
     def    lowercase_   (       self  :  Union[str, Any]					)   ->List[Any]:
            pass






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






     @unittest.skip('ESMFold doesn\'t support data parallel.'					)
     def    lowercase_   (       self  :  Dict					)   ->List[str]:
            pass






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




@require_torch
class 					snake_case__						(       lowerCAmelCase_     ):






     """simple docstring"""


     @slow
     def    lowercase_   (       self  :  str					)   ->Optional[Any]:
            snake_case__							:	Optional[int]   	=	EsmForProteinFolding.from_pretrained('facebook/esmfold_v1'					).float()
            model.eval()
            snake_case__							:	int   	=	torch.tensor([[0, 6, 4, 1_3, 5, 4, 1_6, 1_2, 1_1, 7, 2]]					)
            snake_case__							:	Union[str, Any]   	=	model(_snake_case					)['positions']
            snake_case__							:	Optional[Any]   	=	torch.tensor([2.5_8_2_8, 0.7_9_9_3, -1_0.9_3_3_4], dtype=torch.floataa					)
            self.assertTrue(torch.allclose(position_outputs[0, 0, 0, 0], _snake_case, atol=1e-4					)					)











from math import factorial
def        lowercase_							(A : int		,					A : int		,					A : float      ):
       if successes > trials:
              raise ValueError('successes must be lower or equal to trials'      )
       if trials < 0 or successes < 0:
              raise ValueError('the function is defined for non-negative integers'      )
       if not isinstance(A		,					A      ) or not isinstance(A		,					A      ):
              raise ValueError('the function is defined for non-negative integers'      )
       if not 0 < prob < 1:
              raise ValueError('prob has to be in range of 1 - 0'      )
       snake_case__							:	List[Any]   	=	(prob**successes) * ((1 - prob) ** (trials - successes))
       # Calculate the binomial coefficient: n! / k!(n-k)!
       snake_case__							:	List[str]   	=	float(factorial(A      )      )
       coefficient /= factorial(A      ) * factorial(trials - successes      )
       return probability * coefficient


if __name__ == "__main__":
 from doctest import testmod

 testmod()
 print("Probability of 2 successes out of 4 trails")
 print("with probability of 0.75 is:", end=" ")
 print(binomial_distribution(2, 4, 0.75))






