



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        lowerCAmelCase__					:


				def __init__(							self      :  List[str]						, __UpperCamelCase      :  Dict						, __UpperCamelCase      :  List[str]=13						, __UpperCamelCase      :  Tuple=7						, __UpperCamelCase      :  int=False						, __UpperCamelCase      :  Union[str, Any]=True						, __UpperCamelCase      :  Dict=False						, __UpperCamelCase      :  List[str]=False						, __UpperCamelCase      :  Optional[int]=19						, __UpperCamelCase      :  Any=32						, __UpperCamelCase      :  Union[str, Any]=5						, __UpperCamelCase      :  str=4						, __UpperCamelCase      :  Tuple=37						, __UpperCamelCase      :  Optional[int]="gelu"						, __UpperCamelCase      :  str=0.1						, __UpperCamelCase      :  Any=0.1						, __UpperCamelCase      :  Tuple=512						, __UpperCamelCase      :  str=16						, __UpperCamelCase      :  Union[str, Any]=2						, __UpperCamelCase      :  List[Any]=0.0_2						, __UpperCamelCase      :  int=3						, __UpperCamelCase      :  Optional[Any]=4						, __UpperCamelCase      :  Optional[int]=None						, )		->     Optional[Any]:
											A      						=    parent
											A      						=    batch_size
											A      						=    seq_length
											A      						=    is_training
											A      						=    use_input_mask
											A      						=    use_token_type_ids
											A      						=    use_labels
											A      						=    vocab_size
											A      						=    hidden_size
											A      						=    num_hidden_layers
											A      						=    num_attention_heads
											A      						=    intermediate_size
											A      						=    hidden_act
											A      						=    hidden_dropout_prob
											A      						=    attention_probs_dropout_prob
											A      						=    max_position_embeddings
											A      						=    type_vocab_size
											A      						=    type_sequence_label_size
											A      						=    initializer_range
											A      						=    num_labels
											A      						=    num_choices
											A      						=    scope


				def __UpperCamelCase						(							self      :  Any       )		->     str:
											A      						=    ids_tensor([self.batch_size, self.seq_length]						, self.vocab_size       )

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

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

											A      						=    self.get_config()

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


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


				def __UpperCamelCase						(							self      :  Union[str, Any]						, __UpperCamelCase      :  Union[str, Any]						, __UpperCamelCase      :  Any						, __UpperCamelCase      :  Optional[int]						, __UpperCamelCase      :  Optional[Any]						, __UpperCamelCase      :  Union[str, Any]						, __UpperCamelCase      :  Tuple       )		->     Optional[int]:
											A      						=    EsmForProteinFolding(config=__UpperCamelCase       ).float()
											model.to(__UpperCamelCase       )
											model.eval()
											A      						=    model(__UpperCamelCase						, attention_mask=__UpperCamelCase       )
											A      						=    model(__UpperCamelCase       )
											A      						=    model(__UpperCamelCase       )

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





@require_torch
class        lowerCAmelCase__					(  _lowerCamelCase ,				_lowerCamelCase ,				unittest.TestCase       ):
				A_   :     Dict								=     False

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


				def __UpperCamelCase						(							self      :  List[Any]       )		->     str:
											A      						=    EsmFoldModelTester(self       )
											A      						=    ConfigTester(self						, config_class=__UpperCamelCase						, hidden_size=37       )


				def __UpperCamelCase						(							self      :  Union[str, Any]       )		->     Optional[int]:
											self.config_tester.run_common_tests()


				def __UpperCamelCase						(							self      :  List[str]       )		->     Tuple:
											A      						=    self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_model(*__UpperCamelCase       )


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


				@unittest.skip
				def __UpperCamelCase						(							self      :  Dict       )		->     List[str]:
											pass


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


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


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


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


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


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


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


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


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


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


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


				@unittest.skip('This test doesn\'t work for ESMFold and doesn\'t test core functionality'       )
				def __UpperCamelCase						(							self      :  Tuple       )		->     Tuple:
											pass


				@unittest.skip('ESMFold does not support input chunking.'       )
				def __UpperCamelCase						(							self      :  Any       )		->     Dict:
											pass


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


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


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


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


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


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





@require_torch
class        lowerCAmelCase__					(  _lowerCamelCase       ):


				@slow
				def __UpperCamelCase						(							self      :  Union[str, Any]       )		->     Tuple:
											A      						=    EsmForProteinFolding.from_pretrained('facebook/esmfold_v1'       ).float()
											model.eval()
											A      						=    torch.tensor([[0, 6, 4, 13, 5, 4, 16, 12, 11, 7, 2]]       )
											A      						=    model(__UpperCamelCase       )['positions']
											A      						=    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]						, __UpperCamelCase						, atol=1e-4       )       )






"""simple docstring"""
from typing import Any







