




import unittest

from diffusers.pipelines.pipeline_utils import is_safetensors_compatible
class 						UpperCAmelCase  (							unittest.TestCase     ):







						'''simple docstring'''





						def 			snake_case__		(		self				:	Optional[int]		):






							"""simple docstring"""






							snake_case_						       =	[
							    "safety_checker/pytorch_model.bin",
							    "safety_checker/model.safetensors",
							    "vae/diffusion_pytorch_model.bin",
							    "vae/diffusion_pytorch_model.safetensors",
							    "text_encoder/pytorch_model.bin",
							    "text_encoder/model.safetensors",
							    "unet/diffusion_pytorch_model.bin",
							    "unet/diffusion_pytorch_model.safetensors",
							]
							self.assertTrue(is_safetensors_compatible(__lowercase		)		)






						def 			snake_case__		(		self				:	List[Any]		):






							"""simple docstring"""






							snake_case_						       =	[
							    "unet/diffusion_pytorch_model.bin",
							    "unet/diffusion_pytorch_model.safetensors",
							]
							self.assertTrue(is_safetensors_compatible(__lowercase		)		)






						def 			snake_case__		(		self				:	Dict		):






							"""simple docstring"""






							snake_case_						       =	[
							    "safety_checker/pytorch_model.bin",
							    "safety_checker/model.safetensors",
							    "vae/diffusion_pytorch_model.bin",
							    "vae/diffusion_pytorch_model.safetensors",
							    "text_encoder/pytorch_model.bin",
							    "text_encoder/model.safetensors",
							    "unet/diffusion_pytorch_model.bin",
							    # Removed: 'unet/diffusion_pytorch_model.safetensors',
							]
							self.assertFalse(is_safetensors_compatible(__lowercase		)		)






						def 			snake_case__		(		self				:	Dict		):






							"""simple docstring"""






							snake_case_						       =	[
							    "text_encoder/pytorch_model.bin",
							    "text_encoder/model.safetensors",
							]
							self.assertTrue(is_safetensors_compatible(__lowercase		)		)






						def 			snake_case__		(		self				:	Optional[Any]		):






							"""simple docstring"""






							snake_case_						       =	[
							    "safety_checker/pytorch_model.bin",
							    "safety_checker/model.safetensors",
							    "vae/diffusion_pytorch_model.bin",
							    "vae/diffusion_pytorch_model.safetensors",
							    "text_encoder/pytorch_model.bin",
							    # Removed: 'text_encoder/model.safetensors',
							    "unet/diffusion_pytorch_model.bin",
							    "unet/diffusion_pytorch_model.safetensors",
							]
							self.assertFalse(is_safetensors_compatible(__lowercase		)		)






						def 			snake_case__		(		self				:	Dict		):






							"""simple docstring"""






							snake_case_						       =	[
							    "safety_checker/pytorch_model.fp16.bin",
							    "safety_checker/model.fp16.safetensors",
							    "vae/diffusion_pytorch_model.fp16.bin",
							    "vae/diffusion_pytorch_model.fp16.safetensors",
							    "text_encoder/pytorch_model.fp16.bin",
							    "text_encoder/model.fp16.safetensors",
							    "unet/diffusion_pytorch_model.fp16.bin",
							    "unet/diffusion_pytorch_model.fp16.safetensors",
							]
							snake_case_						       =	"fp16"
							self.assertTrue(is_safetensors_compatible(__lowercase			,      variant=__lowercase		)		)






						def 			snake_case__		(		self				:	Union[str, Any]		):






							"""simple docstring"""






							snake_case_						       =	[
							    "unet/diffusion_pytorch_model.fp16.bin",
							    "unet/diffusion_pytorch_model.fp16.safetensors",
							]
							snake_case_						       =	"fp16"
							self.assertTrue(is_safetensors_compatible(__lowercase			,      variant=__lowercase		)		)






						def 			snake_case__		(		self				:	Union[str, Any]		):






							"""simple docstring"""






							snake_case_						       =	[
							    "unet/diffusion_pytorch_model.bin",
							    "unet/diffusion_pytorch_model.safetensors",
							]
							snake_case_						       =	"fp16"
							self.assertTrue(is_safetensors_compatible(__lowercase			,      variant=__lowercase		)		)






						def 			snake_case__		(		self				:	List[str]		):






							"""simple docstring"""






							snake_case_						       =	[
							    "safety_checker/pytorch_model.fp16.bin",
							    "safety_checker/model.fp16.safetensors",
							    "vae/diffusion_pytorch_model.fp16.bin",
							    "vae/diffusion_pytorch_model.fp16.safetensors",
							    "text_encoder/pytorch_model.fp16.bin",
							    "text_encoder/model.fp16.safetensors",
							    "unet/diffusion_pytorch_model.fp16.bin",
							    # Removed: 'unet/diffusion_pytorch_model.fp16.safetensors',
							]
							snake_case_						       =	"fp16"
							self.assertFalse(is_safetensors_compatible(__lowercase			,      variant=__lowercase		)		)






						def 			snake_case__		(		self				:	Any		):






							"""simple docstring"""






							snake_case_						       =	[
							    "text_encoder/pytorch_model.fp16.bin",
							    "text_encoder/model.fp16.safetensors",
							]
							snake_case_						       =	"fp16"
							self.assertTrue(is_safetensors_compatible(__lowercase			,      variant=__lowercase		)		)






						def 			snake_case__		(		self				:	int		):






							"""simple docstring"""






							snake_case_						       =	[
							    "text_encoder/pytorch_model.bin",
							    "text_encoder/model.safetensors",
							]
							snake_case_						       =	"fp16"
							self.assertTrue(is_safetensors_compatible(__lowercase			,      variant=__lowercase		)		)






						def 			snake_case__		(		self				:	List[Any]		):






							"""simple docstring"""






							snake_case_						       =	[
							    "safety_checker/pytorch_model.fp16.bin",
							    "safety_checker/model.fp16.safetensors",
							    "vae/diffusion_pytorch_model.fp16.bin",
							    "vae/diffusion_pytorch_model.fp16.safetensors",
							    "text_encoder/pytorch_model.fp16.bin",
							    # 'text_encoder/model.fp16.safetensors',
							    "unet/diffusion_pytorch_model.fp16.bin",
							    "unet/diffusion_pytorch_model.fp16.safetensors",
							]
							snake_case_						       =	"fp16"
							self.assertFalse(is_safetensors_compatible(__lowercase			,      variant=__lowercase		)		)






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()
