





import argparse

import intel_extension_for_pytorch as ipex
import torch

from diffusers import DPMSolverMultistepScheduler, StableDiffusionPipeline


_lowerCamelCase			       =      argparse.ArgumentParser('Stable Diffusion script with intel optimization', add_help=False)
parser.add_argument('--dpm', action='store_true', help='Enable DPMSolver or not')
parser.add_argument('--steps', default=None, type=int, help='Num inference steps')
_lowerCamelCase			       =      parser.parse_args()


_lowerCamelCase			       =      'cpu'
_lowerCamelCase			       =      'a lovely <dicoo> in red dress and hat, in the snowly and brightly night, with many brighly buildings'

_lowerCamelCase			       =      'path-to-your-trained-model'
_lowerCamelCase			       =      StableDiffusionPipeline.from_pretrained(model_id)
if args.dpm:
       _lowerCamelCase			       =      DPMSolverMultistepScheduler.from_config(pipe.scheduler.config)
_lowerCamelCase			       =      pipe.to(device)

# to channels last
_lowerCamelCase			       =      pipe.unet.to(memory_format=torch.channels_last)
_lowerCamelCase			       =      pipe.vae.to(memory_format=torch.channels_last)
_lowerCamelCase			       =      pipe.text_encoder.to(memory_format=torch.channels_last)
if pipe.requires_safety_checker:
       _lowerCamelCase			       =      pipe.safety_checker.to(memory_format=torch.channels_last)

# optimize with ipex
_lowerCamelCase			       =      torch.randn(2, 4, 64, 64)
_lowerCamelCase			       =      torch.rand(1) * 999
_lowerCamelCase			       =      torch.randn(2, 77, 768)
_lowerCamelCase			       =      (sample, timestep, encoder_hidden_status)
try:
       _lowerCamelCase			       =      ipex.optimize(pipe.unet.eval(), dtype=torch.bfloataa, inplace=True, sample_input=input_example)
except Exception:
       _lowerCamelCase			       =      ipex.optimize(pipe.unet.eval(), dtype=torch.bfloataa, inplace=True)
_lowerCamelCase			       =      ipex.optimize(pipe.vae.eval(), dtype=torch.bfloataa, inplace=True)
_lowerCamelCase			       =      ipex.optimize(pipe.text_encoder.eval(), dtype=torch.bfloataa, inplace=True)
if pipe.requires_safety_checker:
       _lowerCamelCase			       =      ipex.optimize(pipe.safety_checker.eval(), dtype=torch.bfloataa, inplace=True)

# compute
_lowerCamelCase			       =      666
_lowerCamelCase			       =      torch.Generator(device).manual_seed(seed)
_lowerCamelCase			       =      {'generator': generator}
if args.steps is not None:
       _lowerCamelCase			       =      args.steps

with torch.cpu.amp.autocast(enabled=True, dtype=torch.bfloataa):
       _lowerCamelCase			       =      pipe(prompt, **generate_kwargs).images[0]

# save image
image.save('generated.png')








import qiskit




def    __UpperCAmelCase(      lowercase_ = 2      ):
       _lowerCamelCase							:     Optional[Any]	=		qubits

       # Using Aer's simulator
       _lowerCamelCase							:     Optional[int]	=		qiskit.Aer.get_backend('''aer_simulator'''      )

       # Creating a Quantum Circuit acting on the q register
       _lowerCamelCase							:     List[str]	=		qiskit.QuantumCircuit(lowercase_ ,    lowercase_      )

       # Adding a H gate on qubit 0 (now q0 in superposition)
       circuit.h(0      )

       for i in range(1 ,    lowercase_      ):
              # Adding CX (CNOT) gate
              circuit.cx(i - 1 ,    lowercase_      )

       # Mapping the quantum measurement to the classical bits
       circuit.measure(list(range(lowercase_      )      ) ,    list(range(lowercase_      )      )      )

       # Now measuring any one qubit would affect other qubits to collapse
       # their super position and have same state as the measured one.

       # Executing the circuit on the simulator
       _lowerCamelCase							:     str	=		qiskit.execute(lowercase_ ,    lowercase_ ,    shots=10_00      )

       return job.result().get_counts(lowercase_      )


if __name__ == "__main__":
       print(F'''Total count for various states are: {quantum_entanglement(3)}''')

