


import unittest

import numpy as np

from transformers import RobertaConfig, is_flax_available
from transformers.testing_utils import require_flax, slow

from ...test_modeling_flax_common import FlaxModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask


if is_flax_available():
 from transformers.models.roberta.modeling_flax_roberta import (
     FlaxRobertaForCausalLM,
     FlaxRobertaForMaskedLM,
     FlaxRobertaForMultipleChoice,
     FlaxRobertaForQuestionAnswering,
     FlaxRobertaForSequenceClassification,
     FlaxRobertaForTokenClassification,
     FlaxRobertaModel,
 )






class   __lowercase				(  unittest.TestCase  ):





      def __init__(		self						:					int					,       __lowerCamelCase						:					Tuple					,       __lowerCamelCase						:					int=1_3					,       __lowerCamelCase						:					Tuple=7					,       __lowerCamelCase						:					Union[str, Any]=True					,       __lowerCamelCase						:					List[str]=True					,       __lowerCamelCase						:					int=True					,       __lowerCamelCase						:					Dict=True					,       __lowerCamelCase						:					Dict=9_9					,       __lowerCamelCase						:					Dict=3_2					,       __lowerCamelCase						:					int=5					,       __lowerCamelCase						:					Optional[Any]=4					,       __lowerCamelCase						:					Optional[int]=3_7					,       __lowerCamelCase						:					Tuple="gelu"					,       __lowerCamelCase						:					List[Any]=0.1					,       __lowerCamelCase						:					Dict=0.1					,       __lowerCamelCase						:					Optional[int]=5_1_2					,       __lowerCamelCase						:					Dict=1_6					,       __lowerCamelCase						:					str=2					,       __lowerCamelCase						:					List[str]=0.02					,       __lowerCamelCase						:					Optional[Any]=4					,       )    ->   Optional[Any]:






         """simple docstring"""







         UpperCAmelCase							=     parent
         UpperCAmelCase							=     batch_size
         UpperCAmelCase							=     seq_length
         UpperCAmelCase							=     is_training
         UpperCAmelCase							=     use_attention_mask
         UpperCAmelCase							=     use_token_type_ids
         UpperCAmelCase							=     use_labels
         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_choices





      def        _lowercase				(		self						:					int       )    ->   Dict:






         """simple docstring"""







         UpperCAmelCase							=     ids_tensor([self.batch_size, self.seq_length]					,       self.vocab_size       )

         UpperCAmelCase							=     None
         if self.use_attention_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							=     RobertaConfig(
             vocab_size=self.vocab_size					,       hidden_size=self.hidden_size					,       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					,       is_decoder=__lowerCamelCase					,       initializer_range=self.initializer_range					,       )

         return config, input_ids, token_type_ids, attention_mask





      def        _lowercase				(		self						:					Optional[int]       )    ->   Optional[Any]:






         """simple docstring"""







         UpperCAmelCase							=     self.prepare_config_and_inputs()
         UpperCAmelCase				,  UpperCAmelCase				,  UpperCAmelCase				,  UpperCAmelCase							=     config_and_inputs
         UpperCAmelCase							=     {"""input_ids""": input_ids, """token_type_ids""": token_type_ids, """attention_mask""": attention_mask}
         return config, inputs_dict





      def        _lowercase				(		self						:					int       )    ->   Any:






         """simple docstring"""







         UpperCAmelCase							=     self.prepare_config_and_inputs()
         UpperCAmelCase				,  UpperCAmelCase				,  UpperCAmelCase				,  UpperCAmelCase							=     config_and_inputs

         UpperCAmelCase							=     True
         UpperCAmelCase							=     floats_tensor([self.batch_size, self.seq_length, self.hidden_size]       )
         UpperCAmelCase							=     ids_tensor([self.batch_size, self.seq_length]					,       vocab_size=2       )

         return (
             config,
             input_ids,
             token_type_ids,
             encoder_hidden_states,
             encoder_attention_mask,
         )






