


import unittest

import numpy as np

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

from ...test_modeling_flax_common import FlaxModelTesterMixin, ids_tensor, random_attention_mask


if is_flax_available():
       import jax.numpy as jnp

       from transformers.models.distilbert.modeling_flax_distilbert import (
           FlaxDistilBertForMaskedLM,
           FlaxDistilBertForMultipleChoice,
           FlaxDistilBertForQuestionAnswering,
           FlaxDistilBertForSequenceClassification,
           FlaxDistilBertForTokenClassification,
           FlaxDistilBertModel,
       )





class  lowerCAmelCase__(    unittest.TestCase						):






    '''simple docstring'''





    def __init__(	self				:   Dict       ,   __snake_case				:   Optional[int]       ,   __snake_case				:   int=13       ,   __snake_case				:   Optional[Any]=7       ,   __snake_case				:   Optional[int]=True       ,   __snake_case				:   Optional[int]=True       ,   __snake_case				:   Union[str, Any]=True       ,   __snake_case				:   int=True       ,   __snake_case				:   List[str]=99       ,   __snake_case				:   List[str]=32       ,   __snake_case				:   Tuple=5       ,   __snake_case				:   int=4       ,   __snake_case				:   List[Any]=37       ,   __snake_case				:   str="gelu"       ,   __snake_case				:   Optional[int]=0.1       ,   __snake_case				:   List[Any]=0.1       ,   __snake_case				:   Optional[int]=512       ,   __snake_case				:   Tuple=16       ,   __snake_case				:   List[str]=2       ,   __snake_case				:   List[Any]=0.02       ,   __snake_case				:   Tuple=4       ,   ):





       '''simple docstring'''
       UpperCAmelCase_							:      Optional[int]						=   parent
       UpperCAmelCase_							:      Tuple						=   batch_size
       UpperCAmelCase_							:      Union[str, Any]						=   seq_length
       UpperCAmelCase_							:      Tuple						=   is_training
       UpperCAmelCase_							:      Union[str, Any]						=   use_attention_mask
       UpperCAmelCase_							:      Dict						=   use_token_type_ids
       UpperCAmelCase_							:      int						=   use_labels
       UpperCAmelCase_							:      Any						=   vocab_size
       UpperCAmelCase_							:      Optional[int]						=   hidden_size
       UpperCAmelCase_							:      str						=   num_hidden_layers
       UpperCAmelCase_							:      Optional[Any]						=   num_attention_heads
       UpperCAmelCase_							:      List[str]						=   intermediate_size
       UpperCAmelCase_							:      Optional[Any]						=   hidden_act
       UpperCAmelCase_							:      List[str]						=   hidden_dropout_prob
       UpperCAmelCase_							:      Dict						=   attention_probs_dropout_prob
       UpperCAmelCase_							:      List[str]						=   max_position_embeddings
       UpperCAmelCase_							:      Union[str, Any]						=   type_vocab_size
       UpperCAmelCase_							:      str						=   type_sequence_label_size
       UpperCAmelCase_							:      str						=   initializer_range
       UpperCAmelCase_							:      List[Any]						=   num_choices





    def 					_lowerCamelCase (	self				:   Optional[Any]	):





       '''simple docstring'''
       UpperCAmelCase_							:      Optional[Any]						=   ids_tensor([self.batch_size, self.seq_length]       ,   self.vocab_size	)

       UpperCAmelCase_							:      Optional[int]						=   None
       if self.use_attention_mask:
          UpperCAmelCase_							:      Any						=   random_attention_mask([self.batch_size, self.seq_length]	)

       UpperCAmelCase_							:      List[str]						=   DistilBertConfig(
           vocab_size=self.vocab_size       ,   dim=self.hidden_size       ,   n_layers=self.num_hidden_layers       ,   n_heads=self.num_attention_heads       ,   hidden_dim=self.intermediate_size       ,   hidden_act=self.hidden_act       ,   dropout=self.hidden_dropout_prob       ,   attention_dropout=self.attention_probs_dropout_prob       ,   max_position_embeddings=self.max_position_embeddings       ,   initializer_range=self.initializer_range       ,   tie_weights_=__snake_case       ,   )

       return config, input_ids, attention_mask





    def 					_lowerCamelCase (	self				:   Any	):





       '''simple docstring'''
       UpperCAmelCase_							:      Optional[Any]						=   self.prepare_config_and_inputs()
       UpperCAmelCase_		,      UpperCAmelCase_		,      UpperCAmelCase_							:      Tuple						=   config_and_inputs
       UpperCAmelCase_							:      int						=   {'''input_ids''': input_ids, '''attention_mask''': attention_mask}
       return config, inputs_dict





