






import unittest

import numpy as np

from transformers.testing_utils import require_flax, require_tf, require_torch
from transformers.utils import (
    expand_dims,
    flatten_dict,
    is_flax_available,
    is_tf_available,
    is_torch_available,
    reshape,
    squeeze,
    transpose,
)


if is_flax_available():
     import jax.numpy as jnp

if is_tf_available():
     import tensorflow as tf

if is_torch_available():
     import torch




class 			snake_case__   (							unittest.TestCase):

       '''simple docstring'''



       def 					__lowercase						(							self    ) ->      Dict:






            '''simple docstring'''





            __snake_case			:Union[str, Any]          =						{
                """task_specific_params""": {
                    """summarization""": {"""length_penalty""": 1.0, """max_length""": 1_28, """min_length""": 12, """num_beams""": 4},
                    """summarization_cnn""": {"""length_penalty""": 2.0, """max_length""": 1_42, """min_length""": 56, """num_beams""": 4},
                    """summarization_xsum""": {"""length_penalty""": 1.0, """max_length""": 62, """min_length""": 11, """num_beams""": 6},
                }
            }
            __snake_case			:Tuple          =						{
                """task_specific_params.summarization.length_penalty""": 1.0,
                """task_specific_params.summarization.max_length""": 1_28,
                """task_specific_params.summarization.min_length""": 12,
                """task_specific_params.summarization.num_beams""": 4,
                """task_specific_params.summarization_cnn.length_penalty""": 2.0,
                """task_specific_params.summarization_cnn.max_length""": 1_42,
                """task_specific_params.summarization_cnn.min_length""": 56,
                """task_specific_params.summarization_cnn.num_beams""": 4,
                """task_specific_params.summarization_xsum.length_penalty""": 1.0,
                """task_specific_params.summarization_xsum.max_length""": 62,
                """task_specific_params.summarization_xsum.min_length""": 11,
                """task_specific_params.summarization_xsum.num_beams""": 6,
            }

            self.assertEqual(flatten_dict(a__    )			,						a__    )



       def 					__lowercase						(							self    ) ->      Tuple:






            '''simple docstring'''





            __snake_case			:Tuple          =						np.random.randn(3			,						4    )
            self.assertTrue(np.allclose(transpose(a__    )			,						x.transpose()    )    )

            __snake_case			:List[str]          =						np.random.randn(3			,						4			,						5    )
            self.assertTrue(np.allclose(transpose(a__			,						axes=(1, 2, 0)    )			,						x.transpose((1, 2, 0)    )    )    )



       @require_torch
       def 					__lowercase						(							self    ) ->      Optional[int]:






            '''simple docstring'''





            __snake_case			:Optional[int]          =						np.random.randn(3			,						4    )
            __snake_case			:Tuple          =						torch.tensor(a__    )
            self.assertTrue(np.allclose(transpose(a__    )			,						transpose(a__    ).numpy()    )    )

            __snake_case			:Dict          =						np.random.randn(3			,						4			,						5    )
            __snake_case			:Union[str, Any]          =						torch.tensor(a__    )
            self.assertTrue(np.allclose(transpose(a__			,						axes=(1, 2, 0)    )			,						transpose(a__			,						axes=(1, 2, 0)    ).numpy()    )    )



       @require_tf
       def 					__lowercase						(							self    ) ->      Tuple:






            '''simple docstring'''





            __snake_case			:Union[str, Any]          =						np.random.randn(3			,						4    )
            __snake_case			:List[Any]          =						tf.constant(a__    )
            self.assertTrue(np.allclose(transpose(a__    )			,						transpose(a__    ).numpy()    )    )

            __snake_case			:List[Any]          =						np.random.randn(3			,						4			,						5    )
            __snake_case			:Optional[Any]          =						tf.constant(a__    )
            self.assertTrue(np.allclose(transpose(a__			,						axes=(1, 2, 0)    )			,						transpose(a__			,						axes=(1, 2, 0)    ).numpy()    )    )



       @require_flax
       def 					__lowercase						(							self    ) ->      Optional[int]:






            '''simple docstring'''





            __snake_case			:List[Any]          =						np.random.randn(3			,						4    )
            __snake_case			:List[str]          =						jnp.array(a__    )
            self.assertTrue(np.allclose(transpose(a__    )			,						np.asarray(transpose(a__    )    )    )    )

            __snake_case			:List[Any]          =						np.random.randn(3			,						4			,						5    )
            __snake_case			:Optional[Any]          =						jnp.array(a__    )
            self.assertTrue(np.allclose(transpose(a__			,						axes=(1, 2, 0)    )			,						np.asarray(transpose(a__			,						axes=(1, 2, 0)    )    )    )    )



       def 					__lowercase						(							self    ) ->      Optional[Any]:






            '''simple docstring'''





            __snake_case			:Tuple          =						np.random.randn(3			,						4    )
            self.assertTrue(np.allclose(reshape(a__			,						(4, 3)    )			,						np.reshape(a__			,						(4, 3)    )    )    )

            __snake_case			:List[Any]          =						np.random.randn(3			,						4			,						5    )
            self.assertTrue(np.allclose(reshape(a__			,						(12, 5)    )			,						np.reshape(a__			,						(12, 5)    )    )    )



       @require_torch
       def 					__lowercase						(							self    ) ->      str:






            '''simple docstring'''





            __snake_case			:List[str]          =						np.random.randn(3			,						4    )
            __snake_case			:Optional[Any]          =						torch.tensor(a__    )
            self.assertTrue(np.allclose(reshape(a__			,						(4, 3)    )			,						reshape(a__			,						(4, 3)    ).numpy()    )    )

            __snake_case			:Any          =						np.random.randn(3			,						4			,						5    )
            __snake_case			:Dict          =						torch.tensor(a__    )
            self.assertTrue(np.allclose(reshape(a__			,						(12, 5)    )			,						reshape(a__			,						(12, 5)    ).numpy()    )    )



       @require_tf
       def 					__lowercase						(							self    ) ->      Dict:






            '''simple docstring'''





            __snake_case			:List[Any]          =						np.random.randn(3			,						4    )
            __snake_case			:int          =						tf.constant(a__    )
            self.assertTrue(np.allclose(reshape(a__			,						(4, 3)    )			,						reshape(a__			,						(4, 3)    ).numpy()    )    )

            __snake_case			:Optional[Any]          =						np.random.randn(3			,						4			,						5    )
            __snake_case			:Any          =						tf.constant(a__    )
            self.assertTrue(np.allclose(reshape(a__			,						(12, 5)    )			,						reshape(a__			,						(12, 5)    ).numpy()    )    )



       @require_flax
       def 					__lowercase						(							self    ) ->      Union[str, Any]:






            '''simple docstring'''





            __snake_case			:Optional[Any]          =						np.random.randn(3			,						4    )
            __snake_case			:Any          =						jnp.array(a__    )
            self.assertTrue(np.allclose(reshape(a__			,						(4, 3)    )			,						np.asarray(reshape(a__			,						(4, 3)    )    )    )    )

            __snake_case			:Optional[int]          =						np.random.randn(3			,						4			,						5    )
            __snake_case			:Dict          =						jnp.array(a__    )
            self.assertTrue(np.allclose(reshape(a__			,						(12, 5)    )			,						np.asarray(reshape(a__			,						(12, 5)    )    )    )    )



       def 					__lowercase						(							self    ) ->      str:






            '''simple docstring'''





            __snake_case			:int          =						np.random.randn(1			,						3			,						4    )
            self.assertTrue(np.allclose(squeeze(a__    )			,						np.squeeze(a__    )    )    )

            __snake_case			:List[str]          =						np.random.randn(1			,						4			,						1			,						5    )
            self.assertTrue(np.allclose(squeeze(a__			,						axis=2    )			,						np.squeeze(a__			,						axis=2    )    )    )



       @require_torch
       def 					__lowercase						(							self    ) ->      Union[str, Any]:






            '''simple docstring'''





            __snake_case			:List[str]          =						np.random.randn(1			,						3			,						4    )
            __snake_case			:Optional[int]          =						torch.tensor(a__    )
            self.assertTrue(np.allclose(squeeze(a__    )			,						squeeze(a__    ).numpy()    )    )

            __snake_case			:Optional[Any]          =						np.random.randn(1			,						4			,						1			,						5    )
            __snake_case			:Union[str, Any]          =						torch.tensor(a__    )
            self.assertTrue(np.allclose(squeeze(a__			,						axis=2    )			,						squeeze(a__			,						axis=2    ).numpy()    )    )



       @require_tf
       def 					__lowercase						(							self    ) ->      str:






            '''simple docstring'''





            __snake_case			:List[Any]          =						np.random.randn(1			,						3			,						4    )
            __snake_case			:Tuple          =						tf.constant(a__    )
            self.assertTrue(np.allclose(squeeze(a__    )			,						squeeze(a__    ).numpy()    )    )

            __snake_case			:Optional[int]          =						np.random.randn(1			,						4			,						1			,						5    )
            __snake_case			:int          =						tf.constant(a__    )
            self.assertTrue(np.allclose(squeeze(a__			,						axis=2    )			,						squeeze(a__			,						axis=2    ).numpy()    )    )



       @require_flax
       def 					__lowercase						(							self    ) ->      Any:






            '''simple docstring'''





            __snake_case			:List[Any]          =						np.random.randn(1			,						3			,						4    )
            __snake_case			:Union[str, Any]          =						jnp.array(a__    )
            self.assertTrue(np.allclose(squeeze(a__    )			,						np.asarray(squeeze(a__    )    )    )    )

            __snake_case			:Optional[int]          =						np.random.randn(1			,						4			,						1			,						5    )
            __snake_case			:Union[str, Any]          =						jnp.array(a__    )
            self.assertTrue(np.allclose(squeeze(a__			,						axis=2    )			,						np.asarray(squeeze(a__			,						axis=2    )    )    )    )



       def 					__lowercase						(							self    ) ->      List[Any]:






            '''simple docstring'''





            __snake_case			:Optional[int]          =						np.random.randn(3			,						4    )
            self.assertTrue(np.allclose(expand_dims(a__			,						axis=1    )			,						np.expand_dims(a__			,						axis=1    )    )    )



       @require_torch
       def 					__lowercase						(							self    ) ->      Dict:






            '''simple docstring'''





            __snake_case			:Any          =						np.random.randn(3			,						4    )
            __snake_case			:Any          =						torch.tensor(a__    )
            self.assertTrue(np.allclose(expand_dims(a__			,						axis=1    )			,						expand_dims(a__			,						axis=1    ).numpy()    )    )



       @require_tf
       def 					__lowercase						(							self    ) ->      Any:






            '''simple docstring'''





            __snake_case			:Optional[int]          =						np.random.randn(3			,						4    )
            __snake_case			:List[str]          =						tf.constant(a__    )
            self.assertTrue(np.allclose(expand_dims(a__			,						axis=1    )			,						expand_dims(a__			,						axis=1    ).numpy()    )    )



       @require_flax
       def 					__lowercase						(							self    ) ->      Any:






            '''simple docstring'''





            __snake_case			:int          =						np.random.randn(3			,						4    )
            __snake_case			:int          =						jnp.array(a__    )
            self.assertTrue(np.allclose(expand_dims(a__			,						axis=1    )			,						np.asarray(expand_dims(a__			,						axis=1    )    )    )    )










