






"""simple docstring"""



import gc
import random
import unittest

import numpy as np
import torch
from transformers import XLMRobertaTokenizerFast

from diffusers import DDIMScheduler, KandinskyPipeline, KandinskyPriorPipeline, UNetaDConditionModel, VQModel
from diffusers.pipelines.kandinsky.text_encoder import MCLIPConfig, MultilingualCLIP
from diffusers.utils import floats_tensor, load_numpy, slow, torch_device
from diffusers.utils.testing_utils import enable_full_determinism, require_torch_gpu

from ..test_pipelines_common import PipelineTesterMixin, assert_mean_pixel_difference


enable_full_determinism()




class        __lowercase(       _a						,							unittest.TestCase  ):
						lowerCAmelCase_		:							Optional[Any]=       KandinskyPipeline
						lowerCAmelCase_		:							Dict=       [
						    'prompt',
						    'image_embeds',
						    'negative_image_embeds',
						]
						lowerCAmelCase_		:							List[Any]=       ['prompt', 'negative_prompt', 'image_embeds', 'negative_image_embeds']
						lowerCAmelCase_		:							int=       [
						    'generator',
						    'height',
						    'width',
						    'latents',
						    'guidance_scale',
						    'negative_prompt',
						    'num_inference_steps',
						    'return_dict',
						    'guidance_scale',
						    'num_images_per_prompt',
						    'output_type',
						    'return_dict',
						]
						lowerCAmelCase_		:							Optional[Any]=       False






						@property
						def 		lowerCAmelCase   (					self)			->  Tuple:




											"""simple docstring"""





											return 32






						@property
						def 		lowerCAmelCase   (					self)			->  str:




											"""simple docstring"""





											return 32






						@property
						def 		lowerCAmelCase   (					self)			->  str:




											"""simple docstring"""





											return self.time_input_dim






						@property
						def 		lowerCAmelCase   (					self)			->  Tuple:




											"""simple docstring"""





											return self.time_input_dim * 4






						@property
						def 		lowerCAmelCase   (					self)			->  Dict:




											"""simple docstring"""





											return 1_00






						@property
						def 		lowerCAmelCase   (					self)			->  Any:




											"""simple docstring"""





											lowerCamelCase__				=XLMRobertaTokenizerFast.from_pretrained('YiYiXu/tiny-random-mclip-base')
											return tokenizer






						@property
						def 		lowerCAmelCase   (					self)			->  Tuple:




											"""simple docstring"""





											torch.manual_seed(0)
											lowerCamelCase__				=MCLIPConfig(
											    numDims=self.cross_attention_dim    ,						transformerDimensions=self.text_embedder_hidden_size    ,						hidden_size=self.text_embedder_hidden_size    ,						intermediate_size=37    ,						num_attention_heads=4    ,						num_hidden_layers=5    ,						vocab_size=10_05    ,						)

											lowerCamelCase__				=MultilingualCLIP(_SCREAMING_SNAKE_CASE)
											lowerCamelCase__				=text_encoder.eval()

											return text_encoder






						@property
						def 		lowerCAmelCase   (					self)			->  List[Any]:




											"""simple docstring"""





											torch.manual_seed(0)

											lowerCamelCase__				={
											    'in_channels': 4,
											    # Out channels is double in channels because predicts mean and variance
											    'out_channels': 8,
											    'addition_embed_type': 'text_image',
											    'down_block_types': ('ResnetDownsampleBlock2D', 'SimpleCrossAttnDownBlock2D'),
											    'up_block_types': ('SimpleCrossAttnUpBlock2D', 'ResnetUpsampleBlock2D'),
											    'mid_block_type': 'UNetMidBlock2DSimpleCrossAttn',
											    'block_out_channels': (self.block_out_channels_a, self.block_out_channels_a * 2),
											    'layers_per_block': 1,
											    'encoder_hid_dim': self.text_embedder_hidden_size,
											    'encoder_hid_dim_type': 'text_image_proj',
											    'cross_attention_dim': self.cross_attention_dim,
											    'attention_head_dim': 4,
											    'resnet_time_scale_shift': 'scale_shift',
											    'class_embed_type': None,
											}

											lowerCamelCase__				=UNetaDConditionModel(**_SCREAMING_SNAKE_CASE)
											return model






						@property
						def 		lowerCAmelCase   (					self)			->  Optional[Any]:




											"""simple docstring"""





											return {
											    "block_out_channels": [32, 64],
											    "down_block_types": ["DownEncoderBlock2D", "AttnDownEncoderBlock2D"],
											    "in_channels": 3,
											    "latent_channels": 4,
											    "layers_per_block": 1,
											    "norm_num_groups": 8,
											    "norm_type": "spatial",
											    "num_vq_embeddings": 12,
											    "out_channels": 3,
											    "up_block_types": [
											        "AttnUpDecoderBlock2D",
											        "UpDecoderBlock2D",
											    ],
											    "vq_embed_dim": 4,
											}






						@property
						def 		lowerCAmelCase   (					self)			->  int:




											"""simple docstring"""





											torch.manual_seed(0)
											lowerCamelCase__				=VQModel(**self.dummy_movq_kwargs)
											return model






						def 		lowerCAmelCase   (					self)			->  int:




											"""simple docstring"""





											lowerCamelCase__				=self.dummy_text_encoder
											lowerCamelCase__				=self.dummy_tokenizer
											lowerCamelCase__				=self.dummy_unet
											lowerCamelCase__				=self.dummy_movq

											lowerCamelCase__				=DDIMScheduler(
											    num_train_timesteps=10_00    ,						beta_schedule='linear'    ,						beta_start=0.00085    ,						beta_end=0.012    ,						clip_sample=_SCREAMING_SNAKE_CASE    ,						set_alpha_to_one=_SCREAMING_SNAKE_CASE    ,						steps_offset=1    ,						prediction_type='epsilon'    ,						thresholding=_SCREAMING_SNAKE_CASE    ,						)

											lowerCamelCase__				={
											    'text_encoder': text_encoder,
											    'tokenizer': tokenizer,
											    'unet': unet,
											    'scheduler': scheduler,
											    'movq': movq,
											}
											return components






						def 		lowerCAmelCase   (					self    ,						_SCREAMING_SNAKE_CASE    ,						_SCREAMING_SNAKE_CASE=0)			->  Union[str, Any]:




											"""simple docstring"""





											lowerCamelCase__				=floats_tensor((1, self.cross_attention_dim)    ,						rng=random.Random(_SCREAMING_SNAKE_CASE)).to(_SCREAMING_SNAKE_CASE)
											lowerCamelCase__				=floats_tensor((1, self.cross_attention_dim)    ,						rng=random.Random(seed + 1)).to(_SCREAMING_SNAKE_CASE)
											if str(_SCREAMING_SNAKE_CASE).startswith('mps'):
																lowerCamelCase__				=torch.manual_seed(_SCREAMING_SNAKE_CASE)
											else:
																lowerCamelCase__				=torch.Generator(device=_SCREAMING_SNAKE_CASE).manual_seed(_SCREAMING_SNAKE_CASE)
											lowerCamelCase__				={
											    'prompt': 'horse',
											    'image_embeds': image_embeds,
											    'negative_image_embeds': negative_image_embeds,
											    'generator': generator,
											    'height': 64,
											    'width': 64,
											    'guidance_scale': 4.0,
											    'num_inference_steps': 2,
											    'output_type': 'np',
											}
											return inputs






						def 		lowerCAmelCase   (					self)			->  Optional[int]:




											"""simple docstring"""





											lowerCamelCase__				='cpu'

											lowerCamelCase__				=self.get_dummy_components()

											lowerCamelCase__				=self.pipeline_class(**_SCREAMING_SNAKE_CASE)
											lowerCamelCase__				=pipe.to(_SCREAMING_SNAKE_CASE)

											pipe.set_progress_bar_config(disable=_SCREAMING_SNAKE_CASE)

											lowerCamelCase__				=pipe(**self.get_dummy_inputs(_SCREAMING_SNAKE_CASE))
											lowerCamelCase__				=output.images

											lowerCamelCase__				=pipe(
											    **self.get_dummy_inputs(_SCREAMING_SNAKE_CASE)    ,						return_dict=_SCREAMING_SNAKE_CASE    ,						)[0]

											lowerCamelCase__				=image[0, -3:, -3:, -1]
											lowerCamelCase__				=image_from_tuple[0, -3:, -3:, -1]

											assert image.shape == (1, 64, 64, 3)

											lowerCamelCase__				=np.array(
											    [0.328663, 1.0, 0.23216873, 1.0, 0.92717564, 0.4639046, 0.96894777, 0.31713378, 0.6293953])

											assert (
											    np.abs(image_slice.flatten() - expected_slice).max() < 1E-2
											), F" expected_slice {expected_slice}, but got {image_slice.flatten()}"
											assert (
											    np.abs(image_from_tuple_slice.flatten() - expected_slice).max() < 1E-2
											), F" expected_slice {expected_slice}, but got {image_from_tuple_slice.flatten()}"




