




"""simple docstring"""

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   :					str      ,     _lowerCamelCase   :					Dict      ,     _lowerCamelCase   :					Optional[int]=13      ,     _lowerCamelCase   :					str=7      ,     _lowerCamelCase   :					Optional[int]=False      ,     _lowerCamelCase   :					Optional[int]=True      ,     _lowerCamelCase   :					List[Any]=False      ,     _lowerCamelCase   :					str=False      ,     _lowerCamelCase   :					Optional[Any]=19      ,     _lowerCamelCase   :					Tuple=32      ,     _lowerCamelCase   :					Any=5      ,     _lowerCamelCase   :					str=4      ,     _lowerCamelCase   :					int=37      ,     _lowerCamelCase   :					Union[str, Any]="gelu"      ,     _lowerCamelCase   :					Union[str, Any]=0.1      ,     _lowerCamelCase   :					Tuple=0.1      ,     _lowerCamelCase   :					int=5_12      ,     _lowerCamelCase   :					List[Any]=16      ,     _lowerCamelCase   :					Any=2      ,     _lowerCamelCase   :					List[str]=0.02      ,     _lowerCamelCase   :					Tuple=3      ,     _lowerCamelCase   :					int=4      ,     _lowerCamelCase   :					Optional[Any]=None      ,     ):



					"""simple docstring"""

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







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



					"""simple docstring"""

					A_  :				int	   =		ids_tensor([self.batch_size, self.seq_length]      ,     self.vocab_size       )

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

					A_  :				Union[str, Any]	   =		None
					A_  :				Optional[Any]	   =		None
					A_  :				Dict	   =		None
					if self.use_labels:
						A_  :				List[Any]	   =		ids_tensor([self.batch_size]      ,     self.type_sequence_label_size       )
						A_  :				int	   =		ids_tensor([self.batch_size, self.seq_length]      ,     self.num_labels       )
						A_  :				Tuple	   =		ids_tensor([self.batch_size]      ,     self.num_choices       )

					A_  :				Any	   =		self.get_config()

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







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



					"""simple docstring"""

					A_  :				Optional[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 					a_  (							self   :					int      ,     _lowerCamelCase   :					Any      ,     _lowerCamelCase   :					str      ,     _lowerCamelCase   :					Any      ,     _lowerCamelCase   :					str      ,     _lowerCamelCase   :					List[str]      ,     _lowerCamelCase   :					Optional[int]       ):



					"""simple docstring"""

					A_  :				Optional[int]	   =		EsmForProteinFolding(config=snake_case_       ).float()
					model.to(snake_case_       )
					model.eval()
					A_  :				List[Any]	   =		model(snake_case_      ,     attention_mask=snake_case_       )
					A_  :				str	   =		model(snake_case_       )
					A_  :				Any	   =		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 					a_  (							self   :					Optional[int]       ):



					"""simple docstring"""

					A_  :				Optional[Any]	   =		self.prepare_config_and_inputs()
					(
					    (
					    A_						
					)   , (
					    A_						
					)   , (
					    A_						
					)   , (
					    A_						
					)   , (
					    A_						
					)   , (
					    A_						
					)   , 						
					)  :				Dict	   =		config_and_inputs
					A_  :				Any	   =		{'''input_ids''': input_ids, '''attention_mask''': input_mask}
					return config, inputs_dict

@require_torch
class        lowercase      (    _a     ,	_a     ,	unittest.TestCase):

				'''simple docstring'''





				__lowerCAmelCase    :    Tuple         =   False

				__lowerCAmelCase    :    List[str]         =   (EsmForProteinFolding,) if is_torch_available() else ()
				__lowerCAmelCase    :    Optional[Any]         =   ()
				__lowerCAmelCase    :    List[str]         =   {} if is_torch_available() else {}
				__lowerCAmelCase    :    Optional[Any]         =   False







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



					"""simple docstring"""

					A_  :				int	   =		EsmFoldModelTester(self       )
					A_  :				Union[str, Any]	   =		ConfigTester(self      ,     config_class=snake_case_      ,     hidden_size=37       )







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



					"""simple docstring"""

					self.config_tester.run_common_tests()







				def 					a_  (							self   :					List[Any]       ):



					"""simple docstring"""

					A_  :				Optional[Any]	   =		self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_model(*snake_case_       )







				@unittest.skip('''Does not support attention outputs'''       )
				def 					a_  (							self   :					str       ):



					"""simple docstring"""

					pass







				@unittest.skip
				def 					a_  (							self   :					Dict       ):



					"""simple docstring"""

					pass







				@unittest.skip('''Esm does not support embedding resizing'''       )
				def 					a_  (							self   :					Any       ):



					"""simple docstring"""

					pass







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



					"""simple docstring"""

					pass







				@unittest.skip('''ESMFold does not support passing input embeds!'''       )
				def 					a_  (							self   :					Optional[Any]       ):



					"""simple docstring"""

					pass







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



					"""simple docstring"""

					pass







				@unittest.skip('''ESMFold does not support head pruning.'''       )
				def 					a_  (							self   :					Optional[Any]       ):



					"""simple docstring"""

					pass







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



					"""simple docstring"""

					pass







				@unittest.skip('''ESMFold does not support head pruning.'''       )
				def 					a_  (							self   :					Dict       ):



					"""simple docstring"""

					pass







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



					"""simple docstring"""

					pass







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



					"""simple docstring"""

					pass







				@unittest.skip('''ESMfold does not output hidden states in the normal way.'''       )
				def 					a_  (							self   :					int       ):



					"""simple docstring"""

					pass







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



					"""simple docstring"""

					pass







				@unittest.skip('''This test doesn\'t work for ESMFold and doesn\'t test core functionality'''       )
				def 					a_  (							self   :					str       ):



					"""simple docstring"""

					pass







				@unittest.skip('''ESMFold does not support input chunking.'''       )
				def 					a_  (							self   :					List[str]       ):



					"""simple docstring"""

					pass







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



					"""simple docstring"""

					pass







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



					"""simple docstring"""

					pass







				@unittest.skip('''ESMFold doesn\'t support torchscript compilation.'''       )
				def 					a_  (							self   :					str       ):



					"""simple docstring"""

					pass







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



					"""simple docstring"""

					pass







				@unittest.skip('''ESMFold doesn\'t support data parallel.'''       )
				def 					a_  (							self   :					List[str]       ):



					"""simple docstring"""

					pass







				@unittest.skip('''Will be fixed soon by reducing the size of the model used for common tests.'''       )
				def 					a_  (							self   :					Optional[Any]       ):



					"""simple docstring"""

					pass

@require_torch
class        lowercase      (    _a):

				'''simple docstring'''





				@slow
				def 					a_  (							self   :					List[str]       ):



					"""simple docstring"""

					A_  :				int	   =		EsmForProteinFolding.from_pretrained('''facebook/esmfold_v1'''       ).float()
					model.eval()
					A_  :				str	   =		torch.tensor([[0, 6, 4, 13, 5, 4, 16, 12, 11, 7, 2]]       )
					A_  :				str	   =		model(snake_case_       )['''positions''']
					A_  :				Optional[int]	   =		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       )       )