class       a							:



 def __init__(     self				,       _snake_case     ):







  """simple docstring"""






  lowerCAmelCase    				= data
  lowerCAmelCase    				= None



 def __repr__(     self     ):







  """simple docstring"""






  return F'Node({self.data})'







class       a							:



 def __init__(     self     ):







  """simple docstring"""






  lowerCAmelCase    				= None



 def __iter__(     self     ):







  """simple docstring"""






  lowerCAmelCase    				= self.head
  while node:
   yield node.data
   lowerCAmelCase    				= node.next



 def __len__(     self     ):







  """simple docstring"""






  return sum(1 for _ in self     )



 def __repr__(     self     ):







  """simple docstring"""






  return "->".join([str(_snake_case     ) for item in self]     )



 def __getitem__(     self				,       _snake_case     ):







  """simple docstring"""






  if not 0 <= index < len(self     ):
   raise ValueError('list index out of range.'     )
  for i, node in enumerate(self     ):
   if i == index:
    return node
  return None



 def __setitem__(     self				,       _snake_case				,       _snake_case     ):







  """simple docstring"""






  if not 0 <= index < len(self     ):
   raise ValueError('list index out of range.'     )
  lowerCAmelCase    				= self.head
  for _ in range(_snake_case     ):
   lowerCAmelCase    				= current.next
  lowerCAmelCase    				= data



 def    UpperCamelCase__  (     self				,       _snake_case     ):







  """simple docstring"""






  self.insert_nth(len(self     )				,       _snake_case     )



 def    UpperCamelCase__  (     self				,       _snake_case     ):







  """simple docstring"""






  self.insert_nth(0				,       _snake_case     )



 def    UpperCamelCase__  (     self				,       _snake_case				,       _snake_case     ):







  """simple docstring"""






  if not 0 <= index <= len(self     ):
   raise IndexError('list index out of range'     )
  lowerCAmelCase    				= Node(_snake_case     )
  if self.head is None:
   lowerCAmelCase    				= new_node
  elif index == 0:
   lowerCAmelCase    				= self.head  # link new_node to head
   lowerCAmelCase    				= new_node
  else:
   lowerCAmelCase    				= self.head
   for _ in range(index - 1     ):
    lowerCAmelCase    				= temp.next
   lowerCAmelCase    				= temp.next
   lowerCAmelCase    				= new_node



 def    UpperCamelCase__  (     self     ):  # print every node data







  """simple docstring"""






  print(self     )



 def    UpperCamelCase__  (     self     ):







  """simple docstring"""






  return self.delete_nth(0     )



 def    UpperCamelCase__  (     self     ):  # delete from tail







  """simple docstring"""






  return self.delete_nth(len(self     ) - 1     )



 def    UpperCamelCase__  (     self				,       _snake_case = 0     ):







  """simple docstring"""






  if not 0 <= index <= len(self     ) - 1:  # test if index is valid
   raise IndexError('List index out of range.'     )
  lowerCAmelCase    				= self.head  # default first node
  if index == 0:
   lowerCAmelCase    				= self.head.next
  else:
   lowerCAmelCase    				= self.head
   for _ in range(index - 1     ):
    lowerCAmelCase    				= temp.next
   lowerCAmelCase    				= temp.next
   lowerCAmelCase    				= temp.next.next
  return delete_node.data



 def    UpperCamelCase__  (     self     ):







  """simple docstring"""






  return self.head is None



 def    UpperCamelCase__  (     self     ):







  """simple docstring"""






  lowerCAmelCase    				= None
  lowerCAmelCase    				= self.head

  while current:
   # Store the current node's next node.
   lowerCAmelCase    				= current.next
   # Make the current node's next point backwards
   lowerCAmelCase    				= prev
   # Make the previous node be the current node
   lowerCAmelCase    				= current
   # Make the current node the next node (to progress iteration)
   lowerCAmelCase    				= next_node
  # Return prev in order to put the head at the end
  lowerCAmelCase    				= prev


def 		_SCREAMING_SNAKE_CASE			():
 lowerCAmelCase    				= LinkedList()
 assert linked_list.is_empty() is True
 assert str(_UpperCAmelCase			) == ""

 try:
  linked_list.delete_head()
  raise AssertionError  # This should not happen.
 except IndexError:
  assert True  # This should happen.

 try:
  linked_list.delete_tail()
  raise AssertionError  # This should not happen.
 except IndexError:
  assert True  # This should happen.

 for i in range(10			):
  assert len(_UpperCAmelCase			) == i
  linked_list.insert_nth(_UpperCAmelCase  ,     i + 1			)
 assert str(_UpperCAmelCase			) == "->".join(str(_UpperCAmelCase			) for i in range(1  ,     11			)			)

 linked_list.insert_head(0			)
 linked_list.insert_tail(11			)
 assert str(_UpperCAmelCase			) == "->".join(str(_UpperCAmelCase			) for i in range(0  ,     12			)			)

 assert linked_list.delete_head() == 0
 assert linked_list.delete_nth(9			) == 10
 assert linked_list.delete_tail() == 11
 assert len(_UpperCAmelCase			) == 9
 assert str(_UpperCAmelCase			) == "->".join(str(_UpperCAmelCase			) for i in range(1  ,     10			)			)

 assert all(linked_list[i] == i + 1 for i in range(0  ,     9			)			) is True

 for i in range(0  ,     9			):
  lowerCAmelCase    				= -i
 assert all(linked_list[i] == -i for i in range(0  ,     9			)			) is True

 linked_list.reverse()
 assert str(_UpperCAmelCase			) == "->".join(str(_UpperCAmelCase			) for i in range(-8  ,     1			)			)