@slow
@require_torch_gpu
class        __lowercase(       unittest.TestCase  ):






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




											"""simple docstring"""





											super().tearDown()
											gc.collect()
											torch.cuda.empty_cache()






						def 		lowerCAmelCase   (					self)			->  Optional[Any]:




											"""simple docstring"""





											lowerCamelCase__				=load_numpy(
											    'https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main'
											    '/kandinsky/kandinsky_text2img_cat_fp16.npy')

											lowerCamelCase__				=KandinskyPriorPipeline.from_pretrained(
											    'kandinsky-community/kandinsky-2-1-prior'    ,						torch_dtype=torch.floataa)
											pipe_prior.to(_SCREAMING_SNAKE_CASE)

											lowerCamelCase__				=KandinskyPipeline.from_pretrained('kandinsky-community/kandinsky-2-1'    ,						torch_dtype=torch.floataa)
											lowerCamelCase__				=pipeline.to(_SCREAMING_SNAKE_CASE)
											pipeline.set_progress_bar_config(disable=_SCREAMING_SNAKE_CASE)

											lowerCamelCase__				='red cat, 4k photo'

											lowerCamelCase__				=torch.Generator(device='cuda').manual_seed(0)
											lowerCamelCase__				,     lowerCamelCase__				=pipe_prior(
											    _SCREAMING_SNAKE_CASE    ,						generator=_SCREAMING_SNAKE_CASE    ,						num_inference_steps=5    ,						negative_prompt=''    ,						).to_tuple()

											lowerCamelCase__				=torch.Generator(device='cuda').manual_seed(0)
											lowerCamelCase__				=pipeline(
											    _SCREAMING_SNAKE_CASE    ,						image_embeds=_SCREAMING_SNAKE_CASE    ,						negative_image_embeds=_SCREAMING_SNAKE_CASE    ,						generator=_SCREAMING_SNAKE_CASE    ,						num_inference_steps=1_00    ,						output_type='np'    ,						)

											lowerCamelCase__				=output.images[0]

											assert image.shape == (5_12, 5_12, 3)

											assert_mean_pixel_difference(_SCREAMING_SNAKE_CASE    ,						_SCREAMING_SNAKE_CASE)







