'''simple docstring'''





import gc
import unittest

from transformers import CTRLConfig, is_torch_available
from transformers.testing_utils import require_torch, slow, torch_device

from ...generation.test_utils import GenerationTesterMixin
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 import (
        CTRL_PRETRAINED_MODEL_ARCHIVE_LIST,
        CTRLForSequenceClassification,
        CTRLLMHeadModel,
        CTRLModel,
    )




class        __A      :



    def __init__(self    :    str   ,			__a    :    Optional[Any]   ,			__a    :    Union[str, Any]=14   ,			__a    :    List[str]=7   ,			__a    :    Union[str, Any]=True   ,			__a    :    int=True   ,			__a    :    List[str]=True   ,			__a    :    str=True   ,			__a    :    str=True   ,			__a    :    List[str]=99   ,			__a    :    Union[str, Any]=32   ,			__a    :    Optional[Any]=5   ,			__a    :    int=4   ,			__a    :    List[Any]=37   ,			__a    :    Optional[Any]="gelu"   ,			__a    :    Tuple=0.1   ,			__a    :    Any=0.1   ,			__a    :    int=512   ,			__a    :    int=16   ,			__a    :    Optional[int]=2   ,			__a    :    Any=0.02   ,			__a    :    str=3   ,			__a    :    Optional[Any]=4   ,			__a    :    Optional[Any]=None   ,			):
         UpperCAmelCase_           =   parent
         UpperCAmelCase_           =   batch_size
         UpperCAmelCase_           =   seq_length
         UpperCAmelCase_           =   is_training
         UpperCAmelCase_           =   use_token_type_ids
         UpperCAmelCase_           =   use_input_mask
         UpperCAmelCase_           =   use_labels
         UpperCAmelCase_           =   use_mc_token_ids
         UpperCAmelCase_           =   vocab_size
         UpperCAmelCase_           =   hidden_size
         UpperCAmelCase_           =   num_hidden_layers
         UpperCAmelCase_           =   num_attention_heads
         UpperCAmelCase_           =   intermediate_size
         UpperCAmelCase_           =   hidden_act
         UpperCAmelCase_           =   hidden_dropout_prob
         UpperCAmelCase_           =   attention_probs_dropout_prob
         UpperCAmelCase_           =   max_position_embeddings
         UpperCAmelCase_           =   type_vocab_size
         UpperCAmelCase_           =   type_sequence_label_size
         UpperCAmelCase_           =   initializer_range
         UpperCAmelCase_           =   num_labels
         UpperCAmelCase_           =   num_choices
         UpperCAmelCase_           =   scope
         UpperCAmelCase_           =   self.vocab_size - 1



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

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

         UpperCAmelCase_           =   None
         if self.use_token_type_ids:
              UpperCAmelCase_           =   ids_tensor([self.batch_size, self.seq_length]   ,			self.type_vocab_size )

         UpperCAmelCase_           =   None
         if self.use_mc_token_ids:
              UpperCAmelCase_           =   ids_tensor([self.batch_size, self.num_choices]   ,			self.seq_length )

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

         UpperCAmelCase_           =   self.get_config()

         UpperCAmelCase_           =   ids_tensor([self.num_hidden_layers, self.num_attention_heads]   ,			2 )

         return (
             config,
             input_ids,
             input_mask,
             head_mask,
             token_type_ids,
             mc_token_ids,
             sequence_labels,
             token_labels,
             choice_labels,
         )



    def 					_lowercase						(self    :    Optional[int] ):
         return CTRLConfig(
             vocab_size=self.vocab_size   ,			n_embd=self.hidden_size   ,			n_layer=self.num_hidden_layers   ,			n_head=self.num_attention_heads   ,			n_positions=self.max_position_embeddings   ,			pad_token_id=self.pad_token_id   ,			)



    def 					_lowercase						(self    :    Dict   ,			__a    :    List[str]   ,			__a    :    int   ,			__a    :    Tuple   ,			__a    :    int   ,			__a    :    Union[str, Any]   ,			*__a    :    List[Any] ):
         UpperCAmelCase_           =   CTRLModel(config=__a )
         model.to(__a )
         model.eval()

         model(__a   ,			token_type_ids=__a   ,			head_mask=__a )
         model(__a   ,			token_type_ids=__a )
         UpperCAmelCase_           =   model(__a )
         self.parent.assertEqual(result.last_hidden_state.shape   ,			(self.batch_size, self.seq_length, self.hidden_size) )
         self.parent.assertEqual(len(result.past_key_values )   ,			config.n_layer )



    def 					_lowercase						(self    :    List[Any]   ,			__a    :    Tuple   ,			__a    :    Any   ,			__a    :    Tuple   ,			__a    :    str   ,			__a    :    Tuple   ,			*__a    :    str ):
         UpperCAmelCase_           =   CTRLLMHeadModel(__a )
         model.to(__a )
         model.eval()

         UpperCAmelCase_           =   model(__a   ,			token_type_ids=__a   ,			labels=__a )
         self.parent.assertEqual(result.loss.shape   ,			() )
         self.parent.assertEqual(result.logits.shape   ,			(self.batch_size, self.seq_length, self.vocab_size) )



    def 					_lowercase						(self    :    List[str] ):
         UpperCAmelCase_           =   self.prepare_config_and_inputs()

         (
             (
             UpperCAmelCase_
         )    , (
             UpperCAmelCase_
         )    , (
             UpperCAmelCase_
         )    , (
             UpperCAmelCase_
         )    , (
             UpperCAmelCase_
         )    , (
             UpperCAmelCase_
         )    , (
             UpperCAmelCase_
         )    , (
             UpperCAmelCase_
         )    , (
             UpperCAmelCase_
         )    , 
         )           =   config_and_inputs

         UpperCAmelCase_           =   {"input_ids": input_ids, "token_type_ids": token_type_ids, "head_mask": head_mask}

         return config, inputs_dict






    def 					_lowercase						(self    :    Tuple   ,			__a    :    str   ,			__a    :    Union[str, Any]   ,			__a    :    List[str]   ,			__a    :    Optional[Any]   ,			*__a    :    Optional[int] ):
         UpperCAmelCase_           =   self.num_labels
         UpperCAmelCase_           =   CTRLForSequenceClassification(__a )
         model.to(__a )
         model.eval()
         UpperCAmelCase_           =   ids_tensor([self.batch_size]   ,			self.type_sequence_label_size )
         UpperCAmelCase_           =   model(__a   ,			token_type_ids=__a   ,			labels=__a )
         self.parent.assertEqual(result.logits.shape   ,			(self.batch_size, self.num_labels) )




