



from dataclasses import asdict, dataclass
from typing import Optional

from ...configuration_utils import PretrainedConfig
from ...utils import logging


a_						:     str	     =		logging.get_logger(__name__)

# TODO Update this
a_						:     List[str]	     =		{
    'facebook/esm-1b': 'https://huggingface.co/facebook/esm-1b/resolve/main/config.json',
    # See all ESM models at https://huggingface.co/models?filter=esm
}





class    lowerCamelCase__  (						UpperCAmelCase_):
     """simple docstring"""



     _A       =			'esm'







     def __init__(self				,			__a=None				,			__a=None				,			__a=None				,			__a=7_68				,			__a=12				,			__a=12				,			__a=30_72				,			__a=0.1				,			__a=0.1				,			__a=10_26				,			__a=0.02				,			__a=1E-12				,			__a="absolute"				,			__a=True				,			__a=None				,			__a=False				,			__a=False				,			__a=None				,			__a=None				,			**__a				,			):






           '''simple docstring'''



           super().__init__(pad_token_id=__a				,			mask_token_id=__a				,			**__a    )

           lowerCamelCase								=		vocab_size
           lowerCamelCase								=		hidden_size
           lowerCamelCase								=		num_hidden_layers
           lowerCamelCase								=		num_attention_heads
           lowerCamelCase								=		intermediate_size
           lowerCamelCase								=		hidden_dropout_prob
           lowerCamelCase								=		attention_probs_dropout_prob
           lowerCamelCase								=		max_position_embeddings
           lowerCamelCase								=		initializer_range
           lowerCamelCase								=		layer_norm_eps
           lowerCamelCase								=		position_embedding_type
           lowerCamelCase								=		use_cache
           lowerCamelCase								=		emb_layer_norm_before
           lowerCamelCase								=		token_dropout
           lowerCamelCase								=		is_folding_model
           if is_folding_model:
                 if esmfold_config is None:
                       logger.info("No esmfold_config supplied for folding model, using default values."    )
                       lowerCamelCase								=		EsmFoldConfig()
                 elif isinstance(__a				,			__a    ):
                       lowerCamelCase								=		EsmFoldConfig(**__a    )
                 lowerCamelCase								=		esmfold_config
                 if vocab_list is None:
                       logger.warning("No vocab_list supplied for folding model, assuming the ESM-2 vocabulary!"    )
                       lowerCamelCase								=		get_default_vocab_list()
                 else:
                       lowerCamelCase								=		vocab_list
           else:
                 lowerCamelCase								=		None
                 lowerCamelCase								=		None
           if self.esmfold_config is not None and getattr(self.esmfold_config				,			"use_esm_attn_map"				,			__a    ):
                 raise ValueError("The HuggingFace port of ESMFold does not support use_esm_attn_map at this time!"    )







     def 						_a      (self    ):






           '''simple docstring'''



           lowerCamelCase								=		super().to_dict()
           if isinstance(self.esmfold_config				,			__a    ):
                 lowerCamelCase								=		self.esmfold_config.to_dict()
           return output





@dataclass
class    lowerCamelCase__  :
     """simple docstring"""



     _A       =			None
     _A       =			True
     _A       =			False
     _A       =			False
     _A       =			False
     _A       =			0

     _A       =			True
     _A       =			False

     _A       =			1_28
     _A       =			None







     def 						_a      (self    ):






           '''simple docstring'''



           if self.trunk is None:
                 lowerCamelCase								=		TrunkConfig()
           elif isinstance(self.trunk				,			__a    ):
                 lowerCamelCase								=		TrunkConfig(**self.trunk    )







     def 						_a      (self    ):






           '''simple docstring'''



           lowerCamelCase								=		asdict(self    )
           lowerCamelCase								=		self.trunk.to_dict()
           return output





