




"""simple docstring"""







import gc
import tempfile
import unittest

import numpy as np
import torch

from diffusers import VersatileDiffusionPipeline
from diffusers.utils.testing_utils import load_image, nightly, require_torch_gpu, torch_device


SCREAMING_SNAKE_CASE_	     =       False

class 				snake_case_			(					unittest.TestCase			):







   """simple docstring"""




   pass

@nightly
@require_torch_gpu
class 				snake_case_			(					unittest.TestCase			):







   """simple docstring"""




   def   UpperCAmelCase__			(		self)				->   Optional[int]:
       # clean up the VRAM after each test
       super().tearDown()
       gc.collect()
       torch.cuda.empty_cache()







   def   UpperCAmelCase__			(		self)				->   int:
       UpperCamelCase              =	VersatileDiffusionPipeline.from_pretrained('''shi-labs/versatile-diffusion'''       ,					torch_dtype=torch.floataa)
       pipe.to(lowerCamelCase_)
       pipe.set_progress_bar_config(disable=lowerCamelCase_)

       UpperCamelCase              =	load_image(
           '''https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/versatile_diffusion/benz.jpg''')

       UpperCamelCase              =	torch.manual_seed(0)
       UpperCamelCase              =	pipe.dual_guided(
           prompt='''first prompt'''       ,					image=lowerCamelCase_       ,					text_to_image_strength=0.75       ,					generator=lowerCamelCase_       ,					guidance_scale=7.5       ,					num_inference_steps=2       ,					output_type='''numpy'''       ,					).images

       with tempfile.TemporaryDirectory() as tmpdirname:
           pipe.save_pretrained(lowerCamelCase_)
           UpperCamelCase              =	VersatileDiffusionPipeline.from_pretrained(lowerCamelCase_       ,					torch_dtype=torch.floataa)
       pipe.to(lowerCamelCase_)
       pipe.set_progress_bar_config(disable=lowerCamelCase_)

       UpperCamelCase              =	generator.manual_seed(0)
       UpperCamelCase              =	pipe.dual_guided(
           prompt='''first prompt'''       ,					image=lowerCamelCase_       ,					text_to_image_strength=0.75       ,					generator=lowerCamelCase_       ,					guidance_scale=7.5       ,					num_inference_steps=2       ,					output_type='''numpy'''       ,					).images

       assert np.abs(image - new_image).sum() < 1e-5, "Models don't have the same forward pass"







   def   UpperCAmelCase__			(		self)				->   int:
       UpperCamelCase              =	VersatileDiffusionPipeline.from_pretrained('''shi-labs/versatile-diffusion'''       ,					torch_dtype=torch.floataa)
       pipe.to(lowerCamelCase_)
       pipe.set_progress_bar_config(disable=lowerCamelCase_)

       UpperCamelCase              =	'''cyberpunk 2077'''
       UpperCamelCase              =	load_image(
           '''https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/versatile_diffusion/benz.jpg''')
       UpperCamelCase              =	torch.manual_seed(0)
       UpperCamelCase              =	pipe.dual_guided(
           prompt=lowerCamelCase_       ,					image=lowerCamelCase_       ,					text_to_image_strength=0.75       ,					generator=lowerCamelCase_       ,					guidance_scale=7.5       ,					num_inference_steps=5_0       ,					output_type='''numpy'''       ,					).images

       UpperCamelCase              =	image[0, 2_5_3:2_5_6, 2_5_3:2_5_6, -1]

       assert image.shape == (1, 5_1_2, 5_1_2, 3)
       UpperCamelCase              =	np.array([0.1448, 0.1619, 0.1741, 0.1086, 0.1147, 0.1128, 0.1199, 0.1165, 0.1001])

       assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-1

       UpperCamelCase              =	'''A painting of a squirrel eating a burger '''
       UpperCamelCase              =	torch.manual_seed(0)
       UpperCamelCase              =	pipe.text_to_image(
           prompt=lowerCamelCase_       ,					generator=lowerCamelCase_       ,					guidance_scale=7.5       ,					num_inference_steps=5_0       ,					output_type='''numpy''').images

       UpperCamelCase              =	image[0, 2_5_3:2_5_6, 2_5_3:2_5_6, -1]

       assert image.shape == (1, 5_1_2, 5_1_2, 3)
       UpperCamelCase              =	np.array([0.3367, 0.3169, 0.2656, 0.3870, 0.4790, 0.3796, 0.4009, 0.4878, 0.4778])

       assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-1

       UpperCamelCase              =	pipe.image_variation(lowerCamelCase_       ,					generator=lowerCamelCase_       ,					output_type='''numpy''').images

       UpperCamelCase              =	image[0, 2_5_3:2_5_6, 2_5_3:2_5_6, -1]

       assert image.shape == (1, 5_1_2, 5_1_2, 3)
       UpperCamelCase              =	np.array([0.3076, 0.3123, 0.3284, 0.3782, 0.3770, 0.3894, 0.4297, 0.4331, 0.4456])

       assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-1

'''simple docstring'''





import math

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







def snake_case_     (					lowercase__ = 3		):
  if isinstance(lowercase__   ,       lowercase__		):
    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(lowercase__		) != number_of_qubits:
    raise ValueError("number of qubits must be exact integer."		)
  if number_of_qubits > 1_0:
    raise ValueError("number of qubits too large to simulate(>10)."		)

  UpperCAmelCase__      :					Optional[int]				       =							QuantumRegister(lowercase__   ,       "qr"		)
  UpperCAmelCase__      :					List[Any]				       =							ClassicalRegister(lowercase__   ,       "cr"		)

  UpperCAmelCase__      :					List[str]				       =							QuantumCircuit(lowercase__   ,       lowercase__		)

  UpperCAmelCase__      :					Union[str, Any]				       =							number_of_qubits

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

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

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

  return job.result().get_counts(lowercase__		)


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



