import math

import qiskit



def lowerCamelCase  (   SCREAMING_SNAKE_CASE = 1  ,			SCREAMING_SNAKE_CASE = 1  ,			SCREAMING_SNAKE_CASE = 1	):
    '''simple docstring'''







    if (
        isinstance(SCREAMING_SNAKE_CASE  ,			SCREAMING_SNAKE_CASE	)
        or isinstance(SCREAMING_SNAKE_CASE  ,			SCREAMING_SNAKE_CASE	)
        or isinstance(SCREAMING_SNAKE_CASE  ,			SCREAMING_SNAKE_CASE	)
    ):
        raise TypeError('''inputs must be integers.'''	)

    if (input_a < 0) or (input_a < 0) or (carry_in < 0):
        raise ValueError('''inputs must be positive.'''	)

    if (
        (math.floor(SCREAMING_SNAKE_CASE	) != input_a)
        or (math.floor(SCREAMING_SNAKE_CASE	) != input_a)
        or (math.floor(SCREAMING_SNAKE_CASE	) != carry_in)
    ):
        raise ValueError('''inputs must be exact integers.'''	)

    if (input_a > 2) or (input_a > 2) or (carry_in > 2):
        raise ValueError('''inputs must be less or equal to 2.'''	)

    # build registers
    __UpperCamelCase     :List[str]			  =		qiskit.QuantumRegister(4  ,			'''qr'''	)
    __UpperCamelCase     :str			  =		qiskit.ClassicalRegister(2  ,			'''cr'''	)
    # list the entries
    __UpperCamelCase     :Tuple			  =		[input_a, input_a, carry_in]

    __UpperCamelCase     :Optional[int]			  =		qiskit.QuantumCircuit(SCREAMING_SNAKE_CASE  ,			SCREAMING_SNAKE_CASE	)

    for i in range(0  ,			3	):
        if entry[i] == 2:
            quantum_circuit.h(SCREAMING_SNAKE_CASE	)  # for hadamard entries
        elif entry[i] == 1:
            quantum_circuit.x(SCREAMING_SNAKE_CASE	)  # for 1 entries
        elif entry[i] == 0:
            quantum_circuit.i(SCREAMING_SNAKE_CASE	)  # for 0 entries

    # build the circuit
    quantum_circuit.ccx(0  ,			1  ,			3	)  # ccx = toffoli gate
    quantum_circuit.cx(0  ,			1	)
    quantum_circuit.ccx(1  ,			2  ,			3	)
    quantum_circuit.cx(1  ,			2	)
    quantum_circuit.cx(0  ,			1	)

    quantum_circuit.measure([2, 3]  ,			SCREAMING_SNAKE_CASE	)  # measure the last two qbits

    __UpperCamelCase     :Optional[Any]			  =		qiskit.Aer.get_backend('''aer_simulator'''	)
    __UpperCamelCase     :Tuple			  =		qiskit.execute(SCREAMING_SNAKE_CASE  ,			SCREAMING_SNAKE_CASE  ,			shots=1_000	)

    return job.result().get_counts(SCREAMING_SNAKE_CASE	)


if __name__ == "__main__":
    print(F'Total sum count for state is: {quantum_full_adder(1, 1, 1)}')







import gc
import unittest

import numpy as np
import torch
from transformers import CLIPTextConfig, CLIPTextModel, CLIPTokenizer

from diffusers import (
    AutoencoderKL,
    DDIMScheduler,
    StableDiffusionAttendAndExcitePipeline,
    UNetaDConditionModel,
)
from diffusers.utils import load_numpy, skip_mps, slow
from diffusers.utils.testing_utils import require_torch_gpu

from ..pipeline_params import TEXT_TO_IMAGE_BATCH_PARAMS, TEXT_TO_IMAGE_IMAGE_PARAMS, TEXT_TO_IMAGE_PARAMS
from ..test_pipelines_common import PipelineKarrasSchedulerTesterMixin, PipelineLatentTesterMixin, PipelineTesterMixin


lowerCamelCase__          =		False