@dataclass
class    lowerCamelCase__  :
     """simple docstring"""



     _A       =			48
     _A       =			10_24
     _A       =			1_28
     _A       =			32
     _A       =			32
     _A       =			32
     _A       =			0
     _A       =			0
     _A       =			False
     _A       =			4
     _A       =			1_28
     _A       =			None







     def 						_a      (self    ):






           '''simple docstring'''



           if self.structure_module is None:
                 lowerCamelCase								=		StructureModuleConfig()
           elif isinstance(self.structure_module				,			__a    ):
                 lowerCamelCase								=		StructureModuleConfig(**self.structure_module    )

           if self.max_recycles <= 0:
                 raise ValueError(F"""`max_recycles` should be positive, got {self.max_recycles}."""    )
           if self.sequence_state_dim % self.sequence_state_dim != 0:
                 raise ValueError(
                     "`sequence_state_dim` should be a round multiple of `sequence_state_dim`, got"
                     F""" {self.sequence_state_dim} and {self.sequence_state_dim}."""    )
           if self.pairwise_state_dim % self.pairwise_state_dim != 0:
                 raise ValueError(
                     "`pairwise_state_dim` should be a round multiple of `pairwise_state_dim`, got"
                     F""" {self.pairwise_state_dim} and {self.pairwise_state_dim}."""    )

           lowerCamelCase								=		self.sequence_state_dim // self.sequence_head_width
           lowerCamelCase								=		self.pairwise_state_dim // self.pairwise_head_width

           if self.sequence_state_dim != sequence_num_heads * self.sequence_head_width:
                 raise ValueError(
                     "`sequence_state_dim` should be equal to `sequence_num_heads * sequence_head_width, got"
                     F""" {self.sequence_state_dim} != {sequence_num_heads} * {self.sequence_head_width}."""    )
           if self.pairwise_state_dim != pairwise_num_heads * self.pairwise_head_width:
                 raise ValueError(
                     "`pairwise_state_dim` should be equal to `pairwise_num_heads * pairwise_head_width, got"
                     F""" {self.pairwise_state_dim} != {pairwise_num_heads} * {self.pairwise_head_width}."""    )
           if self.pairwise_state_dim % 2 != 0:
                 raise ValueError(F"""`pairwise_state_dim` should be even, got {self.pairwise_state_dim}."""    )

           if self.dropout >= 0.4:
                 raise ValueError(F"""`dropout` should not be greater than 0.4, got {self.dropout}."""    )







     def 						_a      (self    ):






           '''simple docstring'''



           lowerCamelCase								=		asdict(self    )
           lowerCamelCase								=		self.structure_module.to_dict()
           return output





@dataclass
class    lowerCamelCase__  :
     """simple docstring"""



     _A       =			3_84
     _A       =			1_28
     _A       =			16
     _A       =			1_28
     _A       =			12
     _A       =			4
     _A       =			8
     _A       =			0.1
     _A       =			8
     _A       =			1
     _A       =			2
     _A       =			7
     _A       =			10
     _A       =			1e-8
     _A       =			1e5







     def 						_a      (self    ):






           '''simple docstring'''



           return asdict(self    )



def     __lowercase(	):


      """simple docstring"""



      return (
          "<cls>",
          "<pad>",
          "<eos>",
          "<unk>",
          "L",
          "A",
          "G",
          "V",
          "S",
          "E",
          "R",
          "T",
          "I",
          "D",
          "P",
          "K",
          "Q",
          "N",
          "F",
          "Y",
          "M",
          "H",
          "W",
          "C",
          "X",
          "B",
          "U",
          "Z",
          "O",
          ".",
          "-",
          "<null_1>",
          "<mask>",
      )




import unittest

from transformers.testing_utils import CaptureStdout
from transformers.tools.python_interpreter import evaluate

def     __lowercase(	UpperCAmelCase__ ):


      """simple docstring"""



      return x + 2






