





import copy
import os
from typing import Union

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


UpperCamelCase__  			=logging.get_logger(__name__)

UpperCamelCase__  			={
    'google/pix2struct-textcaps-base': (
        'https://huggingface.co/google/pix2struct-textcaps-base/resolve/main/config.json'
    ),
}





class       lowerCAmelCase__(			UpperCamelCase__     ):






       '''simple docstring'''


       __snake_case			      =     'pix2struct_text_model'
       __snake_case			      =     ['past_key_values']
       __snake_case			      =     {
           'hidden_size': 'hidden_size',
           'num_attention_heads': 'num_heads',
           'num_hidden_layers': 'num_layers',
       }




       def __init__(   self     ,    __lowerCamelCase=5_0_2_4_4     ,    __lowerCamelCase=7_6_8     ,    __lowerCamelCase=6_4     ,    __lowerCamelCase=2_0_4_8     ,    __lowerCamelCase=1_2     ,    __lowerCamelCase=1_2     ,    __lowerCamelCase=3_2     ,    __lowerCamelCase=1_2_8     ,    __lowerCamelCase=0.1     ,    __lowerCamelCase=1E-6     ,    __lowerCamelCase=1.0     ,    __lowerCamelCase="gelu_new"     ,    __lowerCamelCase=0     ,    __lowerCamelCase=False     ,    __lowerCamelCase=0     ,    __lowerCamelCase=1     ,    __lowerCamelCase=False     ,    __lowerCamelCase=True     ,    **__lowerCamelCase     ,    )      ->  Dict:
            _SCREAMING_SNAKE_CASE							:						Dict         =				vocab_size
            _SCREAMING_SNAKE_CASE							:						Tuple         =				hidden_size
            _SCREAMING_SNAKE_CASE							:						Optional[Any]         =				d_kv
            _SCREAMING_SNAKE_CASE							:						Optional[Any]         =				d_ff
            _SCREAMING_SNAKE_CASE							:						Union[str, Any]         =				num_layers
            _SCREAMING_SNAKE_CASE							:						Dict         =				num_heads
            _SCREAMING_SNAKE_CASE							:						Optional[Any]         =				relative_attention_num_buckets
            _SCREAMING_SNAKE_CASE							:						Tuple         =				relative_attention_max_distance
            _SCREAMING_SNAKE_CASE							:						Optional[Any]         =				dropout_rate
            _SCREAMING_SNAKE_CASE							:						Any         =				layer_norm_epsilon
            _SCREAMING_SNAKE_CASE							:						Dict         =				initializer_factor
            _SCREAMING_SNAKE_CASE							:						List[Any]         =				use_cache

            _SCREAMING_SNAKE_CASE							:						List[str]         =				eos_token_id
            _SCREAMING_SNAKE_CASE							:						Any         =				decoder_start_token_id

            # for backwards compatibility
            _SCREAMING_SNAKE_CASE							:						Union[str, Any]         =				dense_act_fn

            super().__init__(
                pad_token_id=__lowerCamelCase     ,    eos_token_id=__lowerCamelCase     ,    decoder_start_token_id=__lowerCamelCase     ,    tie_word_embeddings=__lowerCamelCase     ,    is_decoder=__lowerCamelCase     ,    **__lowerCamelCase     ,    )







       @classmethod
       def      UpperCamelCase_      (   cls     ,    __lowerCamelCase     ,    **__lowerCamelCase				)      ->  List[str]:
            cls._set_token_in_kwargs(__lowerCamelCase				)

            _SCREAMING_SNAKE_CASE     ,      _SCREAMING_SNAKE_CASE							:						Optional[int]         =				cls.get_config_dict(__lowerCamelCase     ,    **__lowerCamelCase				)

            # get the text config dict if we are loading from Pix2StructConfig
            if config_dict.get("model_type"				) == "pix2struct":
                 _SCREAMING_SNAKE_CASE							:						Tuple         =				config_dict["text_config"]

            if "model_type" in config_dict and hasattr(cls     ,    "model_type"				) and config_dict["model_type"] != cls.model_type:
                 logger.warning(
                     F"""You are using a model of type {config_dict['model_type']} to instantiate a model of type """
                     F"""{cls.model_type}. This is not supported for all configurations of models and can yield errors."""				)

            return cls.from_dict(__lowerCamelCase     ,    **__lowerCamelCase				)





