






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




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




							def 		lowerCamelCase_				(							self:				Optional[int]     ):
														lowerCamelCase__					:	int         =       ids_tensor([self.batch_size, self.seq_length]			,							self.vocab_size     )

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

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

														lowerCamelCase__					:	Any         =       self.get_config()

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




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



@require_torch
class _lowercase	(				_lowercase				,      _lowercase				,      unittest.TestCase		):
							a				      =       False

							a				      =       (EsmForProteinFolding,) if is_torch_available() else ()
							a				      =       ()
							a				      =       {} if is_torch_available() else {}
							a				      =       False




							def 		lowerCamelCase_				(							self:				Union[str, Any]     ):
														lowerCamelCase__					:	Optional[Any]         =       EsmFoldModelTester(self     )
														lowerCamelCase__					:	Optional[Any]         =       ConfigTester(self			,							config_class=UpperCamelCase__			,							hidden_size=37     )




							def 		lowerCamelCase_				(							self:				Tuple     ):
														self.config_tester.run_common_tests()




							def 		lowerCamelCase_				(							self:				Tuple     ):
														lowerCamelCase__					:	Union[str, Any]         =       self.model_tester.prepare_config_and_inputs()
														self.model_tester.create_and_check_model(*UpperCamelCase__     )




							@unittest.skip("""Does not support attention outputs"""     )
							def 		lowerCamelCase_				(							self:				List[Any]     ):
														pass




							@unittest.skip
							def 		lowerCamelCase_				(							self:				int     ):
														pass




							@unittest.skip("""Esm does not support embedding resizing"""     )
							def 		lowerCamelCase_				(							self:				Optional[Any]     ):
														pass




							@unittest.skip("""Esm does not support embedding resizing"""     )
							def 		lowerCamelCase_				(							self:				str     ):
														pass




							@unittest.skip("""ESMFold does not support passing input embeds!"""     )
							def 		lowerCamelCase_				(							self:				List[str]     ):
														pass




							@unittest.skip("""ESMFold does not support head pruning."""     )
							def 		lowerCamelCase_				(							self:				int     ):
														pass




							@unittest.skip("""ESMFold does not support head pruning."""     )
							def 		lowerCamelCase_				(							self:				Optional[Any]     ):
														pass




							@unittest.skip("""ESMFold does not support head pruning."""     )
							def 		lowerCamelCase_				(							self:				List[str]     ):
														pass




							@unittest.skip("""ESMFold does not support head pruning."""     )
							def 		lowerCamelCase_				(							self:				Optional[int]     ):
														pass




							@unittest.skip("""ESMFold does not support head pruning."""     )
							def 		lowerCamelCase_				(							self:				Tuple     ):
														pass




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




							@unittest.skip("""ESMfold does not output hidden states in the normal way."""     )
							def 		lowerCamelCase_				(							self:				Union[str, Any]     ):
														pass




							@unittest.skip("""ESMFold only has one output format."""     )
							def 		lowerCamelCase_				(							self:				Dict     ):
														pass




							@unittest.skip("""This test doesn't work for ESMFold and doesn't test core functionality"""     )
							def 		lowerCamelCase_				(							self:				Union[str, Any]     ):
														pass




							@unittest.skip("""ESMFold does not support input chunking."""     )
							def 		lowerCamelCase_				(							self:				Any     ):
														pass




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




							@unittest.skip("""ESMFold doesn't support torchscript compilation."""     )
							def 		lowerCamelCase_				(							self:				Any     ):
														pass




							@unittest.skip("""ESMFold doesn't support torchscript compilation."""     )
							def 		lowerCamelCase_				(							self:				str     ):
														pass




							@unittest.skip("""ESMFold doesn't support torchscript compilation."""     )
							def 		lowerCamelCase_				(							self:				List[Any]     ):
														pass




							@unittest.skip("""ESMFold doesn't support data parallel."""     )
							def 		lowerCamelCase_				(							self:				Tuple     ):
														pass




							@unittest.skip("""Will be fixed soon by reducing the size of the model used for common tests."""     )
							def 		lowerCamelCase_				(							self:				str     ):
														pass



