



'''simple docstring'''


import numpy as np
import qiskit






def  UpperCAmelCase_       (		lowercase__ = 8       ,	lowercase__ = None       ):


     '''simple docstring'''







     a_       		=np.random.default_rng(seed=lowercase__       )

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

     # Quantum Circuit to simulate BB84
     a_       		=qiskit.QuantumCircuit(lowercase__       ,	name="BB84"       )

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

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

     bbaa_circ.barrier()
     bbaa_circ.measure_all()

     # Simulate the quantum circuit.
     a_       		=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_       		=qiskit.execute(lowercase__       ,	lowercase__       ,	shots=1       ,	seed_simulator=lowercase__       )
     # Returns the result of measurement.
     a_       		=job.result().get_counts(lowercase__       ).most_frequent()

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

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


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

  testmod()







'''simple docstring'''


from .testing import (
    are_the_same_tensors,
    execute_subprocess_async,
    require_bnb,
    require_cpu,
    require_cuda,
    require_huggingface_suite,
    require_mps,
    require_multi_gpu,
    require_multi_xpu,
    require_safetensors,
    require_single_gpu,
    require_single_xpu,
    require_torch_min_version,
    require_tpu,
    require_xpu,
    skip,
    slow,
)
from .training import RegressionDataset, RegressionModel, RegressionModelaXPU


from .scripts import test_script, test_sync, test_ops  # isort: skip


