'''simple docstring'''




import unittest

import torch

from diffusers import UNetaDModel
from diffusers.utils import floats_tensor, slow, torch_device

from .test_modeling_common import ModelTesterMixin, UNetTesterMixin





class        SCREAMING_SNAKE_CASE   (				__a	,						__a	,						unittest.TestCase ):
		"""simple docstring"""







		__A     =		UNetaDModel
		__A     =		"sample"



		@property
		def   a   (  self   :					Tuple					):


								"""simple docstring"""



								_lowerCAmelCase		   =   4
								_lowerCAmelCase		   =   14
								_lowerCAmelCase		   =   16

								_lowerCAmelCase		   =   floats_tensor((batch_size, num_features, seq_len)					).to(__lowerCAmelCase					)
								_lowerCAmelCase		   =   torch.tensor([10] * batch_size					).to(__lowerCAmelCase					)

								return {"sample": noise, "timestep": time_step}



		@property
		def   a   (  self   :					Optional[int]					):


								"""simple docstring"""



								return (4, 14, 16)



		@property
		def   a   (  self   :					Optional[int]					):


								"""simple docstring"""



								return (4, 14, 16)



		def   a   (  self   :					str					):


								"""simple docstring"""



								pass



		def   a   (  self   :					str					):


								"""simple docstring"""



								pass



		@unittest.skipIf(torch_device == 'mps'					,					'mish op not supported in MPS'					)
		def   a   (  self   :					Optional[int]					):


								"""simple docstring"""



								super().test_determinism()



		@unittest.skipIf(torch_device == 'mps'					,					'mish op not supported in MPS'					)
		def   a   (  self   :					List[Any]					):


								"""simple docstring"""



								super().test_outputs_equivalence()



		@unittest.skipIf(torch_device == 'mps'					,					'mish op not supported in MPS'					)
		def   a   (  self   :					Union[str, Any]					):


								"""simple docstring"""



								super().test_from_save_pretrained()



		@unittest.skipIf(torch_device == 'mps'					,					'mish op not supported in MPS'					)
		def   a   (  self   :					List[Any]					):


								"""simple docstring"""



								super().test_from_save_pretrained_variant()



		@unittest.skipIf(torch_device == 'mps'					,					'mish op not supported in MPS'					)
		def   a   (  self   :					Any					):


								"""simple docstring"""



								super().test_model_from_pretrained()



		@unittest.skipIf(torch_device == 'mps'					,					'mish op not supported in MPS'					)
		def   a   (  self   :					Dict					):


								"""simple docstring"""



								super().test_output()



		def   a   (  self   :					int					):


								"""simple docstring"""



								_lowerCAmelCase		   =   {
								    'block_out_channels': (32, 64, 128, 256),
								    'in_channels': 14,
								    'out_channels': 14,
								    'time_embedding_type': 'positional',
								    'use_timestep_embedding': True,
								    'flip_sin_to_cos': False,
								    'freq_shift': 1.0,
								    'out_block_type': 'OutConv1DBlock',
								    'mid_block_type': 'MidResTemporalBlock1D',
								    'down_block_types': ('DownResnetBlock1D', 'DownResnetBlock1D', 'DownResnetBlock1D', 'DownResnetBlock1D'),
								    'up_block_types': ('UpResnetBlock1D', 'UpResnetBlock1D', 'UpResnetBlock1D'),
								    'act_fn': 'mish',
								}
								_lowerCAmelCase		   =   self.dummy_input
								return init_dict, inputs_dict



		@unittest.skipIf(torch_device == 'mps'					,					'mish op not supported in MPS'					)
		def   a   (  self   :					List[Any]					):


								"""simple docstring"""



								_lowerCAmelCase   ,  _lowerCAmelCase		   =   UNetaDModel.from_pretrained(
								    'bglick13/hopper-medium-v2-value-function-hor32'					,					output_loading_info=__lowerCAmelCase					,					subfolder='unet'					)
								self.assertIsNotNone(__lowerCAmelCase					)
								self.assertEqual(len(loading_info['missing_keys']					)					,					0					)

								model.to(__lowerCAmelCase					)
								_lowerCAmelCase		   =   model(**self.dummy_input					)

								assert image is not None, "Make sure output is not None"



		@unittest.skipIf(torch_device == 'mps'					,					'mish op not supported in MPS'					)
		def   a   (  self   :					str					):


								"""simple docstring"""



								_lowerCAmelCase		   =   UNetaDModel.from_pretrained('bglick13/hopper-medium-v2-value-function-hor32'					,					subfolder='unet'					)
								torch.manual_seed(0					)
								if torch.cuda.is_available():
														torch.cuda.manual_seed_all(0					)

								_lowerCAmelCase		   =   model.config.in_channels
								_lowerCAmelCase		   =   16
								_lowerCAmelCase		   =   torch.randn((1, seq_len, num_features)					).permute(
								    0					,					2					,					1					)  # match original, we can update values and remove
								_lowerCAmelCase		   =   torch.full((num_features,)					,					0					)

								with torch.no_grad():
														_lowerCAmelCase		   =   model(__lowerCAmelCase					,					__lowerCAmelCase					).sample.permute(0					,					2					,					1					)

								_lowerCAmelCase		   =   output[0, -3:, -3:].flatten()
								# fmt: off
								_lowerCAmelCase		   =   torch.tensor([-2.1_3_7_1_7_2, 1.1_4_2_6_0_1_6, 0.3_6_8_8_6_8_7, -0.7_6_6_9_2_2, 0.7_3_0_3_1_4_6, 0.1_1_0_3_8_8_6_4, -0.4_7_6_0_6_3_3, 0.1_3_2_7_0_1_7_2, 0.0_2_5_9_1_3_4_8]					)
								# fmt: on
								self.assertTrue(torch.allclose(__lowerCAmelCase					,					__lowerCAmelCase					,					rtol=1e-3					)					)



		def   a   (  self   :					str					):


								"""simple docstring"""



								pass



		@slow
		def   a   (  self   :					Dict					):


								"""simple docstring"""



								_lowerCAmelCase		   =   'harmonai/maestro-150k'
								_lowerCAmelCase		   =   UNetaDModel.from_pretrained(__lowerCAmelCase					,					subfolder='unet'					)
								model.to(__lowerCAmelCase					)

								_lowerCAmelCase		   =   6_5536
								_lowerCAmelCase		   =   torch.sin(torch.arange(__lowerCAmelCase					)[None, None, :].repeat(1					,					2					,					1					)					).to(__lowerCAmelCase					)
								_lowerCAmelCase		   =   torch.tensor([1]					).to(__lowerCAmelCase					)

								with torch.no_grad():
														_lowerCAmelCase		   =   model(__lowerCAmelCase					,					__lowerCAmelCase					).sample

								_lowerCAmelCase		   =   output.abs().sum()
								_lowerCAmelCase		   =   output.abs().max()

								assert (output_sum - 224.0896).abs() < 0.5
								assert (output_max - 0.0_6_0_7).abs() < 4e-4





