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




def 				_snake_case     (       lowerCAmelCase							:       float = np.pi / 2       ,			lowerCAmelCase							:       float = np.pi / 2       ,			lowerCAmelCase							:       float = np.pi / 2     ):
  """simple docstring"""







  SCREAMING_SNAKE_CASE_  :		Dict    				=   QuantumRegister(3       ,			"qr"     )  # Define the number of quantum bits
  SCREAMING_SNAKE_CASE_  :		Optional[int]    				=   ClassicalRegister(1       ,			"cr"     )  # Define the number of classical bits

  SCREAMING_SNAKE_CASE_  :		Union[str, Any]    				=   QuantumCircuit(lowerCAmelCase       ,			lowerCAmelCase     )  # Define the quantum circuit.

  # Build the circuit
  quantum_circuit.u(lowerCAmelCase       ,			lowerCAmelCase       ,			lowerCAmelCase       ,			0     )  # Quantum State to teleport
  quantum_circuit.h(1     )  # add hadamard gate
  quantum_circuit.cx(
      1       ,			2     )  # add control gate with qubit 1 as control and 2 as target.
  quantum_circuit.cx(0       ,			1     )
  quantum_circuit.h(0     )
  quantum_circuit.cz(0       ,			2     )  # add control z gate.
  quantum_circuit.cx(1       ,			2     )

  quantum_circuit.measure([2]       ,			[0]     )  # measure the qubit.

  # Simulate the circuit using qasm simulator
  SCREAMING_SNAKE_CASE_  :		List[str]    				=   Aer.get_backend("aer_simulator"     )
  SCREAMING_SNAKE_CASE_  :		Any    				=   execute(lowerCAmelCase       ,			lowerCAmelCase       ,			shots=1_0_0_0     )

  return job.result().get_counts(lowerCAmelCase     )


if __name__ == "__main__":
  print(
      '''Total count for teleported state is: '''
      f'''{quantum_teleportation(np.pi/2, np.pi/2, np.pi/2)}'''
  )

import gc
import tempfile
import unittest

import numpy as np
import torch

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


__lowerCamelCase :     List[Any]          =  False






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

					def     __UpperCamelCase       (   self				:	Optional[int]   ):







							"""simple docstring"""






							super().tearDown()
							gc.collect()
							torch.cuda.empty_cache()

					def     __UpperCamelCase       (   self				:	Optional[Any]   ):







							"""simple docstring"""






							SCREAMING_SNAKE_CASE_  :		int    				=   VersatileDiffusionDualGuidedPipeline.from_pretrained("shi-labs/versatile-diffusion"   )
							# remove text_unet
							pipe.remove_unused_weights()
							pipe.to(_A   )
							pipe.set_progress_bar_config(disable=_A   )

							SCREAMING_SNAKE_CASE_  :		Optional[int]    				=   load_image(
							    "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/versatile_diffusion/benz.jpg"   )

							SCREAMING_SNAKE_CASE_  :		Optional[Any]    				=   torch.manual_seed(0   )
							SCREAMING_SNAKE_CASE_  :		int    				=   pipe(
							    prompt="first prompt",image=_A,text_to_image_strength=0.75,generator=_A,guidance_scale=7.5,num_inference_steps=2,output_type="numpy",).images

							with tempfile.TemporaryDirectory() as tmpdirname:
									pipe.save_pretrained(_A   )
									SCREAMING_SNAKE_CASE_  :		Dict    				=   VersatileDiffusionDualGuidedPipeline.from_pretrained(_A   )

							pipe.to(_A   )
							pipe.set_progress_bar_config(disable=_A   )

							SCREAMING_SNAKE_CASE_  :		List[str]    				=   generator.manual_seed(0   )
							SCREAMING_SNAKE_CASE_  :		str    				=   pipe(
							    prompt="first prompt",image=_A,text_to_image_strength=0.75,generator=_A,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				:	Any   ):







							"""simple docstring"""






							SCREAMING_SNAKE_CASE_  :		Any    				=   VersatileDiffusionDualGuidedPipeline.from_pretrained("shi-labs/versatile-diffusion"   )
							pipe.remove_unused_weights()
							pipe.to(_A   )
							pipe.set_progress_bar_config(disable=_A   )

							SCREAMING_SNAKE_CASE_  :		Union[str, Any]    				=   "cyberpunk 2077"
							SCREAMING_SNAKE_CASE_  :		Dict    				=   load_image(
							    "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/versatile_diffusion/benz.jpg"   )
							SCREAMING_SNAKE_CASE_  :		Tuple    				=   torch.manual_seed(0   )
							SCREAMING_SNAKE_CASE_  :		Dict    				=   pipe(
							    prompt=_A,image=_A,text_to_image_strength=0.75,generator=_A,guidance_scale=7.5,num_inference_steps=50,output_type="numpy",).images

							SCREAMING_SNAKE_CASE_  :		Optional[int]    				=   image[0, 253:256, 253:256, -1]

							assert image.shape == (1, 512, 512, 3)
							SCREAMING_SNAKE_CASE_  :		Optional[Any]    				=   np.array([0.0787, 0.0849, 0.0826, 0.0812, 0.0807, 0.0795, 0.0818, 0.0798, 0.0779]   )

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