

"""simple docstring"""


from __future__ import annotations

import unittest

from transformers import OpenAIGPTConfig, is_tf_available
from transformers.testing_utils import require_tf, slow

from ...test_configuration_common import ConfigTester
from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_tf_available():
   import tensorflow as tf

   from transformers.models.openai.modeling_tf_openai import (
       TF_OPENAI_GPT_PRETRAINED_MODEL_ARCHIVE_LIST,
       TFOpenAIGPTDoubleHeadsModel,
       TFOpenAIGPTForSequenceClassification,
       TFOpenAIGPTLMHeadModel,
       TFOpenAIGPTModel,
   )





class 					snake_case			:

    def __init__(			self							:       Union[str, Any]  ,						UpperCamelCase__							:       int  ,						)->     int:



      '''simple docstring'''


      __lowerCAmelCase: Tuple					   =    parent
      __lowerCAmelCase: str					   =    1_3
      __lowerCAmelCase: List[str]					   =    7
      __lowerCAmelCase: Any					   =    True
      __lowerCAmelCase: List[str]					   =    True
      __lowerCAmelCase: List[Any]					   =    True
      __lowerCAmelCase: Union[str, Any]					   =    True
      __lowerCAmelCase: Tuple					   =    True
      __lowerCAmelCase: List[Any]					   =    9_9
      __lowerCAmelCase: Optional[int]					   =    3_2
      __lowerCAmelCase: Optional[Any]					   =    2
      __lowerCAmelCase: Any					   =    4
      __lowerCAmelCase: Union[str, Any]					   =    3_7
      __lowerCAmelCase: Optional[int]					   =    "gelu"
      __lowerCAmelCase: int					   =    0.1
      __lowerCAmelCase: Any					   =    0.1
      __lowerCAmelCase: Optional[int]					   =    5_1_2
      __lowerCAmelCase: List[str]					   =    1_6
      __lowerCAmelCase: Optional[Any]					   =    2
      __lowerCAmelCase: Optional[int]					   =    0.02
      __lowerCAmelCase: str					   =    3
      __lowerCAmelCase: str					   =    4
      __lowerCAmelCase: Any					   =    None
      __lowerCAmelCase: str					   =    self.vocab_size - 1

    def 							lowercase_  (			self							:       Dict)->     Dict:



      '''simple docstring'''


      __lowerCAmelCase: List[str]					   =    ids_tensor([self.batch_size, self.seq_length]  ,						self.vocab_size)

      __lowerCAmelCase: str					   =    None
      if self.use_input_mask:
        __lowerCAmelCase: Optional[Any]					   =    random_attention_mask([self.batch_size, self.seq_length])

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

      __lowerCAmelCase: List[str]					   =    None
      if self.use_mc_token_ids:
        __lowerCAmelCase: Dict					   =    ids_tensor([self.batch_size, self.num_choices]  ,						self.seq_length)

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

      __lowerCAmelCase: Optional[int]					   =    OpenAIGPTConfig(
          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  ,						)

      __lowerCAmelCase: Optional[int]					   =    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[Any]  ,						UpperCamelCase__							:       Tuple  ,						UpperCamelCase__							:       str  ,						UpperCamelCase__							:       Dict  ,						UpperCamelCase__							:       List[Any]  ,						UpperCamelCase__							:       str  ,						*UpperCamelCase__							:       List[str])->     Optional[Any]:



      '''simple docstring'''


      __lowerCAmelCase: Union[str, Any]					   =    TFOpenAIGPTModel(config=lowercase_)
      __lowerCAmelCase: int					   =    {"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
      __lowerCAmelCase: Dict					   =    model(lowercase_)

      __lowerCAmelCase: Any					   =    [input_ids, input_mask]
      __lowerCAmelCase: List[Any]					   =    model(lowercase_)

      __lowerCAmelCase: int					   =    model(lowercase_)

      self.parent.assertEqual(result.last_hidden_state.shape  ,						(self.batch_size, self.seq_length, self.hidden_size))

    def 							lowercase_  (			self							:       Dict  ,						UpperCamelCase__							:       int  ,						UpperCamelCase__							:       int  ,						UpperCamelCase__							:       int  ,						UpperCamelCase__							:       Optional[int]  ,						UpperCamelCase__							:       List[str]  ,						*UpperCamelCase__							:       Dict)->     Optional[int]:



      '''simple docstring'''


      __lowerCAmelCase: Tuple					   =    TFOpenAIGPTLMHeadModel(config=lowercase_)
      __lowerCAmelCase: List[str]					   =    {"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
      __lowerCAmelCase: Optional[Any]					   =    model(lowercase_)
      self.parent.assertEqual(result.logits.shape  ,						(self.batch_size, self.seq_length, self.vocab_size))

    def 							lowercase_  (			self							:       Optional[Any]  ,						UpperCamelCase__							:       Optional[int]  ,						UpperCamelCase__							:       Optional[Any]  ,						UpperCamelCase__							:       str  ,						UpperCamelCase__							:       Dict  ,						UpperCamelCase__							:       List[Any]  ,						UpperCamelCase__							:       Dict  ,						*UpperCamelCase__							:       int)->     List[Any]:



      '''simple docstring'''


      __lowerCAmelCase: int					   =    TFOpenAIGPTDoubleHeadsModel(config=lowercase_)

      __lowerCAmelCase: Optional[Any]					   =    tf.tile(tf.expand_dims(lowercase_  ,						1)  ,						(1, self.num_choices, 1))
      __lowerCAmelCase: Dict					   =    tf.tile(tf.expand_dims(lowercase_  ,						1)  ,						(1, self.num_choices, 1))
      __lowerCAmelCase: Union[str, Any]					   =    tf.tile(tf.expand_dims(lowercase_  ,						1)  ,						(1, self.num_choices, 1))

      __lowerCAmelCase: str					   =    {
          "input_ids": multiple_choice_inputs_ids,
          "mc_token_ids": mc_token_ids,
          "attention_mask": multiple_choice_input_mask,
          "token_type_ids": multiple_choice_token_type_ids,
      }
      __lowerCAmelCase: List[str]					   =    model(lowercase_)
      self.parent.assertEqual(
          result.logits.shape  ,						(self.batch_size, self.num_choices, self.seq_length, self.vocab_size))
      self.parent.assertEqual(result.mc_logits.shape  ,						(self.batch_size, self.num_choices))

    def 							lowercase_  (			self							:       Union[str, Any]  ,						UpperCamelCase__							:       Optional[int]  ,						UpperCamelCase__							:       int  ,						UpperCamelCase__							:       Any  ,						UpperCamelCase__							:       Optional[Any]  ,						UpperCamelCase__							:       Optional[int]  ,						*UpperCamelCase__							:       Dict)->     List[Any]:



      '''simple docstring'''


      __lowerCAmelCase: Dict					   =    self.num_labels
      __lowerCAmelCase: Union[str, Any]					   =    ids_tensor([self.batch_size]  ,						self.type_sequence_label_size)
      __lowerCAmelCase: List[str]					   =    {
          "input_ids": input_ids,
          "attention_mask": input_mask,
          "token_type_ids": token_type_ids,
          "labels": sequence_labels,
      }
      __lowerCAmelCase: Optional[Any]					   =    TFOpenAIGPTForSequenceClassification(lowercase_)
      __lowerCAmelCase: Union[str, Any]					   =    model(lowercase_)
      self.parent.assertEqual(result.logits.shape  ,						(self.batch_size, self.num_labels))




    def 							lowercase_  (			self							:       List[str])->     Union[str, Any]:



      '''simple docstring'''


      __lowerCAmelCase: Dict					   =    self.prepare_config_and_inputs()

      (
          (
          __lowerCAmelCase   
      )   ,				(
          __lowerCAmelCase   
      )   ,				(
          __lowerCAmelCase   
      )   ,				(
          __lowerCAmelCase   
      )   ,				(
          __lowerCAmelCase   
      )   ,				(
          __lowerCAmelCase   
      )   ,				(
          __lowerCAmelCase   
      )   ,				(
          __lowerCAmelCase   
      )   ,				(
          __lowerCAmelCase   
      )   ,				   
      ): str					   =    config_and_inputs

      __lowerCAmelCase: List[Any]					   =    {"input_ids": input_ids, "token_type_ids": token_type_ids, "attention_mask": input_mask}
      return config, inputs_dict





@require_tf
class 					snake_case			(       lowerCamelCase__,							lowerCamelCase__,							unittest.TestCase						):
    SCREAMING_SNAKE_CASE_     :   Optional[int]        =						(
        (TFOpenAIGPTModel, TFOpenAIGPTLMHeadModel, TFOpenAIGPTDoubleHeadsModel, TFOpenAIGPTForSequenceClassification)
        if is_tf_available()
        else ()
    )
    SCREAMING_SNAKE_CASE_     :   str        =						(
        (TFOpenAIGPTLMHeadModel,) if is_tf_available() else ()
    )  # TODO (PVP): Add Double HeadsModel when generate() function is changed accordingly
    SCREAMING_SNAKE_CASE_     :   str        =						(
        {
            'feature-extraction': TFOpenAIGPTModel,
            'text-classification': TFOpenAIGPTForSequenceClassification,
            'text-generation': TFOpenAIGPTLMHeadModel,
            'zero-shot': TFOpenAIGPTForSequenceClassification,
        }
        if is_tf_available()
        else {}
    )
    SCREAMING_SNAKE_CASE_     :   Union[str, Any]        =						False
    SCREAMING_SNAKE_CASE_     :   Optional[Any]        =						False

    def 							lowercase_  (			self							:       List[Any]  ,						UpperCamelCase__							:       List[Any]  ,						UpperCamelCase__							:       Dict  ,						UpperCamelCase__							:       Union[str, Any]  ,						UpperCamelCase__							:       List[Any]  ,						UpperCamelCase__							:       List[str])->     int:



      '''simple docstring'''


      if pipeline_test_casse_name == "ZeroShotClassificationPipelineTests":
        # Get `tokenizer does not have a padding token` error for both fast/slow tokenizers.
        # `OpenAIGPTConfig` 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							:       int)->     Optional[int]:



      '''simple docstring'''


      __lowerCAmelCase: Any					   =    TFOpenAIGPTModelTester(self)
      __lowerCAmelCase: List[Any]					   =    ConfigTester(self  ,						config_class=lowercase_  ,						n_embd=3_7)

    def 							lowercase_  (			self							:       Any)->     int:



      '''simple docstring'''


      self.config_tester.run_common_tests()

    def 							lowercase_  (			self							:       Union[str, Any])->     str:



      '''simple docstring'''


      __lowerCAmelCase: Optional[int]					   =    self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_openai_gpt_model(*lowercase_)

    def 							lowercase_  (			self							:       List[Any])->     Dict:



      '''simple docstring'''


      __lowerCAmelCase: int					   =    self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_openai_gpt_lm_head(*lowercase_)

    def 							lowercase_  (			self							:       Dict)->     Any:



      '''simple docstring'''


      __lowerCAmelCase: str					   =    self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_openai_gpt_double_head(*lowercase_)

    def 							lowercase_  (			self							:       Optional[Any])->     Tuple:



      '''simple docstring'''


      __lowerCAmelCase: str					   =    self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_openai_gpt_for_sequence_classification(*lowercase_)




    @slow
    def 							lowercase_  (			self							:       List[str])->     int:



      '''simple docstring'''


      for model_name in TF_OPENAI_GPT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
        __lowerCAmelCase: Tuple					   =    TFOpenAIGPTModel.from_pretrained(lowercase_)
        self.assertIsNotNone(lowercase_)





@require_tf
class 					snake_case			(       unittest.TestCase						):

    @slow
    def 							lowercase_  (			self							:       Any)->     List[str]:



      '''simple docstring'''


      __lowerCAmelCase: List[Any]					   =    TFOpenAIGPTLMHeadModel.from_pretrained("openai-gpt")
      __lowerCAmelCase: Dict					   =    tf.convert_to_tensor([[4_8_1, 4_7_3_5, 5_4_4]]  ,						dtype=tf.intaa)  # the president is
      __lowerCAmelCase: str					   =    [
          4_8_1,
          4_7_3_5,
          5_4_4,
          2_4_6,
          9_6_3,
          8_7_0,
          7_6_2,
          2_3_9,
          2_4_4,
          4_0_4_7_7,
          2_4_4,
          2_4_9,
          7_1_9,
          8_8_1,
          4_8_7,
          5_4_4,
          2_4_0,
          2_4_4,
          6_0_3,
          4_8_1,
      ]  # the president is a very good man. " \n " i\'m sure he is, " said the

      __lowerCAmelCase: Optional[int]					   =    model.generate(lowercase_  ,						do_sample=lowercase_)
      self.assertListEqual(output_ids[0].numpy().tolist()  ,						lowercase_)





"""simple docstring"""


import math

import qiskit
from qiskit import Aer, ClassicalRegister, QuantumCircuit, QuantumRegister, execute






def 					a__					(					__SCREAMING_SNAKE_CASE = 1      ,				__SCREAMING_SNAKE_CASE = 1				)			->			qiskit.result.counts.Counts:
		if isinstance(__SCREAMING_SNAKE_CASE      ,				__SCREAMING_SNAKE_CASE				) or isinstance(__SCREAMING_SNAKE_CASE      ,				__SCREAMING_SNAKE_CASE				):
				raise TypeError("inputs must be integers."				)
		if (bit_a < 0) or (bit_a < 0):
				raise ValueError("inputs must be positive."				)
		if (math.floor(__SCREAMING_SNAKE_CASE				) != bit_a) or (math.floor(__SCREAMING_SNAKE_CASE				) != bit_a):
				raise ValueError("inputs must be exact integers."				)
		if (bit_a > 1) or (bit_a > 1):
				raise ValueError("inputs must be less or equal to 1."				)

		# build registers
		__lowerCAmelCase: str					   =    QuantumRegister(2      ,				"qr"				)
		__lowerCAmelCase: Optional[Any]					   =    ClassicalRegister(2      ,				"cr"				)

		__lowerCAmelCase: Dict					   =    QuantumCircuit(__SCREAMING_SNAKE_CASE      ,				__SCREAMING_SNAKE_CASE				)

		# entanglement the qubits
		quantum_circuit.h(1				)
		quantum_circuit.cx(1      ,				0				)

		# send the information
		__lowerCAmelCase: Dict					   =    str(__SCREAMING_SNAKE_CASE				) + str(__SCREAMING_SNAKE_CASE				)

		if c_information == "11":
				quantum_circuit.x(1				)
				quantum_circuit.z(1				)
		elif c_information == "10":
				quantum_circuit.z(1				)
		elif c_information == "01":
				quantum_circuit.x(1				)
		else:
				quantum_circuit.i(1				)

		# unentangled the circuit
		quantum_circuit.cx(1      ,				0				)
		quantum_circuit.h(1				)

		# measure the circuit
		quantum_circuit.measure(__SCREAMING_SNAKE_CASE      ,				__SCREAMING_SNAKE_CASE				)

		__lowerCAmelCase: List[str]					   =    Aer.get_backend("aer_simulator"				)
		__lowerCAmelCase: Dict					   =    execute(__SCREAMING_SNAKE_CASE      ,				__SCREAMING_SNAKE_CASE      ,				shots=1_0_0_0				)

		return job.result().get_counts(__SCREAMING_SNAKE_CASE				)


if __name__ == "__main__":
			print(F'''Counts for classical state send: {superdense_coding(1,1)}''')