"""simple docstring"""

from typing import Any

import numpy as np

def 		lowercase_      (		_UpperCAmelCase	):




	"""simple docstring"""






	return np.array_equal(_UpperCAmelCase  ,      matrix.conjugate().T	)

def 		lowercase_      (		_UpperCAmelCase  ,      _UpperCAmelCase	):




	"""simple docstring"""






	A_  :				Tuple	   =		v.conjugate().T
	A_  :				Tuple	   =		v_star.dot(_UpperCAmelCase	)
	assert isinstance(_UpperCAmelCase  ,      np.ndarray	)
	return (v_star_dot.dot(_UpperCAmelCase	)) / (v_star.dot(_UpperCAmelCase	))

def 		lowercase_      (		):




	"""simple docstring"""






	A_  :				Optional[Any]	   =		np.array([[2, 2 + 1J, 4], [2 - 1J, 3, 1J], [4, -1J, 1]]	)
	A_  :				str	   =		np.array([[1], [2], [3]]	)
	assert is_hermitian(_UpperCAmelCase	), f"""{a} is not hermitian."""
	print(rayleigh_quotient(_UpperCAmelCase  ,      _UpperCAmelCase	)	)

	A_  :				int	   =		np.array([[1, 2, 4], [2, 3, -1], [4, -1, 1]]	)
	assert is_hermitian(_UpperCAmelCase	), f"""{a} is not hermitian."""
	assert rayleigh_quotient(_UpperCAmelCase  ,      _UpperCAmelCase	) == float(3	)


if __name__ == "__main__":
		import doctest

		doctest.testmod()
		tests()