"""simple docstring"""



import math

import qiskit
from qiskit import Aer, ClassicalRegister, QuantumCircuit, QuantumRegister, execute




def 						lowerCamelCase_				(  __A  :		int = 1			,	__A  :		int = 1			):
					if isinstance(__A			,	__A			) or isinstance(__A			,	__A			):
										raise TypeError('inputs must be integers.'			)
					if (bit_a < 0) or (bit_a < 0):
										raise ValueError('inputs must be positive.'			)
					if (math.floor(__A			) != bit_a) or (math.floor(__A			) != bit_a):
										raise ValueError('inputs must be exact integers.'			)
					if (bit_a > 1) or (bit_a > 1):
										raise ValueError('inputs must be less or equal to 1.'			)

					# build registers
					lowerCamelCase__				=QuantumRegister(2			,	'qr'			)
					lowerCamelCase__				=ClassicalRegister(2			,	'cr'			)

					lowerCamelCase__				=QuantumCircuit(__A			,	__A			)

					# entanglement the qubits
					quantum_circuit.h(1			)
					quantum_circuit.cx(1			,	0			)

					# send the information
					lowerCamelCase__				=str(__A			) + str(__A			)

					if c_information == "11":
										quantum_circuit.x(1			)
										quantum_circuit.z(1			)
					elif c_information == "10":
										quantum_circuit.z(1			)
					elif c_information == "01":
										quantum_circuit.x(1			)
					else:
										quantum_circuit.i(1			)

					# unentangled the circuit
					quantum_circuit.cx(1			,	0			)
					quantum_circuit.h(1			)

					# measure the circuit
					quantum_circuit.measure(__A			,	__A			)

					lowerCamelCase__				=Aer.get_backend('aer_simulator'			)
					lowerCamelCase__				=execute(__A			,	__A			,	shots=1000			)

					return job.result().get_counts(__A			)


if __name__ == "__main__":
						print(f"Counts for classical state send: {superdense_coding(1,1)}")