


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




						def 						lowercase_ (				self							)					->    List[str]:
										lowerCAmelCase_ :      Dict    				=				ids_tensor([self.batch_size, self.seq_length]   ,						self.vocab_size							)

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

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

										lowerCAmelCase_ :      List[Any]    				=				self.get_config()

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




						def 						lowercase_ (				self							)					->    List[str]:
										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=__lowercase   ,						esmfold_config={'''trunk''': {'''num_blocks''': 2}, '''fp16_esm''': False}   ,						)
										return config




						def 						lowercase_ (				self   ,						__lowercase   ,						__lowercase   ,						__lowercase   ,						__lowercase   ,						__lowercase   ,						__lowercase							)					->    Optional[Any]:
										lowerCAmelCase_ :      Union[str, Any]    				=				EsmForProteinFolding(config=__lowercase							).float()
										model.to(__lowercase							)
										model.eval()
										lowerCAmelCase_ :      Union[str, Any]    				=				model(__lowercase   ,						attention_mask=__lowercase							)
										lowerCAmelCase_ :      str    				=				model(__lowercase							)
										lowerCAmelCase_ :      Optional[Any]    				=				model(__lowercase							)

										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							)					->    Dict:
										lowerCAmelCase_ :      Dict    				=				self.prepare_config_and_inputs()
										(
										    lowerCAmelCase_		
										) :      Any    				=				config_and_inputs
										lowerCAmelCase_ :      int    				=				{"""input_ids""": input_ids, """attention_mask""": input_mask}
										return config, inputs_dict







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







						'''simple docstring'''




						SCREAMING_SNAKE_CASE__      :  List[str]					=							False

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




						def 						lowercase_ (				self							)					->    Any:
										lowerCAmelCase_ :      Tuple    				=				EsmFoldModelTester(self							)
										lowerCAmelCase_ :      Tuple    				=				ConfigTester(self   ,						config_class=__lowercase   ,						hidden_size=3_7							)




						def 						lowercase_ (				self							)					->    str:
										self.config_tester.run_common_tests()




						def 						lowercase_ (				self							)					->    List[str]:
										lowerCAmelCase_ :      List[str]    				=				self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_model(*__lowercase							)




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




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




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




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




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




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




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




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




						@unittest.skip('''ESMFold does not support head pruning.'''							)
						def 						lowercase_ (				self							)					->    Dict:
										pass




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




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




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




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




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




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




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




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




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




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




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




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







@require_torch
class 				snake_case__(							UpperCAmelCase__							):







						'''simple docstring'''




						@slow
						def 						lowercase_ (				self							)					->    Dict:
										lowerCAmelCase_ :      List[str]    				=				EsmForProteinFolding.from_pretrained('''facebook/esmfold_v1'''							).float()
										model.eval()
										lowerCAmelCase_ :      str    				=				torch.tensor([[0, 6, 4, 1_3, 5, 4, 1_6, 1_2, 1_1, 7, 2]]							)
										lowerCAmelCase_ :      Optional[int]    				=				model(__lowercase							)["""positions"""]
										lowerCAmelCase_ :      List[str]    				=				torch.tensor([2.58_28, 0.79_93, -1_0.9_3_3_4]   ,						dtype=torch.floataa							)
										self.assertTrue(torch.allclose(position_outputs[0, 0, 0, 0]   ,						__lowercase   ,						atol=1e-4							)							)



from __future__ import annotations



def 			lowerCAmelCase (		lowerCAmelCase_ ,   lowerCAmelCase_ ,   lowerCAmelCase_ ,   )-> tuple:
				if (electron_conc, hole_conc, intrinsic_conc).count(0 ) != 1:
								raise ValueError('''You cannot supply more or less than 2 values''' )
				elif electron_conc < 0:
								raise ValueError('''Electron concentration cannot be negative in a semiconductor''' )
				elif hole_conc < 0:
								raise ValueError('''Hole concentration cannot be negative in a semiconductor''' )
				elif intrinsic_conc < 0:
								raise ValueError(
								    '''Intrinsic concentration cannot be negative in a semiconductor''' )
				elif electron_conc == 0:
								return (
								    "electron_conc",
								    intrinsic_conc**2 / hole_conc,
								)
				elif hole_conc == 0:
								return (
								    "hole_conc",
								    intrinsic_conc**2 / electron_conc,
								)
				elif intrinsic_conc == 0:
								return (
								    "intrinsic_conc",
								    (electron_conc * hole_conc) ** 0.5,
								)
				else:
								return (-1, -1)


if __name__ == "__main__":
						import doctest

						doctest.testmod()