class    lowerCamelCase__  (						unittest.TestCase):
     """simple docstring"""



     def 						_a      (self    ):






           '''simple docstring'''



           lowerCamelCase								=		"x = 3"
           lowerCamelCase								=		{}
           lowerCamelCase								=		evaluate(__a				,			{}				,			state=__a    )
           assert result == 3
           self.assertDictEqual(__a				,			{"x": 3}    )

           lowerCamelCase								=		"x = y"
           lowerCamelCase								=		{"y": 5}
           lowerCamelCase								=		evaluate(__a				,			{}				,			state=__a    )
           # evaluate returns the value of the last assignment.
           assert result == 5
           self.assertDictEqual(__a				,			{"x": 5, "y": 5}    )







     def 						_a      (self    ):






           '''simple docstring'''



           lowerCamelCase								=		"y = add_two(x)"
           lowerCamelCase								=		{"x": 3}
           lowerCamelCase								=		evaluate(__a				,			{"add_two": add_two}				,			state=__a    )
           assert result == 5
           self.assertDictEqual(__a				,			{"x": 3, "y": 5}    )

           # Won't work without the tool
           with CaptureStdout() as out:
                 lowerCamelCase								=		evaluate(__a				,			{}				,			state=__a    )
           assert result is None
           assert "tried to execute add_two" in out.out







     def 						_a      (self    ):






           '''simple docstring'''



           lowerCamelCase								=		"x = 3"
           lowerCamelCase								=		{}
           lowerCamelCase								=		evaluate(__a				,			{}				,			state=__a    )
           assert result == 3
           self.assertDictEqual(__a				,			{"x": 3}    )







     def 						_a      (self    ):






           '''simple docstring'''



           lowerCamelCase								=		"test_dict = {'x': x, 'y': add_two(x)}"
           lowerCamelCase								=		{"x": 3}
           lowerCamelCase								=		evaluate(__a				,			{"add_two": add_two}				,			state=__a    )
           self.assertDictEqual(__a				,			{"x": 3, "y": 5}    )
           self.assertDictEqual(__a				,			{"x": 3, "test_dict": {"x": 3, "y": 5}}    )







     def 						_a      (self    ):






           '''simple docstring'''



           lowerCamelCase								=		"x = 3\ny = 5"
           lowerCamelCase								=		{}
           lowerCamelCase								=		evaluate(__a				,			{}				,			state=__a    )
           # evaluate returns the value of the last assignment.
           assert result == 5
           self.assertDictEqual(__a				,			{"x": 3, "y": 5}    )







     def 						_a      (self    ):






           '''simple docstring'''



           lowerCamelCase								=		"text = f'This is x: {x}.'"
           lowerCamelCase								=		{"x": 3}
           lowerCamelCase								=		evaluate(__a				,			{}				,			state=__a    )
           # evaluate returns the value of the last assignment.
           assert result == "This is x: 3."
           self.assertDictEqual(__a				,			{"x": 3, "text": "This is x: 3."}    )







     def 						_a      (self    ):






           '''simple docstring'''



           lowerCamelCase								=		"if x <= 3:\n    y = 2\nelse:\n    y = 5"
           lowerCamelCase								=		{"x": 3}
           lowerCamelCase								=		evaluate(__a				,			{}				,			state=__a    )
           # evaluate returns the value of the last assignment.
           assert result == 2
           self.assertDictEqual(__a				,			{"x": 3, "y": 2}    )

           lowerCamelCase								=		{"x": 8}
           lowerCamelCase								=		evaluate(__a				,			{}				,			state=__a    )
           # evaluate returns the value of the last assignment.
           assert result == 5
           self.assertDictEqual(__a				,			{"x": 8, "y": 5}    )







     def 						_a      (self    ):






           '''simple docstring'''



           lowerCamelCase								=		"test_list = [x, add_two(x)]"
           lowerCamelCase								=		{"x": 3}
           lowerCamelCase								=		evaluate(__a				,			{"add_two": add_two}				,			state=__a    )
           self.assertListEqual(__a				,			[3, 5]    )
           self.assertDictEqual(__a				,			{"x": 3, "test_list": [3, 5]}    )







     def 						_a      (self    ):






           '''simple docstring'''



           lowerCamelCase								=		"y = x"
           lowerCamelCase								=		{"x": 3}
           lowerCamelCase								=		evaluate(__a				,			{}				,			state=__a    )
           assert result == 3
           self.assertDictEqual(__a				,			{"x": 3, "y": 3}    )







     def 						_a      (self    ):






           '''simple docstring'''



           lowerCamelCase								=		"test_list = [x, add_two(x)]\ntest_list[1]"
           lowerCamelCase								=		{"x": 3}
           lowerCamelCase								=		evaluate(__a				,			{"add_two": add_two}				,			state=__a    )
           assert result == 5
           self.assertDictEqual(__a				,			{"x": 3, "test_list": [3, 5]}    )

           lowerCamelCase								=		"test_dict = {'x': x, 'y': add_two(x)}\ntest_dict['y']"
           lowerCamelCase								=		{"x": 3}
           lowerCamelCase								=		evaluate(__a				,			{"add_two": add_two}				,			state=__a    )
           assert result == 5
           self.assertDictEqual(__a				,			{"x": 3, "test_dict": {"x": 3, "y": 5}}    )







     def 						_a      (self    ):






           '''simple docstring'''



           lowerCamelCase								=		"x = 0\nfor i in range(3):\n    x = i"
           lowerCamelCase								=		{}
           lowerCamelCase								=		evaluate(__a				,			{"range": range}				,			state=__a    )
           assert result == 2
           self.assertDictEqual(__a				,			{"x": 2, "i": 2}    )