@require_flax
class   __lowercase				(  __snake_case ,					unittest.TestCase  ):
      UpperCamelCase								=       True

      UpperCamelCase								=       (
          (
              FlaxRobertaModel,
              FlaxRobertaForCausalLM,
              FlaxRobertaForMaskedLM,
              FlaxRobertaForSequenceClassification,
              FlaxRobertaForTokenClassification,
              FlaxRobertaForMultipleChoice,
              FlaxRobertaForQuestionAnswering,
          )
          if is_flax_available()
          else ()
      )





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






         """simple docstring"""







         UpperCAmelCase							=     FlaxRobertaModelTester(self       )





      @slow
      def        _lowercase				(		self						:					Tuple       )    ->   str:






         """simple docstring"""







         for model_class_name in self.all_model_classes:
            UpperCAmelCase							=     model_class_name.from_pretrained("""roberta-base"""					,       from_pt=__lowerCamelCase       )
            UpperCAmelCase							=     model(np.ones((1, 1)       )       )
            self.assertIsNotNone(__lowerCamelCase       )







import math

import qiskit
def   _UpperCamelCase				(						lowerCAmelCase_ = 1  ,						lowerCAmelCase_ = 1  ,						lowerCAmelCase_ = 1   )						->qiskit.result.counts.Counts:
   if (
       isinstance(lowerCAmelCase_  ,						lowerCAmelCase_   )
       or isinstance(lowerCAmelCase_  ,						lowerCAmelCase_   )
       or isinstance(lowerCAmelCase_  ,						lowerCAmelCase_   )
   ):
      raise TypeError("""inputs must be integers."""   )

   if (input_a < 0) or (input_a < 0) or (carry_in < 0):
      raise ValueError("""inputs must be positive."""   )

   if (
       (math.floor(lowerCAmelCase_   ) != input_a)
       or (math.floor(lowerCAmelCase_   ) != input_a)
       or (math.floor(lowerCAmelCase_   ) != carry_in)
   ):
      raise ValueError("""inputs must be exact integers."""   )

   if (input_a > 2) or (input_a > 2) or (carry_in > 2):
      raise ValueError("""inputs must be less or equal to 2."""   )

   # build registers
   UpperCAmelCase							=     qiskit.QuantumRegister(4  ,						"""qr"""   )
   UpperCAmelCase							=     qiskit.ClassicalRegister(2  ,						"""cr"""   )
   # list the entries
   UpperCAmelCase							=     [input_a, input_a, carry_in]

   UpperCAmelCase							=     qiskit.QuantumCircuit(lowerCAmelCase_  ,						lowerCAmelCase_   )

   for i in range(0  ,						3   ):
      if entry[i] == 2:
         quantum_circuit.h(lowerCAmelCase_   )  # for hadamard entries
      elif entry[i] == 1:
         quantum_circuit.x(lowerCAmelCase_   )  # for 1 entries
      elif entry[i] == 0:
         quantum_circuit.i(lowerCAmelCase_   )  # for 0 entries

    # build the circuit
   quantum_circuit.ccx(0  ,						1  ,						3   )  # ccx = toffoli gate
   quantum_circuit.cx(0  ,						1   )
   quantum_circuit.ccx(1  ,						2  ,						3   )
   quantum_circuit.cx(1  ,						2   )
   quantum_circuit.cx(0  ,						1   )

   quantum_circuit.measure([2, 3]  ,						lowerCAmelCase_   )  # measure the last two qbits

   UpperCAmelCase							=     qiskit.Aer.get_backend("""aer_simulator"""   )
   UpperCAmelCase							=     qiskit.execute(lowerCAmelCase_  ,						lowerCAmelCase_  ,						shots=1_0_0_0   )

   return job.result().get_counts(lowerCAmelCase_   )


if __name__ == "__main__":
 print(F"""Total sum count for state is: {quantum_full_adder(1, 1, 1)}""")



