


"""simple docstring"""
from typing import Any, Callable, Dict, List, Optional, Union

import PIL.Image
import torch
from transformers import CLIPImageProcessor, CLIPTextModel, CLIPTokenizer

from diffusers import (
    AutoencoderKL,
    DDIMScheduler,
    DiffusionPipeline,
    LMSDiscreteScheduler,
    PNDMScheduler,
    StableDiffusionImgaImgPipeline,
    StableDiffusionInpaintPipelineLegacy,
    StableDiffusionPipeline,
    UNetaDConditionModel,
)
from diffusers.configuration_utils import FrozenDict
from diffusers.pipelines.stable_diffusion.safety_checker import StableDiffusionSafetyChecker
from diffusers.utils import deprecate, logging


__SCREAMING_SNAKE_CASE				:     List[str]		=     logging.get_logger(__name__)  # pylint: disable=invalid-name





class   __A  (snake_case__):





							'''simple docstring'''

							__lowercase:		str				   =     ["""safety_checker""", """feature_extractor"""]



							def __init__(					self				:   int		,							UpperCAmelCase_				:   AutoencoderKL		,							UpperCAmelCase_				:   CLIPTextModel		,							UpperCAmelCase_				:   CLIPTokenizer		,							UpperCAmelCase_				:   UNetaDConditionModel		,							UpperCAmelCase_				:   Union[DDIMScheduler, PNDMScheduler, LMSDiscreteScheduler]		,							UpperCAmelCase_				:   StableDiffusionSafetyChecker		,							UpperCAmelCase_				:   CLIPImageProcessor		,							UpperCAmelCase_				:   bool = True		,							)       ->List[str]:



														"""simple docstring"""



														super().__init__()
														if hasattr(scheduler.config		,							"""steps_offset"""							) and scheduler.config.steps_offset != 1:
																					snake_case_     							=		(
																					    F"""The configuration file of this scheduler: {scheduler} is outdated. `steps_offset`"""
																					    F""" should be set to 1 instead of {scheduler.config.steps_offset}. Please make sure """
																					    """to update the config accordingly as leaving `steps_offset` might led to incorrect results"""
																					    """ in future versions. If you have downloaded this checkpoint from the Hugging Face Hub,"""
																					    """ it would be very nice if you could open a Pull request for the `scheduler/scheduler_config.json`"""
																					    """ file"""
																					)
																					deprecate("""steps_offset!=1"""		,							"""1.0.0"""		,							UpperCAmelCase_		,							standard_warn=UpperCAmelCase_							)
																					snake_case_     							=		dict(scheduler.config							)
																					snake_case_     							=		1
																					snake_case_     							=		FrozenDict(UpperCAmelCase_							)

														self.register_modules(
														    vae=UpperCAmelCase_		,							text_encoder=UpperCAmelCase_		,							tokenizer=UpperCAmelCase_		,							unet=UpperCAmelCase_		,							scheduler=UpperCAmelCase_		,							safety_checker=UpperCAmelCase_		,							feature_extractor=UpperCAmelCase_		,							)
														self.register_to_config(requires_safety_checker=UpperCAmelCase_							)



							@property
							def 		lowerCAmelCase							(					self				:   Union[str, Any]							)       ->Dict[str, Any]:



														"""simple docstring"""



														return {k: getattr(self		,							UpperCAmelCase_							) for k in self.config.keys() if not k.startswith("""_"""							)}



							def 		lowerCAmelCase							(					self				:   Union[str, Any]		,							UpperCAmelCase_				:   Optional[Union[str, int]] = "auto"							)       ->List[str]:



														"""simple docstring"""



														if slice_size == "auto":
																					# half the attention head size is usually a good trade-off between
																					# speed and memory
																					snake_case_     							=		self.unet.config.attention_head_dim // 2
														self.unet.set_attention_slice(UpperCAmelCase_							)



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



														"""simple docstring"""



														self.enable_attention_slicing(UpperCAmelCase_							)



							@torch.no_grad()
							def 		lowerCAmelCase							(					self				:   Union[str, Any]		,							UpperCAmelCase_				:   Union[str, List[str]]		,							UpperCAmelCase_				:   Union[torch.FloatTensor, PIL.Image.Image]		,							UpperCAmelCase_				:   Union[torch.FloatTensor, PIL.Image.Image]		,							UpperCAmelCase_				:   float = 0.8		,							UpperCAmelCase_				:   Optional[int] = 50		,							UpperCAmelCase_				:   Optional[float] = 7.5		,							UpperCAmelCase_				:   Optional[Union[str, List[str]]] = None		,							UpperCAmelCase_				:   Optional[int] = 1		,							UpperCAmelCase_				:   Optional[float] = 0.0		,							UpperCAmelCase_				:   Optional[torch.Generator] = None		,							UpperCAmelCase_				:   Optional[str] = "pil"		,							UpperCAmelCase_				:   bool = True		,							UpperCAmelCase_				:   Optional[Callable[[int, int, torch.FloatTensor], None]] = None		,							UpperCAmelCase_				:   int = 1		,							)       ->str:



														"""simple docstring"""



														return StableDiffusionInpaintPipelineLegacy(**self.components							)(
														    prompt=UpperCAmelCase_		,							image=UpperCAmelCase_		,							mask_image=UpperCAmelCase_		,							strength=UpperCAmelCase_		,							num_inference_steps=UpperCAmelCase_		,							guidance_scale=UpperCAmelCase_		,							negative_prompt=UpperCAmelCase_		,							num_images_per_prompt=UpperCAmelCase_		,							eta=UpperCAmelCase_		,							generator=UpperCAmelCase_		,							output_type=UpperCAmelCase_		,							return_dict=UpperCAmelCase_		,							callback=UpperCAmelCase_		,							)



							@torch.no_grad()
							def 		lowerCAmelCase							(					self				:   str		,							UpperCAmelCase_				:   Union[str, List[str]]		,							UpperCAmelCase_				:   Union[torch.FloatTensor, PIL.Image.Image]		,							UpperCAmelCase_				:   float = 0.8		,							UpperCAmelCase_				:   Optional[int] = 50		,							UpperCAmelCase_				:   Optional[float] = 7.5		,							UpperCAmelCase_				:   Optional[Union[str, List[str]]] = None		,							UpperCAmelCase_				:   Optional[int] = 1		,							UpperCAmelCase_				:   Optional[float] = 0.0		,							UpperCAmelCase_				:   Optional[torch.Generator] = None		,							UpperCAmelCase_				:   Optional[str] = "pil"		,							UpperCAmelCase_				:   bool = True		,							UpperCAmelCase_				:   Optional[Callable[[int, int, torch.FloatTensor], None]] = None		,							UpperCAmelCase_				:   int = 1		,							**UpperCAmelCase_				:   Dict		,							)       ->Optional[Any]:



														"""simple docstring"""



														return StableDiffusionImgaImgPipeline(**self.components							)(
														    prompt=UpperCAmelCase_		,							image=UpperCAmelCase_		,							strength=UpperCAmelCase_		,							num_inference_steps=UpperCAmelCase_		,							guidance_scale=UpperCAmelCase_		,							negative_prompt=UpperCAmelCase_		,							num_images_per_prompt=UpperCAmelCase_		,							eta=UpperCAmelCase_		,							generator=UpperCAmelCase_		,							output_type=UpperCAmelCase_		,							return_dict=UpperCAmelCase_		,							callback=UpperCAmelCase_		,							callback_steps=UpperCAmelCase_		,							)



							@torch.no_grad()
							def 		lowerCAmelCase							(					self				:   Tuple		,							UpperCAmelCase_				:   Union[str, List[str]]		,							UpperCAmelCase_				:   int = 512		,							UpperCAmelCase_				:   int = 512		,							UpperCAmelCase_				:   int = 50		,							UpperCAmelCase_				:   float = 7.5		,							UpperCAmelCase_				:   Optional[Union[str, List[str]]] = None		,							UpperCAmelCase_				:   Optional[int] = 1		,							UpperCAmelCase_				:   float = 0.0		,							UpperCAmelCase_				:   Optional[torch.Generator] = None		,							UpperCAmelCase_				:   Optional[torch.FloatTensor] = None		,							UpperCAmelCase_				:   Optional[str] = "pil"		,							UpperCAmelCase_				:   bool = True		,							UpperCAmelCase_				:   Optional[Callable[[int, int, torch.FloatTensor], None]] = None		,							UpperCAmelCase_				:   int = 1		,							)       ->str:



														"""simple docstring"""



														return StableDiffusionPipeline(**self.components							)(
														    prompt=UpperCAmelCase_		,							height=UpperCAmelCase_		,							width=UpperCAmelCase_		,							num_inference_steps=UpperCAmelCase_		,							guidance_scale=UpperCAmelCase_		,							negative_prompt=UpperCAmelCase_		,							num_images_per_prompt=UpperCAmelCase_		,							eta=UpperCAmelCase_		,							generator=UpperCAmelCase_		,							latents=UpperCAmelCase_		,							output_type=UpperCAmelCase_		,							return_dict=UpperCAmelCase_		,							callback=UpperCAmelCase_		,							callback_steps=UpperCAmelCase_		,							)







"""simple docstring"""
import doctest

import projectq
from projectq.ops import H, Measure







def     _a					(   _SCREAMING_SNAKE_CASE					)     ->					int:
							snake_case_     							=		quantum_engine.allocate_qubit()
							H | qubit
							Measure | qubit
							return int(_SCREAMING_SNAKE_CASE					)


if __name__ == "__main__":
				doctest.testmod()

				# initialises a new quantum backend
				__SCREAMING_SNAKE_CASE				:     Dict		=     projectq.MainEngine()

				# Generate a list of 10 random numbers
				__SCREAMING_SNAKE_CASE				:     Optional[Any]		=     [get_random_number(quantum_engine) for _ in range(10)]

				# Flushes the quantum engine from memory
				quantum_engine.flush()

				print('Random numbers', random_numbers_list)