def 		_SCREAMING_SNAKE_CASE			():
 lowerCAmelCase    				= [
     -9,
     100,
     Node(7734_5112			),
     'dlrow olleH',
     7,
     5555,
     0,
     -192.5_5555,
     'Hello, world!',
     77.9,
     Node(10			),
     None,
     None,
     12.20,
 ]
 lowerCAmelCase    				= LinkedList()

 for i in test_input:
  linked_list.insert_tail(_UpperCAmelCase			)

 # Check if it's empty or not
 assert linked_list.is_empty() is False
 assert (
     str(_UpperCAmelCase			) == "-9->100->Node(77345112)->dlrow olleH->7->5555->0->"
     "-192.55555->Hello, world!->77.9->Node(10)->None->None->12.2"
 )

 # Delete the head
 lowerCAmelCase    				= linked_list.delete_head()
 assert result == -9
 assert (
     str(_UpperCAmelCase			) == "100->Node(77345112)->dlrow olleH->7->5555->0->-192.55555->"
     "Hello, world!->77.9->Node(10)->None->None->12.2"
 )

 # Delete the tail
 lowerCAmelCase    				= linked_list.delete_tail()
 assert result == 12.2
 assert (
     str(_UpperCAmelCase			) == "100->Node(77345112)->dlrow olleH->7->5555->0->-192.55555->"
     "Hello, world!->77.9->Node(10)->None->None"
 )

 # Delete a node in specific location in linked list
 lowerCAmelCase    				= linked_list.delete_nth(10			)
 assert result is None
 assert (
     str(_UpperCAmelCase			) == "100->Node(77345112)->dlrow olleH->7->5555->0->-192.55555->"
     "Hello, world!->77.9->Node(10)->None"
 )

 # Add a Node instance to its head
 linked_list.insert_head(Node('Hello again, world!'			)			)
 assert (
     str(_UpperCAmelCase			)
     == "Node(Hello again, world!)->100->Node(77345112)->dlrow olleH->"
     "7->5555->0->-192.55555->Hello, world!->77.9->Node(10)->None"
 )

 # Add None to its tail
 linked_list.insert_tail(_UpperCAmelCase			)
 assert (
     str(_UpperCAmelCase			)
     == "Node(Hello again, world!)->100->Node(77345112)->dlrow olleH->"
     "7->5555->0->-192.55555->Hello, world!->77.9->Node(10)->None->None"
 )

 # Reverse the linked list
 linked_list.reverse()
 assert (
     str(_UpperCAmelCase			)
     == "None->None->Node(10)->77.9->Hello, world!->-192.55555->0->5555->"
     "7->dlrow olleH->Node(77345112)->100->Node(Hello again, world!)"
 )

def 		_SCREAMING_SNAKE_CASE			():
 from doctest import testmod

 testmod()

 lowerCAmelCase    				= LinkedList()
 linked_list.insert_head(input('Inserting 1st at head '			).strip()			)
 linked_list.insert_head(input('Inserting 2nd at head '			).strip()			)
 print('\nPrint list:'			)
 linked_list.print_list()
 linked_list.insert_tail(input('\nInserting 1st at tail '			).strip()			)
 linked_list.insert_tail(input('Inserting 2nd at tail '			).strip()			)
 print('\nPrint list:'			)
 linked_list.print_list()
 print('\nDelete head'			)
 linked_list.delete_head()
 print('Delete tail'			)
 linked_list.delete_tail()
 print('\nPrint list:'			)
 linked_list.print_list()
 print('\nReverse linked list'			)
 linked_list.reverse()
 print('\nPrint list:'			)
 linked_list.print_list()
 print('\nString representation of linked list:'			)
 print(_UpperCAmelCase			)
 print('\nReading/changing Node data using indexing:'			)
 print(F'Element at Position 1: {linked_list[1]}'			)
 lowerCAmelCase    				= input('Enter New Value: '			).strip()
 print('New list:'			)
 print(_UpperCAmelCase			)
 print(F'length of linked_list is : {len(_UpperCAmelCase			)}'			)


if __name__ == "__main__":
       main()





