


import math

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






def 		lowercase_(  SCREAMING_SNAKE_CASE_ = 3	):


  '''simple docstring'''

  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)."	)

  lowerCamelCase :					List[str]    =				QuantumRegister(SCREAMING_SNAKE_CASE_      ,						"qr"	)
  lowerCamelCase :					Optional[Any]    =				ClassicalRegister(SCREAMING_SNAKE_CASE_      ,						"cr"	)

  lowerCamelCase :					List[Any]    =				QuantumCircuit(SCREAMING_SNAKE_CASE_      ,						SCREAMING_SNAKE_CASE_	)

  lowerCamelCase :					Optional[int]    =				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
  lowerCamelCase :					str    =				Aer.get_backend("qasm_simulator"	)
  lowerCamelCase :					str    =				execute(SCREAMING_SNAKE_CASE_      ,						SCREAMING_SNAKE_CASE_      ,						shots=10000	)

  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)}'''
   )







import argparse

import intel_extension_for_pytorch as ipex
import torch

from diffusers import DPMSolverMultistepScheduler, StableDiffusionPipeline


_snake_case             =     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''')
_snake_case             =     parser.parse_args()


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

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

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

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

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

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

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