class        SCREAMING_SNAKE_CASE   (				__a	,						__a	,						unittest.TestCase ):
		"""simple docstring"""







		__A     =		UNetaDModel
		__A     =		"sample"



		@property
		def   a   (  self   :					Dict					):


								"""simple docstring"""



								_lowerCAmelCase		   =   4
								_lowerCAmelCase		   =   14
								_lowerCAmelCase		   =   16

								_lowerCAmelCase		   =   floats_tensor((batch_size, num_features, seq_len)					).to(__lowerCAmelCase					)
								_lowerCAmelCase		   =   torch.tensor([10] * batch_size					).to(__lowerCAmelCase					)

								return {"sample": noise, "timestep": time_step}



		@property
		def   a   (  self   :					Any					):


								"""simple docstring"""



								return (4, 14, 16)



		@property
		def   a   (  self   :					Optional[int]					):


								"""simple docstring"""



								return (4, 14, 1)



		@unittest.skipIf(torch_device == 'mps'					,					'mish op not supported in MPS'					)
		def   a   (  self   :					Dict					):


								"""simple docstring"""



								super().test_determinism()



		@unittest.skipIf(torch_device == 'mps'					,					'mish op not supported in MPS'					)
		def   a   (  self   :					int					):


								"""simple docstring"""



								super().test_outputs_equivalence()



		@unittest.skipIf(torch_device == 'mps'					,					'mish op not supported in MPS'					)
		def   a   (  self   :					Dict					):


								"""simple docstring"""



								super().test_from_save_pretrained()



		@unittest.skipIf(torch_device == 'mps'					,					'mish op not supported in MPS'					)
		def   a   (  self   :					Any					):


								"""simple docstring"""



								super().test_from_save_pretrained_variant()



		@unittest.skipIf(torch_device == 'mps'					,					'mish op not supported in MPS'					)
		def   a   (  self   :					Optional[int]					):


								"""simple docstring"""



								super().test_model_from_pretrained()



		@unittest.skipIf(torch_device == 'mps'					,					'mish op not supported in MPS'					)
		def   a   (  self   :					Any					):


								"""simple docstring"""



								_lowerCAmelCase   ,  _lowerCAmelCase		   =   self.prepare_init_args_and_inputs_for_common()
								_lowerCAmelCase		   =   self.model_class(**__lowerCAmelCase					)
								model.to(__lowerCAmelCase					)
								model.eval()

								with torch.no_grad():
														_lowerCAmelCase		   =   model(**__lowerCAmelCase					)

														if isinstance(__lowerCAmelCase					,					__lowerCAmelCase					):
																				_lowerCAmelCase		   =   output.sample

								self.assertIsNotNone(__lowerCAmelCase					)
								_lowerCAmelCase		   =   torch.Size((inputs_dict['sample'].shape[0], 1)					)
								self.assertEqual(output.shape					,					__lowerCAmelCase					,					'Input and output shapes do not match'					)



		def   a   (  self   :					Optional[Any]					):


								"""simple docstring"""



								pass



		def   a   (  self   :					Union[str, Any]					):


								"""simple docstring"""



								pass



		def   a   (  self   :					Union[str, Any]					):


								"""simple docstring"""



								_lowerCAmelCase		   =   {
								    'in_channels': 14,
								    'out_channels': 14,
								    'down_block_types': ['DownResnetBlock1D', 'DownResnetBlock1D', 'DownResnetBlock1D', 'DownResnetBlock1D'],
								    'up_block_types': [],
								    'out_block_type': 'ValueFunction',
								    'mid_block_type': 'ValueFunctionMidBlock1D',
								    'block_out_channels': [32, 64, 128, 256],
								    'layers_per_block': 1,
								    'downsample_each_block': True,
								    'use_timestep_embedding': True,
								    'freq_shift': 1.0,
								    'flip_sin_to_cos': False,
								    'time_embedding_type': 'positional',
								    'act_fn': 'mish',
								}
								_lowerCAmelCase		   =   self.dummy_input
								return init_dict, inputs_dict



		@unittest.skipIf(torch_device == 'mps'					,					'mish op not supported in MPS'					)
		def   a   (  self   :					List[str]					):


								"""simple docstring"""



								_lowerCAmelCase   ,  _lowerCAmelCase		   =   UNetaDModel.from_pretrained(
								    'bglick13/hopper-medium-v2-value-function-hor32'					,					output_loading_info=__lowerCAmelCase					,					subfolder='value_function'					)
								self.assertIsNotNone(__lowerCAmelCase					)
								self.assertEqual(len(vf_loading_info['missing_keys']					)					,					0					)

								value_function.to(__lowerCAmelCase					)
								_lowerCAmelCase		   =   value_function(**self.dummy_input					)

								assert image is not None, "Make sure output is not None"



		@unittest.skipIf(torch_device == 'mps'					,					'mish op not supported in MPS'					)
		def   a   (  self   :					int					):


								"""simple docstring"""



								_lowerCAmelCase   ,  _lowerCAmelCase		   =   UNetaDModel.from_pretrained(
								    'bglick13/hopper-medium-v2-value-function-hor32'					,					output_loading_info=__lowerCAmelCase					,					subfolder='value_function'					)
								torch.manual_seed(0					)
								if torch.cuda.is_available():
														torch.cuda.manual_seed_all(0					)

								_lowerCAmelCase		   =   value_function.config.in_channels
								_lowerCAmelCase		   =   14
								_lowerCAmelCase		   =   torch.randn((1, seq_len, num_features)					).permute(
								    0					,					2					,					1					)  # match original, we can update values and remove
								_lowerCAmelCase		   =   torch.full((num_features,)					,					0					)

								with torch.no_grad():
														_lowerCAmelCase		   =   value_function(__lowerCAmelCase					,					__lowerCAmelCase					).sample

								# fmt: off
								_lowerCAmelCase		   =   torch.tensor([165.25] * seq_len					)
								# fmt: on
								self.assertTrue(torch.allclose(__lowerCAmelCase					,					__lowerCAmelCase					,					rtol=1e-3					)					)



		def   a   (  self   :					List[Any]					):


								"""simple docstring"""



								pass






'''simple docstring'''




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







def 			A_   ( _lowerCamelCase			:							float = np.pi / 2  ,  _lowerCamelCase			:							float = np.pi / 2  ,  _lowerCamelCase			:							float = np.pi / 2    ):
      _lowerCAmelCase		   =   QuantumRegister(3  ,  'qr'    )  # Define the number of quantum bits
      _lowerCAmelCase		   =   ClassicalRegister(1  ,  'cr'    )  # Define the number of classical bits

      _lowerCAmelCase		   =   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
      _lowerCAmelCase		   =   Aer.get_backend('aer_simulator'    )
      _lowerCAmelCase		   =   execute(_lowerCamelCase  ,  _lowerCamelCase  ,  shots=1_000    )

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