class       lowerCAmelCase__(			UpperCamelCase__     ):






       '''simple docstring'''


       __snake_case			      =     'pix2struct_vision_model'




       def __init__(   self     ,    __lowerCamelCase=7_6_8     ,    __lowerCamelCase=7_6_8     ,    __lowerCamelCase=2_0_4_8     ,    __lowerCamelCase=6_4     ,    __lowerCamelCase=1_2     ,    __lowerCamelCase=1_2     ,    __lowerCamelCase="gelu_new"     ,    __lowerCamelCase=1E-6     ,    __lowerCamelCase=0.0     ,    __lowerCamelCase=0.0     ,    __lowerCamelCase=1E-10     ,    __lowerCamelCase=1.0     ,    __lowerCamelCase=4_0_9_6     ,    __lowerCamelCase=3_2     ,    __lowerCamelCase=1_2_8     ,    **__lowerCamelCase     ,    )      ->  List[Any]:
            super().__init__(**__lowerCamelCase				)

            _SCREAMING_SNAKE_CASE							:						Tuple         =				hidden_size
            _SCREAMING_SNAKE_CASE							:						Union[str, Any]         =				patch_embed_hidden_size
            _SCREAMING_SNAKE_CASE							:						Optional[Any]         =				d_ff
            _SCREAMING_SNAKE_CASE							:						str         =				dropout_rate
            _SCREAMING_SNAKE_CASE							:						Tuple         =				num_hidden_layers
            _SCREAMING_SNAKE_CASE							:						List[Any]         =				num_attention_heads
            _SCREAMING_SNAKE_CASE							:						Union[str, Any]         =				initializer_range
            _SCREAMING_SNAKE_CASE							:						int         =				initializer_factor
            _SCREAMING_SNAKE_CASE							:						int         =				attention_dropout
            _SCREAMING_SNAKE_CASE							:						int         =				layer_norm_eps
            _SCREAMING_SNAKE_CASE							:						List[Any]         =				dense_act_fn
            _SCREAMING_SNAKE_CASE							:						Optional[Any]         =				seq_len
            _SCREAMING_SNAKE_CASE							:						List[str]         =				relative_attention_num_buckets
            _SCREAMING_SNAKE_CASE							:						List[Any]         =				relative_attention_max_distance
            _SCREAMING_SNAKE_CASE							:						str         =				d_kv







       @classmethod
       def      UpperCamelCase_      (   cls     ,    __lowerCamelCase     ,    **__lowerCamelCase				)      ->  Optional[int]:
            cls._set_token_in_kwargs(__lowerCamelCase				)

            _SCREAMING_SNAKE_CASE     ,      _SCREAMING_SNAKE_CASE							:						Union[str, Any]         =				cls.get_config_dict(__lowerCamelCase     ,    **__lowerCamelCase				)

            # get the vision config dict if we are loading from Pix2StructConfig
            if config_dict.get("model_type"				) == "pix2struct":
                 _SCREAMING_SNAKE_CASE							:						str         =				config_dict["vision_config"]

            if "model_type" in config_dict and hasattr(cls     ,    "model_type"				) and config_dict["model_type"] != cls.model_type:
                 logger.warning(
                     F"""You are using a model of type {config_dict['model_type']} to instantiate a model of type """
                     F"""{cls.model_type}. This is not supported for all configurations of models and can yield errors."""				)

            return cls.from_dict(__lowerCamelCase     ,    **__lowerCamelCase				)





