
"""simple docstring"""

from typing import Optional

from .. import Features, NamedSplit
from ..packaged_modules.text.text import Text
from ..utils.typing import NestedDataStructureLike, PathLike
from .abc import AbstractDatasetReader

class __lowerCAmelCase	(   __SCREAMING_SNAKE_CASE    ):





     def __init__(			self			,  __UpperCAmelCase			,  __UpperCAmelCase = None			,  __UpperCAmelCase = None			,  __UpperCAmelCase = None			,  __UpperCAmelCase = False			,  __UpperCAmelCase = False			,  __UpperCAmelCase = None			,  **__UpperCAmelCase			,  ):

      '''simple docstring'''




      super().__init__(
          __UpperCAmelCase			,  split=__UpperCAmelCase			,  features=__UpperCAmelCase			,  cache_dir=__UpperCAmelCase			,  keep_in_memory=__UpperCAmelCase			,  streaming=__UpperCAmelCase			,  num_proc=__UpperCAmelCase			,  **__UpperCAmelCase			,  )
      __UpperCamelCase       						= path_or_paths if isinstance(__UpperCAmelCase			,  __UpperCAmelCase   ) else {self.split: path_or_paths}
      __UpperCamelCase       						= Text(
          cache_dir=__UpperCAmelCase			,  data_files=__UpperCAmelCase			,  features=__UpperCAmelCase			,  **__UpperCAmelCase			,  )







     def 		UpperCAmelCase      (			self   ):

      '''simple docstring'''




      if self.streaming:
       __UpperCamelCase       						= self.builder.as_streaming_dataset(split=self.split   )
      # Build regular (map-style) dataset
      else:
       __UpperCamelCase       						= None
       __UpperCamelCase       						= None
       __UpperCamelCase       						= None
       __UpperCamelCase       						= None

       self.builder.download_and_prepare(
           download_config=__UpperCAmelCase			,  download_mode=__UpperCAmelCase			,  verification_mode=__UpperCAmelCase			,  base_path=__UpperCAmelCase			,  num_proc=self.num_proc			,  )
       __UpperCamelCase       						= self.builder.as_dataset(
           split=self.split			,  verification_mode=__UpperCAmelCase			,  in_memory=self.keep_in_memory   )
      return dataset





"""simple docstring"""

import numpy as np
import qiskit






def 							A		(       snake_case   :int = 8       ,      snake_case   :int | None = None	)   ->			str:
 __UpperCamelCase       						= np.random.default_rng(seed=snake_case	)

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

 # Quantum Circuit to simulate BB84
 __UpperCamelCase       						= 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.
 __UpperCamelCase       						= 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       						= qiskit.execute(snake_case       ,      snake_case       ,      shots=1       ,      seed_simulator=snake_case	)
 # Returns the result of measurement.
 __UpperCamelCase       						= 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.
 __UpperCamelCase       						= ''.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.
 __UpperCamelCase       						= 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()