@require_torch
class _lowercase	(				_lowercase		):




							@slow
							def 		lowerCamelCase_				(							self:				str     ):
														lowerCamelCase__					:	List[Any]         =       EsmForProteinFolding.from_pretrained("""facebook/esmfold_v1"""     ).float()
														model.eval()
														lowerCamelCase__					:	Optional[int]         =       torch.tensor([[0, 6, 4, 13, 5, 4, 16, 12, 11, 7, 2]]     )
														lowerCamelCase__					:	Any         =       model(UpperCamelCase__     )["""positions"""]
														lowerCamelCase__					:	Dict         =       torch.tensor([2.5_828, 0.7_993, -10.9_334]			,							dtype=torch.floataa     )
														self.assertTrue(torch.allclose(position_outputs[0, 0, 0, 0]			,							UpperCamelCase__			,							atol=1e-4     )     )









'''simple docstring'''







_A	:			Union[str, Any]         =range(2, 20 + 1)
_A	:			List[str]         =[10**k for k in range(ks[-1] + 1)]
_A	:			dict[int, dict[int, list[list[int]]]]         ={}





def  SCREAMING_SNAKE_CASE_       (UpperCamelCase				,			UpperCamelCase				,			UpperCamelCase				,			UpperCamelCase      )      ->       List[Any]:
							lowerCamelCase__					:	List[str]         =       sum(a_i[j] for j in range(UpperCamelCase				,			len(UpperCamelCase      )      )      )
							lowerCamelCase__					:	int         =       sum(a_i[j] * base[j] for j in range(min(len(UpperCamelCase      )				,			UpperCamelCase      )      )      )

							lowerCamelCase__  ,		lowerCamelCase__					:	Dict         =       0, 0
							lowerCamelCase__					:	List[str]         =       n - i

							lowerCamelCase__					:	Optional[Any]         =       memo.get(UpperCamelCase      )

							if sub_memo is not None:
														lowerCamelCase__					:	str         =       sub_memo.get(UpperCamelCase      )

														if jumps is not None and len(UpperCamelCase      ) > 0:
																					# find and make the largest jump without going over
																					lowerCamelCase__					:	Optional[Any]         =       -1
																					for _k in range(len(UpperCamelCase      ) - 1				,			-1				,			-1      ):
																												if jumps[_k][2] <= k and jumps[_k][1] <= max_dn:
																																			lowerCamelCase__					:	Dict         =       _k
																																			break

																					if max_jump >= 0:
																												lowerCamelCase__  ,		lowerCamelCase__  ,		lowerCamelCase__					:	str         =       jumps[max_jump]
																												# since the difference between jumps is cached, add c
																												lowerCamelCase__					:	Dict         =       diff + c
																												for j in range(min(UpperCamelCase				,			len(UpperCamelCase      )      )      ):
																																			lowerCamelCase__  ,		lowerCamelCase__					:	List[Any]         =       divmod(UpperCamelCase				,			10      )
																												if new_c > 0:
																																			add(UpperCamelCase				,			UpperCamelCase				,			UpperCamelCase      )

														else:
																					lowerCamelCase__					:	Any         =       []
							else:
														lowerCamelCase__					:	str         =       {c: []}
														lowerCamelCase__					:	Tuple         =       sub_memo

							if dn >= max_dn or c + diff >= base[k]:
														return diff, dn

							if k > ks[0]:
														while True:
																					# keep doing smaller jumps
																					lowerCamelCase__  ,		lowerCamelCase__					:	Dict         =       next_term(UpperCamelCase				,			k - 1				,			i + dn				,			UpperCamelCase      )
																					diff += _diff
																					dn += terms_jumped

																					if dn >= max_dn or c + diff >= base[k]:
																												break
							else:
														# would be too small a jump, just compute sequential terms instead
														lowerCamelCase__  ,		lowerCamelCase__					:	Optional[int]         =       compute(UpperCamelCase				,			UpperCamelCase				,			i + dn				,			UpperCamelCase      )
														diff += _diff
														dn += terms_jumped

							lowerCamelCase__					:	str         =       sub_memo[c]

							# keep jumps sorted by # of terms skipped
							lowerCamelCase__					:	List[Any]         =       0
							while j < len(UpperCamelCase      ):
														if jumps[j][1] > dn:
																					break
														j += 1

							# cache the jump for this value digitsum(b) and c
							sub_memo[c].insert(UpperCamelCase				,			(diff, dn, k)      )
							return (diff, dn)





