



'''simple docstring'''





import os
import sys
import unittest


lowercase_	 =						os.path.abspath(os.path.dirname(os.path.dirname(os.path.dirname(__file__))))
sys.path.append(os.path.join(git_repo_path, "utils"))

import check_dummies  # noqa: E402
from check_dummies import create_dummy_files, create_dummy_object, find_backend, read_init  # noqa: E402


# Align TRANSFORMERS_PATH in check_dummies with the current path
lowercase_	 =						os.path.join(git_repo_path, "src", "diffusers")






class __A    (						unittest.TestCase		):



 '''simple docstring'''







 def       a__						(self )					->  str:


      """simple docstring"""



      _a											=						find_backend('''    if not is_torch_available():''' )
      self.assertEqual(A				,     '''torch''' )

      # backend_with_underscore = find_backend("    if not is_tensorflow_text_available():")
      # self.assertEqual(backend_with_underscore, "tensorflow_text")

      _a											=						find_backend('''    if not (is_torch_available() and is_transformers_available()):''' )
      self.assertEqual(A				,     '''torch_and_transformers''' )

      # double_backend_with_underscore = find_backend(
      #    "    if not (is_sentencepiece_available() and is_tensorflow_text_available()):"
      # )
      # self.assertEqual(double_backend_with_underscore, "sentencepiece_and_tensorflow_text")

      _a											=						find_backend(
          '''    if not (is_torch_available() and is_transformers_available() and is_onnx_available()):''' )
      self.assertEqual(A				,     '''torch_and_transformers_and_onnx''' )



 def       a__						(self )					->  List[str]:


      """simple docstring"""



      _a											=						read_init()
      # We don't assert on the exact list of keys to allow for smooth grow of backend-specific objects
      self.assertIn('''torch'''				,     A )
      self.assertIn('''torch_and_transformers'''				,     A )
      self.assertIn('''flax_and_transformers'''				,     A )
      self.assertIn('''torch_and_transformers_and_onnx'''				,     A )

      # Likewise, we can't assert on the exact content of a key
      self.assertIn('''UNet2DModel'''				,     objects['''torch'''] )
      self.assertIn('''FlaxUNet2DConditionModel'''				,     objects['''flax'''] )
      self.assertIn('''StableDiffusionPipeline'''				,     objects['''torch_and_transformers'''] )
      self.assertIn('''FlaxStableDiffusionPipeline'''				,     objects['''flax_and_transformers'''] )
      self.assertIn('''LMSDiscreteScheduler'''				,     objects['''torch_and_scipy'''] )
      self.assertIn('''OnnxStableDiffusionPipeline'''				,     objects['''torch_and_transformers_and_onnx'''] )



 def       a__						(self )					->  Any:


      """simple docstring"""



      _a											=						create_dummy_object('''CONSTANT'''				,     '''\'torch\'''' )
      self.assertEqual(A				,     '''\nCONSTANT = None\n''' )

      _a											=						create_dummy_object('''function'''				,     '''\'torch\'''' )
      self.assertEqual(
          A				,     '''\ndef function(*args, **kwargs):\n    requires_backends(function, \'torch\')\n''' )

      _a											=						'''
class FakeClass(metaclass=DummyObject):
    _backends = \'torch\'

    def __init__(self, *args, **kwargs):
        requires_backends(self, \'torch\')

    @classmethod
    def from_config(cls, *args, **kwargs):
        requires_backends(cls, \'torch\')

    @classmethod
    def from_pretrained(cls, *args, **kwargs):
        requires_backends(cls, \'torch\')
'''
      _a											=						create_dummy_object('''FakeClass'''				,     '''\'torch\'''' )
      self.assertEqual(A				,     A )



 def       a__						(self )					->  Tuple:


      """simple docstring"""



      _a											=						'''# This file is autogenerated by the command `make fix-copies`, do not edit.
from ..utils import DummyObject, requires_backends


CONSTANT = None


def function(*args, **kwargs):
    requires_backends(function, ["torch"])


class FakeClass(metaclass=DummyObject):
    _backends = ["torch"]

    def __init__(self, *args, **kwargs):
        requires_backends(self, ["torch"])

    @classmethod
    def from_config(cls, *args, **kwargs):
        requires_backends(cls, ["torch"])

    @classmethod
    def from_pretrained(cls, *args, **kwargs):
        requires_backends(cls, ["torch"])
'''
      _a											=						create_dummy_files({'''torch''': ['''CONSTANT''', '''function''', '''FakeClass''']} )
      self.assertEqual(dummy_files['''torch''']				,     A )








'''simple docstring'''





import numpy as np
import qiskit




def lowerCAmelCase						(__A = 8						,			__A = 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()