@require_torch
class        __A      ( UpperCamelCase__		,	UpperCamelCase__		,	UpperCamelCase__		,	unittest.TestCase	):
    a__       :						Dict          =  (CTRLModel, CTRLLMHeadModel, CTRLForSequenceClassification) if is_torch_available() else ()
    a__       :						Union[str, Any]          =  (CTRLLMHeadModel,) if is_torch_available() else ()
    a__       :						List[Any]          =  (
        {
            """feature-extraction""": CTRLModel,
            """text-classification""": CTRLForSequenceClassification,
            """text-generation""": CTRLLMHeadModel,
            """zero-shot""": CTRLForSequenceClassification,
        }
        if is_torch_available()
        else {}
    )
    a__       :						Any          =  True
    a__       :						Union[str, Any]          =  False
    a__       :						Dict          =  False



    def 					_lowercase						(self    :    List[Any]   ,			__a    :    int   ,			__a    :    Optional[int]   ,			__a    :    Dict   ,			__a    :    int   ,			__a    :    List[Any] ):
         if pipeline_test_casse_name == "ZeroShotClassificationPipelineTests":
              # Get `tokenizer does not have a padding token` error for both fast/slow tokenizers.
              # `CTRLConfig` was never used in pipeline tests, either because of a missing checkpoint or because a tiny
              # config could not be created.
              return True

         return False



    def 					_lowercase						(self    :    Any ):
         UpperCAmelCase_           =   CTRLModelTester(self )
         UpperCAmelCase_           =   ConfigTester(self   ,			config_class=__a   ,			n_embd=37 )



    def 					_lowercase						(self    :    Union[str, Any] ):
         super().tearDown()
         # clean-up as much as possible GPU memory occupied by PyTorch
         gc.collect()
         torch.cuda.empty_cache()



    def 					_lowercase						(self    :    Optional[int] ):
         self.config_tester.run_common_tests()



    def 					_lowercase						(self    :    Union[str, Any] ):
         UpperCAmelCase_           =   self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_ctrl_model(*__a )



    def 					_lowercase						(self    :    str ):
         UpperCAmelCase_           =   self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_lm_head_model(*__a )



    @unittest.skip("Will be fixed soon by reducing the size of the model used for common tests." )
    def 					_lowercase						(self    :    Optional[int] ):
         pass



    @slow
    def 					_lowercase						(self    :    Union[str, Any] ):
         for model_name in CTRL_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
              UpperCAmelCase_           =   CTRLModel.from_pretrained(__a )
              self.assertIsNotNone(__a )






    @unittest.skip("The model doesn't support left padding" )  # and it's not used enough to be worth fixing :)
    def 					_lowercase						(self    :    List[str] ):
         pass




@require_torch
class        __A      ( unittest.TestCase	):



    def 					_lowercase						(self    :    Optional[Any] ):
         super().tearDown()
         # clean-up as much as possible GPU memory occupied by PyTorch
         gc.collect()
         torch.cuda.empty_cache()






    @slow
    def 					_lowercase						(self    :    Optional[int] ):
         UpperCAmelCase_           =   CTRLLMHeadModel.from_pretrained("ctrl" )
         model.to(__a )
         UpperCAmelCase_           =   torch.tensor(
             [[11859, 0, 1611, 8]]   ,			dtype=torch.long   ,			device=__a )  # Legal the president is
         UpperCAmelCase_           =   [
             11859,
             0,
             1611,
             8,
             5,
             150,
             26449,
             2,
             19,
             348,
             469,
             3,
             2595,
             48,
             20740,
             246533,
             246533,
             19,
             30,
             5,
         ]  # Legal the president is a good guy and I don't want to lose my job. \n \n I have a

         UpperCAmelCase_           =   model.generate(__a   ,			do_sample=__a )
         self.assertListEqual(output_ids[0].tolist()   ,			__a )





'''simple docstring'''





from math import log

from scipy.constants import Boltzmann, physical_constants

SCREAMING_SNAKE_CASE_:     Optional[int]  =3_00  # TEMPERATURE (unit = K)





def 	lowerCAmelCase_				(					snake_case_       : float					,    snake_case_       : float					,    snake_case_       : float					,    )    ->      float:


     '''simple docstring'''




     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()




