


"""simple docstring"""



from __future__ import annotations

from typing import Dict

from ...configuration_utils import PretrainedConfig


a_			=      {
    'susnato/ernie-m-base_pytorch': 'https://huggingface.co/susnato/ernie-m-base_pytorch/blob/main/config.json',
    'susnato/ernie-m-large_pytorch': 'https://huggingface.co/susnato/ernie-m-large_pytorch/blob/main/config.json',
}






class 		__snake_case (		_UpperCamelCase					):





 """simple docstring"""


 _lowerCamelCase				=					'ernie_m'
 _lowerCamelCase				=					{"dropout": "classifier_dropout", "num_classes": "num_labels"}

 def __init__(   self ,						__lowerCamelCase = 25_0002 ,						__lowerCamelCase = 768 ,						__lowerCamelCase = 12 ,						__lowerCamelCase = 12 ,						__lowerCamelCase = 3072 ,						__lowerCamelCase = "gelu" ,						__lowerCamelCase = 0.1 ,						__lowerCamelCase = 0.1 ,						__lowerCamelCase = 514 ,						__lowerCamelCase = 0.0_2 ,						__lowerCamelCase = 1 ,						__lowerCamelCase = 1e-0_5 ,						__lowerCamelCase=None ,						__lowerCamelCase=False ,						__lowerCamelCase=0.0 ,						**__lowerCamelCase ,						):



     '''simple docstring'''




     super().__init__(pad_token_id=_SCREAMING_SNAKE_CASE ,						**_SCREAMING_SNAKE_CASE  )
     __A   :						Optional[int]									=					vocab_size
     __A   :						Optional[int]									=					hidden_size
     __A   :						str									=					num_hidden_layers
     __A   :						Tuple									=					num_attention_heads
     __A   :						int									=					intermediate_size
     __A   :						List[Any]									=					hidden_act
     __A   :						Any									=					hidden_dropout_prob
     __A   :						int									=					attention_probs_dropout_prob
     __A   :						Dict									=					max_position_embeddings
     __A   :						List[str]									=					initializer_range
     __A   :						List[Any]									=					layer_norm_eps
     __A   :						int									=					classifier_dropout
     __A   :						Dict									=					is_decoder
     __A   :						List[Any]									=					act_dropout











"""simple docstring"""



import numpy as np
import qiskit







def 		__lowercase					(       snake_case_  :  int = 8    ,snake_case_  :  int | None = None						)       ->str:



    '''simple docstring'''







    __A   :						str									=					np.random.default_rng(seed=snake_case_						)

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

    # Quantum Circuit to simulate BB84
    __A   :						Dict									=					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.
    __A   :						List[str]									=					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.
    __A   :						List[str]									=					qiskit.execute(snake_case_    ,snake_case_    ,shots=1    ,seed_simulator=snake_case_						)
    # Returns the result of measurement.
    __A   :						Union[str, Any]									=					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.
    __A   :						int									=					''''''.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.
    __A   :						Union[str, Any]									=					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()




