





from typing import Any, Callable, Dict, List, Optional, Union

import torch
from transformers import CLIPImageProcessor, CLIPTextModel, CLIPTokenizer

from diffusers import (
    AutoencoderKL,
    DDIMScheduler,
    DiffusionPipeline,
    LMSDiscreteScheduler,
    PNDMScheduler,
    StableDiffusionPipeline,
    UNetaDConditionModel,
)
from diffusers.pipelines.stable_diffusion import StableDiffusionPipelineOutput
from diffusers.pipelines.stable_diffusion.safety_checker import StableDiffusionSafetyChecker


__UpperCAmelCase	:       List[str]    	=							"CompVis/stable-diffusion-v1-1"
__UpperCAmelCase	:       int    	=							"CompVis/stable-diffusion-v1-2"
__UpperCAmelCase	:       Optional[Any]    	=							"CompVis/stable-diffusion-v1-3"
__UpperCAmelCase	:       Any    	=							"CompVis/stable-diffusion-v1-4"







class    __snake_case	(							__lowerCamelCase      ):





       '''simple docstring'''







       def __init__(  self			:   Union[str, Any]							,    A			:   AutoencoderKL							,    A			:   CLIPTextModel							,    A			:   CLIPTokenizer							,    A			:   UNetaDConditionModel							,    A			:   Union[DDIMScheduler, PNDMScheduler, LMSDiscreteScheduler]							,    A			:   StableDiffusionSafetyChecker							,    A			:   CLIPImageProcessor							,    A			:   bool = True							,    ):
         super()._init_()

         __snake_case:						str			  =						StableDiffusionPipeline.from_pretrained(A		)
         __snake_case:						List[str]			  =						StableDiffusionPipeline.from_pretrained(A		)
         __snake_case:						Tuple			  =						StableDiffusionPipeline.from_pretrained(A		)
         __snake_case:						Dict			  =						StableDiffusionPipeline(
             vae=A							,    text_encoder=A							,    tokenizer=A							,    unet=A							,    scheduler=A							,    safety_checker=A							,    feature_extractor=A							,    requires_safety_checker=A							,    )

         self.register_modules(pipelinea=self.pipea							,    pipelinea=self.pipea							,    pipelinea=self.pipea							,    pipelinea=self.pipea		)




       @property
       def 							UpperCAmelCase__			(  self			:   Tuple		):
         return {k: getattr(self							,    A		) for k in self.config.keys() if not k.startswith("""_"""		)}




       def 							UpperCAmelCase__			(  self			:   Optional[int]							,    A			:   Optional[Union[str, int]] = "auto"		):
         if slice_size == "auto":
           # half the attention head size is usually a good trade-off between
           # speed and memory
           __snake_case:						Optional[Any]			  =						self.unet.config.attention_head_dim // 2
         self.unet.set_attention_slice(A		)




       def 							UpperCAmelCase__			(  self			:   List[Any]		):
         self.enable_attention_slicing(A		)




       @torch.no_grad()
       def 							UpperCAmelCase__			(  self			:   Tuple							,    A			:   Union[str, List[str]]							,    A			:   int = 512							,    A			:   int = 512							,    A			:   int = 50							,    A			:   float = 7.5							,    A			:   Optional[Union[str, List[str]]] = None							,    A			:   Optional[int] = 1							,    A			:   float = 0.0							,    A			:   Optional[torch.Generator] = None							,    A			:   Optional[torch.FloatTensor] = None							,    A			:   Optional[str] = "pil"							,    A			:   bool = True							,    A			:   Optional[Callable[[int, int, torch.FloatTensor], None]] = None							,    A			:   int = 1							,    **A			:   Union[str, Any]							,    ):
         return self.pipea(
             prompt=A							,    height=A							,    width=A							,    num_inference_steps=A							,    guidance_scale=A							,    negative_prompt=A							,    num_images_per_prompt=A							,    eta=A							,    generator=A							,    latents=A							,    output_type=A							,    return_dict=A							,    callback=A							,    callback_steps=A							,    **A							,    )




       @torch.no_grad()
       def 							UpperCAmelCase__			(  self			:   Any							,    A			:   Union[str, List[str]]							,    A			:   int = 512							,    A			:   int = 512							,    A			:   int = 50							,    A			:   float = 7.5							,    A			:   Optional[Union[str, List[str]]] = None							,    A			:   Optional[int] = 1							,    A			:   float = 0.0							,    A			:   Optional[torch.Generator] = None							,    A			:   Optional[torch.FloatTensor] = None							,    A			:   Optional[str] = "pil"							,    A			:   bool = True							,    A			:   Optional[Callable[[int, int, torch.FloatTensor], None]] = None							,    A			:   int = 1							,    **A			:   str							,    ):
         return self.pipea(
             prompt=A							,    height=A							,    width=A							,    num_inference_steps=A							,    guidance_scale=A							,    negative_prompt=A							,    num_images_per_prompt=A							,    eta=A							,    generator=A							,    latents=A							,    output_type=A							,    return_dict=A							,    callback=A							,    callback_steps=A							,    **A							,    )




       @torch.no_grad()
       def 							UpperCAmelCase__			(  self			:   Dict							,    A			:   Union[str, List[str]]							,    A			:   int = 512							,    A			:   int = 512							,    A			:   int = 50							,    A			:   float = 7.5							,    A			:   Optional[Union[str, List[str]]] = None							,    A			:   Optional[int] = 1							,    A			:   float = 0.0							,    A			:   Optional[torch.Generator] = None							,    A			:   Optional[torch.FloatTensor] = None							,    A			:   Optional[str] = "pil"							,    A			:   bool = True							,    A			:   Optional[Callable[[int, int, torch.FloatTensor], None]] = None							,    A			:   int = 1							,    **A			:   Tuple							,    ):
         return self.pipea(
             prompt=A							,    height=A							,    width=A							,    num_inference_steps=A							,    guidance_scale=A							,    negative_prompt=A							,    num_images_per_prompt=A							,    eta=A							,    generator=A							,    latents=A							,    output_type=A							,    return_dict=A							,    callback=A							,    callback_steps=A							,    **A							,    )




       @torch.no_grad()
       def 							UpperCAmelCase__			(  self			:   str							,    A			:   Union[str, List[str]]							,    A			:   int = 512							,    A			:   int = 512							,    A			:   int = 50							,    A			:   float = 7.5							,    A			:   Optional[Union[str, List[str]]] = None							,    A			:   Optional[int] = 1							,    A			:   float = 0.0							,    A			:   Optional[torch.Generator] = None							,    A			:   Optional[torch.FloatTensor] = None							,    A			:   Optional[str] = "pil"							,    A			:   bool = True							,    A			:   Optional[Callable[[int, int, torch.FloatTensor], None]] = None							,    A			:   int = 1							,    **A			:   Any							,    ):
         return self.pipea(
             prompt=A							,    height=A							,    width=A							,    num_inference_steps=A							,    guidance_scale=A							,    negative_prompt=A							,    num_images_per_prompt=A							,    eta=A							,    generator=A							,    latents=A							,    output_type=A							,    return_dict=A							,    callback=A							,    callback_steps=A							,    **A							,    )






       @torch.no_grad()
       def 							UpperCAmelCase__			(  self			:   str							,    A			:   Union[str, List[str]]							,    A			:   int = 512							,    A			:   int = 512							,    A			:   int = 50							,    A			:   float = 7.5							,    A			:   Optional[Union[str, List[str]]] = None							,    A			:   Optional[int] = 1							,    A			:   float = 0.0							,    A			:   Optional[torch.Generator] = None							,    A			:   Optional[torch.FloatTensor] = None							,    A			:   Optional[str] = "pil"							,    A			:   bool = True							,    A			:   Optional[Callable[[int, int, torch.FloatTensor], None]] = None							,    A			:   int = 1							,    **A			:   Optional[int]							,    ):
         __snake_case:						Any			  =						"""cuda""" if torch.cuda.is_available() else """cpu"""
         self.to(A		)

         # Checks if the height and width are divisible by 8 or not
         if height % 8 != 0 or width % 8 != 0:
           raise ValueError(f'''`height` and `width` must be divisible by 8 but are {height} and {width}.'''		)

         # Get first result from Stable Diffusion Checkpoint v1.1
         __snake_case:						str			  =						self.textaimg_sda_a(
             prompt=A							,    height=A							,    width=A							,    num_inference_steps=A							,    guidance_scale=A							,    negative_prompt=A							,    num_images_per_prompt=A							,    eta=A							,    generator=A							,    latents=A							,    output_type=A							,    return_dict=A							,    callback=A							,    callback_steps=A							,    **A							,    )

         # Get first result from Stable Diffusion Checkpoint v1.2
         __snake_case:						Optional[int]			  =						self.textaimg_sda_a(
             prompt=A							,    height=A							,    width=A							,    num_inference_steps=A							,    guidance_scale=A							,    negative_prompt=A							,    num_images_per_prompt=A							,    eta=A							,    generator=A							,    latents=A							,    output_type=A							,    return_dict=A							,    callback=A							,    callback_steps=A							,    **A							,    )

         # Get first result from Stable Diffusion Checkpoint v1.3
         __snake_case:						List[Any]			  =						self.textaimg_sda_a(
             prompt=A							,    height=A							,    width=A							,    num_inference_steps=A							,    guidance_scale=A							,    negative_prompt=A							,    num_images_per_prompt=A							,    eta=A							,    generator=A							,    latents=A							,    output_type=A							,    return_dict=A							,    callback=A							,    callback_steps=A							,    **A							,    )

         # Get first result from Stable Diffusion Checkpoint v1.4
         __snake_case:						int			  =						self.textaimg_sda_a(
             prompt=A							,    height=A							,    width=A							,    num_inference_steps=A							,    guidance_scale=A							,    negative_prompt=A							,    num_images_per_prompt=A							,    eta=A							,    generator=A							,    latents=A							,    output_type=A							,    return_dict=A							,    callback=A							,    callback_steps=A							,    **A							,    )

         # Get all result images into a single list and pass it via StableDiffusionPipelineOutput for final result
         return StableDiffusionPipelineOutput([resa[0], resa[0], resa[0], resa[0]]		)













