

import numpy as np
import qiskit




def 			UpperCAmelCase__				(			_A      : int = 8	,      _A      : int | None = None							):





  '''simple docstring'''







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

  # 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=a_							)
  # The set of states Alice will prepare.
  a__  =rng.integers(2	,      size=a_							)
  # Measurement basis for Bob's qubits.
  a__  =rng.integers(2	,      size=a_							)

  # Quantum Circuit to simulate BB84
  a__  =qiskit.QuantumCircuit(a_	,      name='''BB84'''							)

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

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

  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(a_	,      a_	,      shots=1	,      seed_simulator=a_							)
  # Returns the result of measurement.
  a__  =job.result().get_counts(a_							).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(
              a_	,      a_	,      a_							)
          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(a_							) >= key_len else gen_key.ljust(a_	,      '''0'''							)
  return key


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

       testmod()







"""simple docstring"""
from ...configuration_utils import PretrainedConfig
from ...utils import logging


lowerCamelCase_								=		logging.get_logger(__name__)

lowerCamelCase_								=		{}






class 					_SCREAMING_SNAKE_CASE(   A  ):
       SCREAMING_SNAKE_CASE_   :      List[Any]							=  '''llama'''
       SCREAMING_SNAKE_CASE_   :      Optional[int]							=  ['''past_key_values''']




       def __init__(						self		,SCREAMING_SNAKE_CASE__=3_20_00		,SCREAMING_SNAKE_CASE__=40_96		,SCREAMING_SNAKE_CASE__=1_10_08		,SCREAMING_SNAKE_CASE__=32		,SCREAMING_SNAKE_CASE__=32		,SCREAMING_SNAKE_CASE__=None		,SCREAMING_SNAKE_CASE__="silu"		,SCREAMING_SNAKE_CASE__=20_48		,SCREAMING_SNAKE_CASE__=0.0_2		,SCREAMING_SNAKE_CASE__=1E-6		,SCREAMING_SNAKE_CASE__=True		,SCREAMING_SNAKE_CASE__=0		,SCREAMING_SNAKE_CASE__=1		,SCREAMING_SNAKE_CASE__=2		,SCREAMING_SNAKE_CASE__=1		,SCREAMING_SNAKE_CASE__=False		,SCREAMING_SNAKE_CASE__=None		,**SCREAMING_SNAKE_CASE__		,)			->      Union[str, Any]:





             """simple docstring"""






             __SCREAMING_SNAKE_CASE   :Optional[Any]						=  vocab_size
             __SCREAMING_SNAKE_CASE   :int						=  max_position_embeddings
             __SCREAMING_SNAKE_CASE   :List[str]						=  hidden_size
             __SCREAMING_SNAKE_CASE   :Tuple						=  intermediate_size
             __SCREAMING_SNAKE_CASE   :List[str]						=  num_hidden_layers
             __SCREAMING_SNAKE_CASE   :List[Any]						=  num_attention_heads

             # for backward compatibility
             if num_key_value_heads is None:
                   __SCREAMING_SNAKE_CASE   :Optional[int]						=  num_attention_heads

             __SCREAMING_SNAKE_CASE   :str						=  num_key_value_heads
             __SCREAMING_SNAKE_CASE   :Union[str, Any]						=  hidden_act
             __SCREAMING_SNAKE_CASE   :List[str]						=  initializer_range
             __SCREAMING_SNAKE_CASE   :Union[str, Any]						=  rms_norm_eps
             __SCREAMING_SNAKE_CASE   :Dict						=  pretraining_tp
             __SCREAMING_SNAKE_CASE   :Optional[Any]						=  use_cache
             __SCREAMING_SNAKE_CASE   :Optional[Any]						=  rope_scaling
             self._rope_scaling_validation()

             super().__init__(
                 pad_token_id=SCREAMING_SNAKE_CASE__		,bos_token_id=SCREAMING_SNAKE_CASE__		,eos_token_id=SCREAMING_SNAKE_CASE__		,tie_word_embeddings=SCREAMING_SNAKE_CASE__		,**SCREAMING_SNAKE_CASE__		,)




       def     _UpperCamelCase     (						self							)			->      List[Any]:





             """simple docstring"""






             if self.rope_scaling is None:
                   return

             if not isinstance(self.rope_scaling		,SCREAMING_SNAKE_CASE__							) or len(self.rope_scaling							) != 2:
                   raise ValueError(
                       '''`rope_scaling` must be a dictionary with with two fields, `name` and `factor`, '''
                       f'''got {self.rope_scaling}'''							)
             __SCREAMING_SNAKE_CASE   :Optional[Any]						=  self.rope_scaling.get('''type'''		,SCREAMING_SNAKE_CASE__							)
             __SCREAMING_SNAKE_CASE   :Optional[int]						=  self.rope_scaling.get('''factor'''		,SCREAMING_SNAKE_CASE__							)
             if rope_scaling_type is None or rope_scaling_type not in ["linear", "dynamic"]:
                   raise ValueError(
                       f'''`rope_scaling`\'s name field must be one of [\'linear\', \'dynamic\'], got {rope_scaling_type}'''							)
             if rope_scaling_factor is None or not isinstance(SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__							) or rope_scaling_factor <= 1.0:
                   raise ValueError(f'''`rope_scaling`\'s factor field must be an float > 1, got {rope_scaling_factor}'''							)