def  SCREAMING_SNAKE_CASE_       (UpperCamelCase				,			UpperCamelCase				,			UpperCamelCase				,			UpperCamelCase      )      ->       List[Any]:
							if i >= n:
														return 0, i
							if k > len(UpperCamelCase      ):
														a_i.extend([0 for _ in range(k - len(UpperCamelCase      )      )]      )

							# note: a_i -> b * 10^k + c
							# ds_b -> digitsum(b)
							# ds_c -> digitsum(c)
							lowerCamelCase__					:	Optional[Any]         =       i
							lowerCamelCase__  ,		lowerCamelCase__  ,		lowerCamelCase__					:	Optional[int]         =       0, 0, 0
							for j in range(len(UpperCamelCase      )      ):
														if j >= k:
																					ds_b += a_i[j]
														else:
																					ds_c += a_i[j]

							while i < n:
														i += 1
														lowerCamelCase__					:	Optional[int]         =       ds_c + ds_b
														diff += addend
														lowerCamelCase__					:	int         =       0
														for j in range(UpperCamelCase      ):
																					lowerCamelCase__					:	str         =       a_i[j] + addend
																					lowerCamelCase__  ,		lowerCamelCase__					:	int         =       divmod(UpperCamelCase				,			10      )

																					ds_c += a_i[j]

														if addend > 0:
																					break

							if addend > 0:
														add(UpperCamelCase				,			UpperCamelCase				,			UpperCamelCase      )
							return diff, i - start_i





def  SCREAMING_SNAKE_CASE_       (UpperCamelCase				,			UpperCamelCase				,			UpperCamelCase      )      ->       str:
							for j in range(UpperCamelCase				,			len(UpperCamelCase      )      ):
														lowerCamelCase__					:	List[Any]         =       digits[j] + addend
														if s >= 10:
																					lowerCamelCase__  ,		lowerCamelCase__					:	Union[str, Any]         =       divmod(UpperCamelCase				,			10      )
																					lowerCamelCase__					:	Any         =       addend // 10 + quotient
														else:
																					lowerCamelCase__					:	Any         =       s
																					lowerCamelCase__					:	Optional[Any]         =       addend // 10

														if addend == 0:
																					break

							while addend > 0:
														lowerCamelCase__  ,		lowerCamelCase__					:	Any         =       divmod(UpperCamelCase				,			10      )
														digits.append(UpperCamelCase      )





def  SCREAMING_SNAKE_CASE_       (UpperCamelCase = 10**15      )      ->       int:
							lowerCamelCase__					:	Any         =       [1]
							lowerCamelCase__					:	List[str]         =       1
							lowerCamelCase__					:	Tuple         =       0
							while True:
														lowerCamelCase__  ,		lowerCamelCase__					:	Any         =       next_term(UpperCamelCase				,			20				,			i + dn				,			UpperCamelCase      )
														dn += terms_jumped
														if dn == n - i:
																					break

							lowerCamelCase__					:	Union[str, Any]         =       0
							for j in range(len(UpperCamelCase      )      ):
														a_n += digits[j] * 10**j
							return a_n


if __name__ == "__main__":
			print(F'{solution() = }')

