
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   UpperCamelCase_      (      UpperCAmelCase__		,    UpperCAmelCase__		,    unittest.TestCase		):







						'''simple docstring'''



						UpperCamelCase      :  List[str]				   =					IFImgaImgSuperResolutionPipeline
						UpperCamelCase      :  int				   =					TEXT_GUIDED_IMAGE_VARIATION_PARAMS - {'''width''', '''height'''}
						UpperCamelCase      :  str				   =					TEXT_GUIDED_IMAGE_VARIATION_BATCH_PARAMS.union({'''original_image'''}		)
						UpperCamelCase      :  Union[str, Any]				   =					PipelineTesterMixin.required_optional_params - {'''latents'''}





						def        SCREAMING_SNAKE_CASE(			self							:Any     )  ->List[str]:
										return self._get_superresolution_dummy_components()





						def        SCREAMING_SNAKE_CASE(			self							:Optional[int]		,    lowerCAmelCase__							:Union[str, Any]		,    lowerCAmelCase__							:int=0     )  ->Optional[int]:






										if str(__lowercase     ).startswith("mps"     ):
														lowercase         =      torch.manual_seed(__lowercase     )
										else:
														lowercase         =      torch.Generator(device=__lowercase     ).manual_seed(__lowercase     )

										lowercase         =      floats_tensor((1, 3, 32, 32)		,    rng=random.Random(__lowercase     )     ).to(__lowercase     )
										lowercase         =      floats_tensor((1, 3, 16, 16)		,    rng=random.Random(__lowercase     )     ).to(__lowercase     )

										lowercase         =      {
										    "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        SCREAMING_SNAKE_CASE(			self							:str     )  ->Optional[Any]:
										self._test_xformers_attention_forwardGenerator_pass(expected_max_diff=1E-3     )





						def        SCREAMING_SNAKE_CASE(			self							:List[Any]     )  ->List[str]:
										self._test_save_load_optional_components()





						@unittest.skipIf(torch_device != "cuda"		,    reason="float16 requires CUDA"     )
						def        SCREAMING_SNAKE_CASE(			self							:List[Any]     )  ->Union[str, Any]:
										super().test_save_load_floataa(expected_max_diff=1E-1     )





						def        SCREAMING_SNAKE_CASE(			self							:List[Any]     )  ->Optional[int]:
										self._test_attention_slicing_forward_pass(expected_max_diff=1E-2     )





						def        SCREAMING_SNAKE_CASE(			self							:str     )  ->Any:
										self._test_save_load_local()





						def        SCREAMING_SNAKE_CASE(			self							:Union[str, Any]     )  ->Optional[Any]:
										self._test_inference_batch_single_identical(
										    expected_max_diff=1E-2		,    )






import numpy as np
import qiskit


def 		lowerCamelCase__       (						_A = 8	,      _A = None				):







	'''simple docstring'''





	snake_case_						       =	np.random.default_rng(seed=_A				)

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

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