@require_flax
class  lowerCAmelCase__(    snake_case__    ,    unittest.TestCase						):






    '''simple docstring'''





    A_  :     Optional[int]			= (
        (
            FlaxDistilBertModel,
            FlaxDistilBertForMaskedLM,
            FlaxDistilBertForMultipleChoice,
            FlaxDistilBertForQuestionAnswering,
            FlaxDistilBertForSequenceClassification,
            FlaxDistilBertForTokenClassification,
            FlaxDistilBertForQuestionAnswering,
        )
        if is_flax_available()
        else ()
    )





    def 					_lowerCamelCase (	self				:   List[str]	):





       '''simple docstring'''
       UpperCAmelCase_							:      int						=   FlaxDistilBertModelTester(self	)





    @slow
    def 					_lowerCamelCase (	self				:   Optional[int]	):





       '''simple docstring'''
       for model_class_name in self.all_model_classes:
          UpperCAmelCase_							:      str						=   model_class_name.from_pretrained('''distilbert-base-uncased'''	)
          UpperCAmelCase_							:      Union[str, Any]						=   model(np.ones((1, 1)	)	)
          self.assertIsNotNone(__snake_case	)





@require_flax
class  lowerCAmelCase__(    unittest.TestCase						):






    '''simple docstring'''





    @slow
    def 					_lowerCamelCase (	self				:   List[Any]	):





       '''simple docstring'''
       UpperCAmelCase_							:      Optional[Any]						=   FlaxDistilBertModel.from_pretrained('''distilbert-base-uncased'''	)
       UpperCAmelCase_							:      Optional[Any]						=   np.array([[0, 345, 232, 328, 740, 140, 1_695, 69, 6_078, 1_588, 2]]	)
       UpperCAmelCase_							:      Tuple						=   np.array([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]	)
       UpperCAmelCase_							:      str						=   model(__snake_case       ,   attention_mask=__snake_case	)[0]
       UpperCAmelCase_							:      List[Any]						=   (1, 11, 768)
       self.assertEqual(output.shape       ,   __snake_case	)
       UpperCAmelCase_							:      List[Any]						=   np.array([[[-0.1_639, 0.3_299, 0.1_648], [-0.1_746, 0.3_289, 0.1_710], [-0.1_884, 0.3_357, 0.1_810]]]	)

       self.assertTrue(jnp.allclose(output[:, 1:4, 1:4]       ,   __snake_case       ,   atol=1E-4	)	)



import math

import qiskit
def      snake_case_						( __lowercase = 1			,       __lowercase = 1			,       __lowercase = 1       ):
   if (
       isinstance(__lowercase			,       __lowercase       )
       or isinstance(__lowercase			,       __lowercase       )
       or isinstance(__lowercase			,       __lowercase       )
   ):
      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(__lowercase       ) != input_a)
       or (math.floor(__lowercase       ) != input_a)
       or (math.floor(__lowercase       ) != 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_							:      Any						=   qiskit.QuantumRegister(4			,       '''qr'''       )
   UpperCAmelCase_							:      List[str]						=   qiskit.ClassicalRegister(2			,       '''cr'''       )
   # list the entries
   UpperCAmelCase_							:      Any						=   [input_a, input_a, carry_in]

   UpperCAmelCase_							:      Dict						=   qiskit.QuantumCircuit(__lowercase			,       __lowercase       )

   for i in range(0			,       3       ):
      if entry[i] == 2:
         quantum_circuit.h(__lowercase       )  # for hadamard entries
      elif entry[i] == 1:
         quantum_circuit.x(__lowercase       )  # for 1 entries
      elif entry[i] == 0:
         quantum_circuit.i(__lowercase       )  # 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]			,       __lowercase       )  # measure the last two qbits

   UpperCAmelCase_							:      Optional[int]						=   qiskit.Aer.get_backend('''aer_simulator'''       )
   UpperCAmelCase_							:      List[str]						=   qiskit.execute(__lowercase			,       __lowercase			,       shots=1_0_0_0       )

   return job.result().get_counts(__lowercase       )


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