


'''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   SCREAMING_SNAKE_CASE			:







		"""simple docstring"""






		def __init__(   self		,						__A		,						__A=13		,						__A=7		,						__A=False		,						__A=True		,						__A=False		,						__A=False		,						__A=19		,						__A=32		,						__A=5		,						__A=4		,						__A=37		,						__A="gelu"		,						__A=0.1		,						__A=0.1		,						__A=512		,						__A=16		,						__A=2		,						__A=0.02		,						__A=3		,						__A=4		,						__A=None		,						) ->     Any:
								_lowerCAmelCase										=parent
								_lowerCAmelCase										=batch_size
								_lowerCAmelCase										=seq_length
								_lowerCAmelCase										=is_training
								_lowerCAmelCase										=use_input_mask
								_lowerCAmelCase										=use_token_type_ids
								_lowerCAmelCase										=use_labels
								_lowerCAmelCase										=vocab_size
								_lowerCAmelCase										=hidden_size
								_lowerCAmelCase										=num_hidden_layers
								_lowerCAmelCase										=num_attention_heads
								_lowerCAmelCase										=intermediate_size
								_lowerCAmelCase										=hidden_act
								_lowerCAmelCase										=hidden_dropout_prob
								_lowerCAmelCase										=attention_probs_dropout_prob
								_lowerCAmelCase										=max_position_embeddings
								_lowerCAmelCase										=type_vocab_size
								_lowerCAmelCase										=type_sequence_label_size
								_lowerCAmelCase										=initializer_range
								_lowerCAmelCase										=num_labels
								_lowerCAmelCase										=num_choices
								_lowerCAmelCase										=scope






		def 		UpperCamelCase__       (   self				) ->     List[Any]:
								_lowerCAmelCase										=ids_tensor([self.batch_size, self.seq_length]		,						self.vocab_size				)

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

								_lowerCAmelCase										=None
								_lowerCAmelCase										=None
								_lowerCAmelCase										=None
								if self.use_labels:
														_lowerCAmelCase										=ids_tensor([self.batch_size]		,						self.type_sequence_label_size				)
														_lowerCAmelCase										=ids_tensor([self.batch_size, self.seq_length]		,						self.num_labels				)
														_lowerCAmelCase										=ids_tensor([self.batch_size]		,						self.num_choices				)

								_lowerCAmelCase										=self.get_config()

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






		def 		UpperCamelCase__       (   self				) ->     Optional[int]:
								_lowerCAmelCase										=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 		UpperCamelCase__       (   self		,						__A		,						__A		,						__A		,						__A		,						__A		,						__A				) ->     Optional[Any]:
								_lowerCAmelCase										=EsmForProteinFolding(config=__A				).float()
								model.to(__A				)
								model.eval()
								_lowerCAmelCase										=model(__A		,						attention_mask=__A				)
								_lowerCAmelCase										=model(__A				)
								_lowerCAmelCase										=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 		UpperCamelCase__       (   self				) ->     List[str]:
								_lowerCAmelCase										=self.prepare_config_and_inputs()
								(
								    (
								    _lowerCAmelCase				
								)						,				(
								    _lowerCAmelCase				
								)						,				(
								    _lowerCAmelCase				
								)						,				(
								    _lowerCAmelCase				
								)						,				(
								    _lowerCAmelCase				
								)						,				(
								    _lowerCAmelCase				
								)						,								
								)										=config_and_inputs
								_lowerCAmelCase										={'input_ids': input_ids, 'attention_mask': input_mask}
								return config, inputs_dict

@require_torch
class   SCREAMING_SNAKE_CASE			(						__lowercase    ,			__lowercase    ,			unittest.TestCase):







		"""simple docstring"""
		lowercase   :      Dict       =							False

		lowercase   :      str       =							(EsmForProteinFolding,) if is_torch_available() else ()
		lowercase   :      Dict       =							()
		lowercase   :      Union[str, Any]       =							{} if is_torch_available() else {}
		lowercase   :      Dict       =							False






		def 		UpperCamelCase__       (   self				) ->     Any:
								_lowerCAmelCase										=EsmFoldModelTester(self				)
								_lowerCAmelCase										=ConfigTester(self		,						config_class=__A		,						hidden_size=37				)






		def 		UpperCamelCase__       (   self				) ->     Tuple:
								self.config_tester.run_common_tests()






		def 		UpperCamelCase__       (   self				) ->     Any:
								_lowerCAmelCase										=self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_model(*__A				)






		@unittest.skip('Does not support attention outputs'				)
		def 		UpperCamelCase__       (   self				) ->     Tuple:
								pass






		@unittest.skip
		def 		UpperCamelCase__       (   self				) ->     str:
								pass






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






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






		@unittest.skip('ESMFold does not support passing input embeds!'				)
		def 		UpperCamelCase__       (   self				) ->     int:
								pass






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






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






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






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






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






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






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






		@unittest.skip('ESMFold only has one output format.'				)
		def 		UpperCamelCase__       (   self				) ->     List[str]:
								pass






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






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






		@unittest.skip('ESMFold doesn\'t respect you and it certainly doesn\'t respect your initialization arguments.'				)
		def 		UpperCamelCase__       (   self				) ->     str:
								pass






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






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






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






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






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

@require_torch
class   SCREAMING_SNAKE_CASE			(						__lowercase):







		"""simple docstring"""






		@slow
		def 		UpperCamelCase__       (   self				) ->     List[str]:
								_lowerCAmelCase										=EsmForProteinFolding.from_pretrained('facebook/esmfold_v1'				).float()
								model.eval()
								_lowerCAmelCase										=torch.tensor([[0, 6, 4, 13, 5, 4, 16, 12, 11, 7, 2]]				)
								_lowerCAmelCase										=model(__A				)['positions']
								_lowerCAmelCase										=torch.tensor([2.5_828, 0.7_993, -10.9_334]		,						dtype=torch.floataa				)
								self.assertTrue(torch.allclose(position_outputs[0, 0, 0, 0]		,						__A		,						atol=1E-4				)				)






'''simple docstring'''

def 							UpperCamelCase__			(			a__      ):


						'''simple docstring'''






						_lowerCAmelCase										=set()
						# To detect a back edge, keep track of vertices currently in the recursion stack
						_lowerCAmelCase										=set()
						return any(
						    node not in visited and depth_first_search(a__			,      a__			,      a__			,      a__      )
						    for node in graph      )



def 							UpperCamelCase__			(			a__			,      a__			,      a__			,      a__      ):


						'''simple docstring'''






						visited.add(a__      )
						rec_stk.add(a__      )

						for node in graph[vertex]:
												if node not in visited:
																		if depth_first_search(a__			,      a__			,      a__			,      a__      ):
																								return True
												elif node in rec_stk:
																		return True

    # The node needs to be removed from recursion stack before function ends
						rec_stk.remove(a__      )
						return False


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

							testmod()





