

'''simple docstring'''
import numpy as np
import qiskit







def  _A		(     snake_case = 8		,							snake_case = None					)      ->     str:
   _lowercase      :				Optional[int]      					=       np.random.default_rng(seed=snake_case					)

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

   # Quantum Circuit to simulate BB84
   _lowercase      :				Tuple      					=       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.
   _lowercase      :				Dict      					=       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.
   _lowercase      :				List[str]      					=       qiskit.execute(snake_case		,							snake_case		,							shots=1		,							seed_simulator=snake_case					)
   # Returns the result of measurement.
   _lowercase      :				List[Any]      					=       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.
   _lowercase      :				Any      					=       "".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.
   _lowercase      :				Optional[Any]      					=       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()









'''simple docstring'''
import random
import unittest

import torch

from diffusers import IFImgaImgSuperResolutionPipeline
from diffusers.utils import floats_tensor
from diffusers.utils.import_utils import is_xformers_available
from diffusers.utils.testing_utils import skip_mps, torch_device

from ..pipeline_params import TEXT_GUIDED_IMAGE_VARIATION_BATCH_PARAMS, TEXT_GUIDED_IMAGE_VARIATION_PARAMS
from ..test_pipelines_common import PipelineTesterMixin
from . import IFPipelineTesterMixin


@skip_mps
class        a__  (							lowerCamelCase_  ,				lowerCamelCase_  ,				unittest.TestCase  ):
   _SCREAMING_SNAKE_CASE   :					List[str]     	=							IFImgaImgSuperResolutionPipeline
   _SCREAMING_SNAKE_CASE   :					int     	=							TEXT_GUIDED_IMAGE_VARIATION_PARAMS - {'width', 'height'}
   _SCREAMING_SNAKE_CASE   :					List[str]     	=							TEXT_GUIDED_IMAGE_VARIATION_BATCH_PARAMS.union({'original_image'}  )
   _SCREAMING_SNAKE_CASE   :					Optional[int]     	=							PipelineTesterMixin.required_optional_params - {'latents'}


   def 						_lowerCamelCase       (			self  ):





      """simple docstring"""





      return self._get_superresolution_dummy_components()


   def 						_lowerCamelCase       (			self      ,    _UpperCamelCase      ,    _UpperCamelCase=0  ):





      """simple docstring"""





      if str(_UpperCamelCase  ).startswith("mps"  ):
         _lowercase      :				Tuple      					=       torch.manual_seed(_UpperCamelCase  )
      else:
         _lowercase      :				int      					=       torch.Generator(device=_UpperCamelCase  ).manual_seed(_UpperCamelCase  )

      _lowercase      :				List[Any]      					=       floats_tensor((1, 3, 32, 32)      ,    rng=random.Random(_UpperCamelCase  )  ).to(_UpperCamelCase  )
      _lowercase      :				Optional[int]      					=       floats_tensor((1, 3, 16, 16)      ,    rng=random.Random(_UpperCamelCase  )  ).to(_UpperCamelCase  )

      _lowercase      :				List[str]      					=       {
          "prompt": "A painting of a squirrel eating a burger",
          "image": image,
          "original_image": original_image,
          "generator": generator,
          "num_inference_steps": 2,
          "output_type": "numpy",
      }

      return inputs


   @unittest.skipIf(
       torch_device != "cuda" or not is_xformers_available()      ,    reason="XFormers attention is only available with CUDA and `xformers` installed"      ,    )
   def 						_lowerCamelCase       (			self  ):





      """simple docstring"""





      self._test_xformers_attention_forwardGenerator_pass(expected_max_diff=1E-3  )


   def 						_lowerCamelCase       (			self  ):





      """simple docstring"""





      self._test_save_load_optional_components()


   @unittest.skipIf(torch_device != "cuda"      ,    reason="float16 requires CUDA"  )
   def 						_lowerCamelCase       (			self  ):





      """simple docstring"""





      super().test_save_load_floataa(expected_max_diff=1E-1  )


   def 						_lowerCamelCase       (			self  ):





      """simple docstring"""





      self._test_attention_slicing_forward_pass(expected_max_diff=1E-2  )


   def 						_lowerCamelCase       (			self  ):





      """simple docstring"""





      self._test_save_load_local()






   def 						_lowerCamelCase       (			self  ):





      """simple docstring"""





      self._test_inference_batch_single_identical(
          expected_max_diff=1E-2      ,    )






