





"""simple docstring"""





import numpy as np
import qiskit



def 				lowerCAmelCase_			(      SCREAMING_SNAKE_CASE       :							int = 8    ,						SCREAMING_SNAKE_CASE       :							int | None = None   ):


							'''simple docstring'''







							__lowerCamelCase      :      Optional[Any]         =np.random.default_rng(seed=SCREAMING_SNAKE_CASE   )

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

							# Quantum Circuit to simulate BB84
							__lowerCamelCase      :      Any         =qiskit.QuantumCircuit(SCREAMING_SNAKE_CASE    ,						name='''BB84'''   )

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

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

							bbaa_circ.barrier()
							bbaa_circ.measure_all()

							# Simulate the quantum circuit.
							__lowerCamelCase      :      Any         =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.
							__lowerCamelCase      :      Optional[Any]         =qiskit.execute(SCREAMING_SNAKE_CASE    ,						SCREAMING_SNAKE_CASE    ,						shots=1    ,						seed_simulator=SCREAMING_SNAKE_CASE   )
							# Returns the result of measurement.
							__lowerCamelCase      :      List[str]         =job.result().get_counts(SCREAMING_SNAKE_CASE   ).most_frequent()

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

							# Get final key. Pad with 0 if too short, otherwise truncate.
							__lowerCamelCase      :      int         =gen_key[:key_len] if len(SCREAMING_SNAKE_CASE   ) >= key_len else gen_key.ljust(SCREAMING_SNAKE_CASE    ,						'''0'''   )
							return key


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

							testmod()











"""simple docstring"""





from .glue import GlueDataset, GlueDataTrainingArguments
from .language_modeling import (
    LineByLineTextDataset,
    LineByLineWithRefDataset,
    LineByLineWithSOPTextDataset,
    TextDataset,
    TextDatasetForNextSentencePrediction,
)
from .squad import SquadDataset, SquadDataTrainingArguments