import math

import numpy as np
import qiskit
from qiskit import Aer, ClassicalRegister, QuantumCircuit, QuantumRegister, execute







def       A__							(   SCREAMING_SNAKE_CASE__ = 3)       ->   qiskit.result.counts.Counts:
  if isinstance(SCREAMING_SNAKE_CASE__ , SCREAMING_SNAKE_CASE__):
    raise TypeError("""number of qubits must be a integer.""")
  if number_of_qubits <= 0:
    raise ValueError("""number of qubits must be > 0.""")
  if math.floor(SCREAMING_SNAKE_CASE__) != number_of_qubits:
    raise ValueError("""number of qubits must be exact integer.""")
  if number_of_qubits > 10:
    raise ValueError("""number of qubits too large to simulate(>10).""")

  __snake_case:						int			  =						QuantumRegister(SCREAMING_SNAKE_CASE__ , """qr""")
  __snake_case:						List[str]			  =						ClassicalRegister(SCREAMING_SNAKE_CASE__ , """cr""")

  __snake_case:						Optional[Any]			  =						QuantumCircuit(SCREAMING_SNAKE_CASE__ , SCREAMING_SNAKE_CASE__)

  __snake_case:						Tuple			  =						number_of_qubits

  for i in range(SCREAMING_SNAKE_CASE__):
    quantum_circuit.h(number_of_qubits - i - 1)
    counter -= 1
    for j in range(SCREAMING_SNAKE_CASE__):
      quantum_circuit.cp(np.pi / 2 ** (counter - j) , SCREAMING_SNAKE_CASE__ , SCREAMING_SNAKE_CASE__)

  for k in range(number_of_qubits // 2):
    quantum_circuit.swap(SCREAMING_SNAKE_CASE__ , number_of_qubits - k - 1)

  # measure all the qubits
  quantum_circuit.measure(SCREAMING_SNAKE_CASE__ , SCREAMING_SNAKE_CASE__)
  # simulate with 10000 shots
  __snake_case:						Union[str, Any]			  =						Aer.get_backend("""qasm_simulator""")
  __snake_case:						Optional[Any]			  =						execute(SCREAMING_SNAKE_CASE__ , SCREAMING_SNAKE_CASE__ , shots=1_0000)

  return job.result().get_counts(SCREAMING_SNAKE_CASE__)


if __name__ == "__main__":
      print(
          f'Total count for quantum fourier transform state is: \
    {quantum_fourier_transform(3)}'
      )






