

"""simple docstring"""




import numpy as np
import qiskit
def   lowerCAmelCase						(					__UpperCamelCase = 8							,    __UpperCamelCase = None      ):
 '''simple docstring'''





 UpperCAmelCase__					:  Optional[int]					   =					np.random.default_rng(seed=__UpperCamelCase      )

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

 # Quantum Circuit to simulate BB84
 UpperCAmelCase__					:  List[str]					   =					qiskit.QuantumCircuit(__UpperCamelCase							,    name="""BB84"""      )

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

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

 bbaa_circ.barrier()
 bbaa_circ.measure_all()

 # Simulate the quantum circuit.
 UpperCAmelCase__					:  List[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.
 UpperCAmelCase__					:  Tuple					   =					qiskit.execute(__UpperCamelCase							,    __UpperCamelCase							,    shots=1							,    seed_simulator=__UpperCamelCase      )
 # Returns the result of measurement.
 UpperCAmelCase__					:  int					   =					job.result().get_counts(__UpperCamelCase      ).most_frequent()

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

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


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

      testmod()








"""simple docstring"""




from typing import List, Optional, TypeVar

from .arrow_dataset import Dataset, _concatenate_map_style_datasets, _interleave_map_style_datasets
from .dataset_dict import DatasetDict, IterableDatasetDict
from .info import DatasetInfo
from .iterable_dataset import IterableDataset, _concatenate_iterable_datasets, _interleave_iterable_datasets
from .splits import NamedSplit
from .utils import logging
from .utils.py_utils import Literal


__UpperCAmelCase =				logging.get_logger(__name__)


__UpperCAmelCase =				TypeVar('DatasetType', Dataset, IterableDataset)
def   lowerCAmelCase						(					__UpperCamelCase							,    __UpperCamelCase = None							,    __UpperCamelCase = None							,    __UpperCamelCase = None							,    __UpperCamelCase = None							,    __UpperCamelCase = "first_exhausted"							,    ):
 '''simple docstring'''





 from .arrow_dataset import Dataset
 from .iterable_dataset import IterableDataset

 if not datasets:
  raise ValueError("""Unable to interleave an empty list of datasets."""      )
 for i, dataset in enumerate(__UpperCamelCase      ):
  if not isinstance(__UpperCamelCase							,    (Dataset, IterableDataset)      ):
   if isinstance(__UpperCamelCase							,    (DatasetDict, IterableDatasetDict)      ):
    if not dataset:
     raise ValueError(
         F"Expected a list of Dataset objects or a list of IterableDataset objects, but element at position {i} "
         """is an empty dataset dictionary."""      )
    raise ValueError(
        F"Dataset at position {i} has at least one split: {list(__UpperCamelCase      )}\n"
        F"Please pick one to interleave with the other datasets, for example: dataset['{next(iter(__UpperCamelCase      )      )}']"      )
   raise ValueError(
       F"Expected a list of Dataset objects or a list of IterableDataset objects, but element at position {i} is a {type(__UpperCamelCase      ).__name__}."      )
  if i == 0:
   UpperCAmelCase__   ,      UpperCAmelCase__					:  List[str]					   =					(
       (Dataset, IterableDataset) if isinstance(__UpperCamelCase							,    __UpperCamelCase      ) else (IterableDataset, Dataset)
   )
  elif not isinstance(__UpperCamelCase							,    __UpperCamelCase      ):
   raise ValueError(
       F"Unable to interleave a {dataset_type.__name__} (at position 0) with a {other_type.__name__} (at position {i}). Expected a list of Dataset objects or a list of IterableDataset objects."      )
 if stopping_strategy not in ["first_exhausted", "all_exhausted"]:
  raise ValueError(F"{stopping_strategy} is not supported. Please enter a valid stopping_strategy."      )
 if dataset_type is Dataset:
  return _interleave_map_style_datasets(
      __UpperCamelCase							,    __UpperCamelCase							,    __UpperCamelCase							,    info=__UpperCamelCase							,    split=__UpperCamelCase							,    stopping_strategy=__UpperCamelCase      )
 else:
  return _interleave_iterable_datasets(
      __UpperCamelCase							,    __UpperCamelCase							,    __UpperCamelCase							,    info=__UpperCamelCase							,    split=__UpperCamelCase							,    stopping_strategy=__UpperCamelCase      )




def   lowerCAmelCase						(					__UpperCamelCase							,    __UpperCamelCase = None							,    __UpperCamelCase = None							,    __UpperCamelCase = 0							,    ):
 '''simple docstring'''





 if not dsets:
  raise ValueError("""Unable to concatenate an empty list of datasets."""      )
 for i, dataset in enumerate(__UpperCamelCase      ):
  if not isinstance(__UpperCamelCase							,    (Dataset, IterableDataset)      ):
   if isinstance(__UpperCamelCase							,    (DatasetDict, IterableDatasetDict)      ):
    if not dataset:
     raise ValueError(
         F"Expected a list of Dataset objects or a list of IterableDataset objects, but element at position {i} "
         """is an empty dataset dictionary."""      )
    raise ValueError(
        F"Dataset at position {i} has at least one split: {list(__UpperCamelCase      )}\n"
        F"Please pick one to interleave with the other datasets, for example: dataset['{next(iter(__UpperCamelCase      )      )}']"      )
   raise ValueError(
       F"Expected a list of Dataset objects or a list of IterableDataset objects, but element at position {i} is a {type(__UpperCamelCase      ).__name__}."      )
  if i == 0:
   UpperCAmelCase__   ,      UpperCAmelCase__					:  Optional[int]					   =					(
       (Dataset, IterableDataset) if isinstance(__UpperCamelCase							,    __UpperCamelCase      ) else (IterableDataset, Dataset)
   )
  elif not isinstance(__UpperCamelCase							,    __UpperCamelCase      ):
   raise ValueError(
       F"Unable to interleave a {dataset_type.__name__} (at position 0) with a {other_type.__name__} (at position {i}). Expected a list of Dataset objects or a list of IterableDataset objects."      )
 if dataset_type is Dataset:
  return _concatenate_map_style_datasets(__UpperCamelCase							,    info=__UpperCamelCase							,    split=__UpperCamelCase							,    axis=__UpperCamelCase      )
 else:
  return _concatenate_iterable_datasets(__UpperCamelCase							,    info=__UpperCamelCase							,    split=__UpperCamelCase							,    axis=__UpperCamelCase      )