import numpy as np
import qiskit






def   UpperCamelCase  (       snake_case__     :   int = 8	,snake_case__     :   int | None = None  ):




     '''simple docstring'''






     __snake_case			:Tuple          =						np.random.default_rng(seed=snake_case__  )

     # Roughly 25% of the qubits will contribute to the key.
     # So we take more than we need.
     __snake_case			:Union[str, Any]          =						6 * key_len
     # Measurement basis for Alice's qubits.
     __snake_case			:int          =						rng.integers(2	,size=snake_case__  )
     # The set of states Alice will prepare.
     __snake_case			:Dict          =						rng.integers(2	,size=snake_case__  )
     # Measurement basis for Bob's qubits.
     __snake_case			:str          =						rng.integers(2	,size=snake_case__  )

     # Quantum Circuit to simulate BB84
     __snake_case			:Optional[int]          =						qiskit.QuantumCircuit(snake_case__	,name="""BB84"""  )

     # Alice prepares her qubits according to rules above.
     for index, _ in enumerate(snake_case__  ):
          if alice_state[index] == 1:
               bbaa_circ.x(snake_case__  )
          if alice_basis[index] == 1:
               bbaa_circ.h(snake_case__  )
     bbaa_circ.barrier()

     # Bob measures the received qubits according to rules above.
     for index, _ in enumerate(snake_case__  ):
          if bob_basis[index] == 1:
               bbaa_circ.h(snake_case__  )

     bbaa_circ.barrier()
     bbaa_circ.measure_all()

     # Simulate the quantum circuit.
     __snake_case			:Optional[int]          =						qiskit.Aer.get_backend("""aer_simulator"""  )
     # We only need to run one shot because the key is unique.
     # Multiple shots will produce the same key.
     __snake_case			:List[Any]          =						qiskit.execute(snake_case__	,snake_case__	,shots=1	,seed_simulator=snake_case__  )
     # Returns the result of measurement.
     __snake_case			:Tuple          =						job.result().get_counts(snake_case__  ).most_frequent()

     # Extracting the generated key from the simulation results.
     # Only keep measurement results where Alice and Bob chose the same basis.
     __snake_case			:Any          =						"""""".join(
         [
             result_bit
             for alice_basis_bit, bob_basis_bit, result_bit in zip(
                 snake_case__	,snake_case__	,snake_case__  )
             if alice_basis_bit == bob_basis_bit
         ]  )

     # Get final key. Pad with 0 if too short, otherwise truncate.
     __snake_case			:Dict          =						gen_key[:key_len] if len(snake_case__  ) >= key_len else gen_key.ljust(snake_case__	,"""0"""  )
     return key


if __name__ == "__main__":
     print(f'''The generated key is : {bbaa(8, seed=0)}''')
     from doctest import testmod

     testmod()