class       lowerCAmelCase__(			UpperCamelCase__     ):






       '''simple docstring'''


       __snake_case			      =     'pix2struct'
       __snake_case			      =     True




       def __init__(   self     ,    __lowerCamelCase=None     ,    __lowerCamelCase=None     ,    __lowerCamelCase=1.0     ,    __lowerCamelCase=0.02     ,    __lowerCamelCase=False     ,    __lowerCamelCase=False     ,    __lowerCamelCase=True     ,    **__lowerCamelCase     ,    )      ->  Optional[Any]:
            super().__init__(tie_word_embeddings=__lowerCamelCase     ,    is_encoder_decoder=__lowerCamelCase     ,    **__lowerCamelCase				)

            if text_config is None:
                 _SCREAMING_SNAKE_CASE							:						Tuple         =				{}
                 logger.info("text_config is None. Initializing the Pix2StructTextConfig with default values."				)

            if vision_config is None:
                 _SCREAMING_SNAKE_CASE							:						List[str]         =				{}
                 logger.info("vision_config is None. Initializing the Pix2StructVisionConfig with default values."				)

            _SCREAMING_SNAKE_CASE							:						Union[str, Any]         =				PixaStructTextConfig(**__lowerCamelCase				)
            _SCREAMING_SNAKE_CASE							:						Dict         =				PixaStructVisionConfig(**__lowerCamelCase				)

            _SCREAMING_SNAKE_CASE							:						List[str]         =				self.text_config.decoder_start_token_id
            _SCREAMING_SNAKE_CASE							:						int         =				self.text_config.pad_token_id
            _SCREAMING_SNAKE_CASE							:						List[str]         =				self.text_config.eos_token_id

            _SCREAMING_SNAKE_CASE							:						Tuple         =				initializer_factor
            _SCREAMING_SNAKE_CASE							:						List[Any]         =				initializer_range

            _SCREAMING_SNAKE_CASE							:						Union[str, Any]         =				self.initializer_range
            _SCREAMING_SNAKE_CASE							:						Any         =				self.initializer_range

            _SCREAMING_SNAKE_CASE							:						str         =				is_vqa




       @classmethod
       def      UpperCamelCase_      (   cls     ,    __lowerCamelCase     ,    __lowerCamelCase     ,    **__lowerCamelCase				)      ->  Optional[Any]:
            return cls(text_config=text_config.to_dict()     ,    vision_config=vision_config.to_dict()     ,    **__lowerCamelCase				)







       def      UpperCamelCase_      (   self				)      ->  Dict:
            _SCREAMING_SNAKE_CASE							:						str         =				copy.deepcopy(self.__dict__				)
            _SCREAMING_SNAKE_CASE							:						Optional[Any]         =				self.text_config.to_dict()
            _SCREAMING_SNAKE_CASE							:						List[str]         =				self.vision_config.to_dict()
            _SCREAMING_SNAKE_CASE							:						str         =				self.__class__.model_type
            return output

'''simple docstring'''
from math import log

from scipy.constants import Boltzmann, physical_constants

lowercase__											=3_00  # TEMPERATURE (unit = K)






def      UpperCamelCase_				(      A__  ,      A__  ,      A__  ,      ):

	if donor_conc <= 0:
		raise ValueError("""Donor concentration should be positive"""						)
	elif acceptor_conc <= 0:
		raise ValueError("""Acceptor concentration should be positive"""						)
	elif intrinsic_conc <= 0:
		raise ValueError("""Intrinsic concentration should be positive"""						)
	elif donor_conc <= intrinsic_conc:
		raise ValueError(
		    """Donor concentration should be greater than intrinsic concentration"""						)
	elif acceptor_conc <= intrinsic_conc:
		raise ValueError(
		    """Acceptor concentration should be greater than intrinsic concentration"""						)
	else:
		return (
		    Boltzmann
		    * T
		    * log((donor_conc * acceptor_conc) / intrinsic_conc**2						)
		    / physical_constants["electron volt"][0]
		)


if __name__ == "__main__":
		import doctest

		doctest.testmod()