@skip_mps
class      A__							(     __magic_name__						,   __magic_name__						,   __magic_name__						,   unittest.TestCase	):
				lowercase			    =  StableDiffusionAttendAndExcitePipeline
				lowercase			    =  False
				lowercase			    =  TEXT_TO_IMAGE_PARAMS
				lowercase			    =  TEXT_TO_IMAGE_BATCH_PARAMS.union({'token_indices'}	)
				lowercase			    =  TEXT_TO_IMAGE_IMAGE_PARAMS
				lowercase			    =  TEXT_TO_IMAGE_IMAGE_PARAMS






				@classmethod
				def 							_lowerCamelCase		(						cls					:      Tuple   ):






							'''simple docstring'''







							super().setUpClass()
							torch.use_deterministic_algorithms(a   )






				@classmethod
				def 							_lowerCamelCase		(						cls					:      Any   ):






							'''simple docstring'''







							super().tearDownClass()
							torch.use_deterministic_algorithms(a   )






				def 							_lowerCamelCase		(						self					:      Optional[Any]   ):






							'''simple docstring'''







							torch.manual_seed(0   )
							lowerCAmelCase__      :      Any         =		UNetaDConditionModel(
							    block_out_channels=(32, 64)    ,     layers_per_block=1    ,     sample_size=32    ,     in_channels=4    ,     out_channels=4    ,     down_block_types=('DownBlock2D', 'CrossAttnDownBlock2D')    ,     up_block_types=('CrossAttnUpBlock2D', 'UpBlock2D')    ,     cross_attention_dim=32    ,     attention_head_dim=(2, 4)    ,     use_linear_projection=a    ,     )
							lowerCAmelCase__      :      Any         =		DDIMScheduler(
							    beta_start=0.0_0_0_8_5    ,     beta_end=0.0_1_2    ,     beta_schedule='scaled_linear'    ,     clip_sample=a    ,     set_alpha_to_one=a    ,     )
							torch.manual_seed(0   )
							lowerCAmelCase__      :      Union[str, Any]         =		AutoencoderKL(
							    block_out_channels=[32, 64]    ,     in_channels=3    ,     out_channels=3    ,     down_block_types=['DownEncoderBlock2D', 'DownEncoderBlock2D']    ,     up_block_types=['UpDecoderBlock2D', 'UpDecoderBlock2D']    ,     latent_channels=4    ,     sample_size=128    ,     )
							torch.manual_seed(0   )
							lowerCAmelCase__      :      Tuple         =		CLIPTextConfig(
							    bos_token_id=0    ,     eos_token_id=2    ,     hidden_size=32    ,     intermediate_size=37    ,     layer_norm_eps=1E-05    ,     num_attention_heads=4    ,     num_hidden_layers=5    ,     pad_token_id=1    ,     vocab_size=1_000    ,     hidden_act='gelu'    ,     projection_dim=512    ,     )
							lowerCAmelCase__      :      str         =		CLIPTextModel(a   )
							lowerCAmelCase__      :      Optional[Any]         =		CLIPTokenizer.from_pretrained('hf-internal-testing/tiny-random-clip'   )

							lowerCAmelCase__      :      Union[str, Any]         =		{
							    'unet': unet,
							    'scheduler': scheduler,
							    'vae': vae,
							    'text_encoder': text_encoder,
							    'tokenizer': tokenizer,
							    'safety_checker': None,
							    'feature_extractor': None,
							}

							return components






				def 							_lowerCamelCase		(						self					:      Union[str, Any]    ,     a					:      Tuple    ,     a					:      Union[str, Any]=0   ):






							'''simple docstring'''







							if str(a   ).startswith('mps'   ):
										lowerCAmelCase__      :      List[str]         =		torch.manual_seed(a   )
							else:
										lowerCAmelCase__      :      Any         =		torch.Generator(device=a   ).manual_seed(a   )
							lowerCAmelCase__      :      Optional[int]         =		{
							    'prompt': 'a cat and a frog',
							    'token_indices': [2, 5],
							    'generator': generator,
							    'num_inference_steps': 1,
							    'guidance_scale': 6.0,
							    'output_type': 'numpy',
							    'max_iter_to_alter': 2,
							    'thresholds': {0: 0.7},
							}
							return inputs






				def 							_lowerCamelCase		(						self					:      Optional[int]   ):






							'''simple docstring'''







							lowerCAmelCase__      :      Tuple         =		'cpu'

							lowerCAmelCase__      :      Optional[int]         =		self.get_dummy_components()
							lowerCAmelCase__      :      Dict         =		self.pipeline_class(**a   )
							pipe.to(a   )
							pipe.set_progress_bar_config(disable=a   )

							lowerCAmelCase__      :      Union[str, Any]         =		self.get_dummy_inputs(a   )
							lowerCAmelCase__      :      Union[str, Any]         =		pipe(**a   ).images
							lowerCAmelCase__      :      Optional[int]         =		image[0, -3:, -3:, -1]

							self.assertEqual(image.shape    ,     (1, 64, 64, 3)   )
							lowerCAmelCase__      :      Dict         =		np.array(
							    [0.6_3_9_0_5_3_6_4, 0.6_2_8_9_7_3_0_7, 0.4_8_5_9_9_0_1_7, 0.5_1_3_3_6_2_4, 0.5_5_5_0_0_4_8, 0.4_5_7_6_9_5_1_6, 0.5_0_3_2_6_9_7_3, 0.5_0_2_3_1_3_9, 0.4_5_3_8_4_4_9_6]   )
							lowerCAmelCase__      :      Optional[int]         =		np.abs(image_slice.flatten() - expected_slice   ).max()
							self.assertLessEqual(a    ,     1E-3   )






				def 							_lowerCamelCase		(						self					:      Optional[Any]   ):






							'''simple docstring'''







							super().test_cpu_offload_forward_pass(expected_max_diff=5E-4   )






				def 							_lowerCamelCase		(						self					:      List[str]   ):






							'''simple docstring'''







							self._test_inference_batch_consistent(batch_sizes=[1, 2]   )






				def 							_lowerCamelCase		(						self					:      Tuple   ):






							'''simple docstring'''







							self._test_inference_batch_single_identical(batch_size=2    ,     expected_max_diff=7E-4   )






				def 							_lowerCamelCase		(						self					:      List[Any]   ):






							'''simple docstring'''







							super().test_dict_tuple_outputs_equivalent(expected_max_difference=3E-3   )






				def 							_lowerCamelCase		(						self					:      List[str]   ):






							'''simple docstring'''







							super().test_pt_np_pil_outputs_equivalent(expected_max_diff=5E-4   )






				def 							_lowerCamelCase		(						self					:      Any   ):






							'''simple docstring'''







							super().test_save_load_local(expected_max_difference=5E-4   )






				def 							_lowerCamelCase		(						self					:      Dict   ):






							'''simple docstring'''







							super().test_save_load_optional_components(expected_max_difference=4E-4   )







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






				@classmethod
				def 							_lowerCamelCase		(						cls					:      List[str]   ):






							'''simple docstring'''







							super().setUpClass()
							torch.use_deterministic_algorithms(a   )






				@classmethod
				def 							_lowerCamelCase		(						cls					:      List[str]   ):






							'''simple docstring'''







							super().tearDownClass()
							torch.use_deterministic_algorithms(a   )






				def 							_lowerCamelCase		(						self					:      int   ):






							'''simple docstring'''







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






				def 							_lowerCamelCase		(						self					:      Tuple   ):






							'''simple docstring'''







							lowerCAmelCase__      :      List[str]         =		torch.manual_seed(51   )

							lowerCAmelCase__      :      Any         =		StableDiffusionAttendAndExcitePipeline.from_pretrained(
							    'CompVis/stable-diffusion-v1-4'    ,     safety_checker=a    ,     torch_dtype=torch.floataa   )
							pipe.to('cuda'   )

							lowerCAmelCase__      :      Optional[int]         =		'a painting of an elephant with glasses'
							lowerCAmelCase__      :      Any         =		[5, 7]

							lowerCAmelCase__      :      Optional[Any]         =		pipe(
							    prompt=a    ,     token_indices=a    ,     guidance_scale=7.5    ,     generator=a    ,     num_inference_steps=5    ,     max_iter_to_alter=5    ,     output_type='numpy'    ,     ).images[0]

							lowerCAmelCase__      :      str         =		load_numpy(
							    'https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/attend-and-excite/elephant_glasses.npy'   )
							assert np.abs((expected_image - image).max()   ) < 5E-1