
'''simple docstring'''







import gc
import unittest

import numpy as np
import torch

from diffusers import DanceDiffusionPipeline, IPNDMScheduler, UNetaDModel
from diffusers.utils import slow, torch_device
from diffusers.utils.testing_utils import enable_full_determinism, require_torch_gpu, skip_mps

from ..pipeline_params import UNCONDITIONAL_AUDIO_GENERATION_BATCH_PARAMS, UNCONDITIONAL_AUDIO_GENERATION_PARAMS
from ..test_pipelines_common import PipelineTesterMixin


enable_full_determinism()






class 			lowerCAmelCase__       (  lowerCamelCase_   ,						unittest.TestCase					):
					lowerCAmelCase_					       =					DanceDiffusionPipeline
					lowerCAmelCase_					       =					UNCONDITIONAL_AUDIO_GENERATION_PARAMS
					lowerCAmelCase_					       =					PipelineTesterMixin.required_optional_params - {
					    '''callback''',
					    '''latents''',
					    '''callback_steps''',
					    '''output_type''',
					    '''num_images_per_prompt''',
					}
					lowerCAmelCase_					       =					UNCONDITIONAL_AUDIO_GENERATION_BATCH_PARAMS
					lowerCAmelCase_					       =					False
					lowerCAmelCase_					       =					False






					def      _snake_case   (       self		):


											"""simple docstring"""





											torch.manual_seed(0		)
											lowercase_     :					str													=	UNetaDModel(
											    block_out_channels=(32, 32, 64)    ,							extra_in_channels=16    ,							sample_size=5_12    ,							sample_rate=1_60_00    ,							in_channels=2    ,							out_channels=2    ,							flip_sin_to_cos=__SCREAMING_SNAKE_CASE    ,							use_timestep_embedding=__SCREAMING_SNAKE_CASE    ,							time_embedding_type='''fourier'''    ,							mid_block_type='''UNetMidBlock1D'''    ,							down_block_types=('''DownBlock1DNoSkip''', '''DownBlock1D''', '''AttnDownBlock1D''')    ,							up_block_types=('''AttnUpBlock1D''', '''UpBlock1D''', '''UpBlock1DNoSkip''')    ,							)
											lowercase_     :					Any													=	IPNDMScheduler()

											lowercase_     :					Tuple													=	{
											    '''unet''': unet,
											    '''scheduler''': scheduler,
											}
											return components






					def      _snake_case   (       self    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE=0		):


											"""simple docstring"""





											if str(__SCREAMING_SNAKE_CASE		).startswith('''mps'''		):
																	lowercase_     :					Any													=	torch.manual_seed(__SCREAMING_SNAKE_CASE		)
											else:
																	lowercase_     :					str													=	torch.Generator(device=__SCREAMING_SNAKE_CASE		).manual_seed(__SCREAMING_SNAKE_CASE		)
											lowercase_     :					Dict													=	{
											    '''batch_size''': 1,
											    '''generator''': generator,
											    '''num_inference_steps''': 4,
											}
											return inputs






					def      _snake_case   (       self		):


											"""simple docstring"""





											lowercase_     :					int													=	'''cpu'''  # ensure determinism for the device-dependent torch.Generator
											lowercase_     :					Optional[Any]													=	self.get_dummy_components()
											lowercase_     :					Optional[int]													=	DanceDiffusionPipeline(**__SCREAMING_SNAKE_CASE		)
											lowercase_     :					int													=	pipe.to(__SCREAMING_SNAKE_CASE		)
											pipe.set_progress_bar_config(disable=__SCREAMING_SNAKE_CASE		)

											lowercase_     :					str													=	self.get_dummy_inputs(__SCREAMING_SNAKE_CASE		)
											lowercase_     :					Dict													=	pipe(**__SCREAMING_SNAKE_CASE		)
											lowercase_     :					Optional[Any]													=	output.audios

											lowercase_     :					int													=	audio[0, -3:, -3:]

											assert audio.shape == (1, 2, components["unet"].sample_size)
											lowercase_     :					Union[str, Any]													=	np.array([-0.7_265, 1.0_000, -0.8_388, 0.1_175, 0.9_498, -1.0_000]		)
											assert np.abs(audio_slice.flatten() - expected_slice		).max() < 1E-2






					@skip_mps
					def      _snake_case   (       self		):


											"""simple docstring"""





											return super().test_save_load_local()






					@skip_mps
					def      _snake_case   (       self		):


											"""simple docstring"""





											return super().test_dict_tuple_outputs_equivalent(expected_max_difference=3E-3		)






					@skip_mps
					def      _snake_case   (       self		):


											"""simple docstring"""





											return super().test_save_load_optional_components()






					@skip_mps
					def      _snake_case   (       self		):


											"""simple docstring"""





											return super().test_attention_slicing_forward_pass()






					def      _snake_case   (       self		):


											"""simple docstring"""





											super().test_inference_batch_single_identical(expected_max_diff=3E-3		)







@slow
@require_torch_gpu
class 			lowerCAmelCase__       (  unittest.TestCase					):






					def      _snake_case   (       self		):


											"""simple docstring"""





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






					def      _snake_case   (       self		):


											"""simple docstring"""





											lowercase_     :					Optional[Any]													=	torch_device

											lowercase_     :					Optional[int]													=	DanceDiffusionPipeline.from_pretrained('''harmonai/maestro-150k'''		)
											lowercase_     :					int													=	pipe.to(__SCREAMING_SNAKE_CASE		)
											pipe.set_progress_bar_config(disable=__SCREAMING_SNAKE_CASE		)

											lowercase_     :					Union[str, Any]													=	torch.manual_seed(0		)
											lowercase_     :					Optional[int]													=	pipe(generator=__SCREAMING_SNAKE_CASE    ,							num_inference_steps=1_00    ,							audio_length_in_s=4.096		)
											lowercase_     :					List[str]													=	output.audios

											lowercase_     :					Optional[int]													=	audio[0, -3:, -3:]

											assert audio.shape == (1, 2, pipe.unet.sample_size)
											lowercase_     :					str													=	np.array([-0.0_192, -0.0_231, -0.0_318, -0.0_059, 0.0_002, -0.0_020]		)

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






					def      _snake_case   (       self		):


											"""simple docstring"""





											lowercase_     :					int													=	torch_device

											lowercase_     :					List[Any]													=	DanceDiffusionPipeline.from_pretrained('''harmonai/maestro-150k'''    ,							torch_dtype=torch.floataa		)
											lowercase_     :					Union[str, Any]													=	pipe.to(__SCREAMING_SNAKE_CASE		)
											pipe.set_progress_bar_config(disable=__SCREAMING_SNAKE_CASE		)

											lowercase_     :					str													=	torch.manual_seed(0		)
											lowercase_     :					Optional[Any]													=	pipe(generator=__SCREAMING_SNAKE_CASE    ,							num_inference_steps=1_00    ,							audio_length_in_s=4.096		)
											lowercase_     :					Any													=	output.audios

											lowercase_     :					Dict													=	audio[0, -3:, -3:]

											assert audio.shape == (1, 2, pipe.unet.sample_size)
											lowercase_     :					Dict													=	np.array([-0.0_367, -0.0_488, -0.0_771, -0.0_525, -0.0_444, -0.0_341]		)

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





'''simple docstring'''







import qiskit
def  snake_case_		(    __SCREAMING_SNAKE_CASE :			int				,				__SCREAMING_SNAKE_CASE :			int							):



						"""simple docstring"""





						lowercase_     :					List[Any]													=	qiskit.Aer.get_backend('''aer_simulator'''							)

						# Create a Quantum Circuit acting on the q register
						lowercase_     :					Dict													=	qiskit.QuantumCircuit(__SCREAMING_SNAKE_CASE				,				__SCREAMING_SNAKE_CASE							)

						# Map the quantum measurement to the classical bits
						circuit.measure([0]				,				[0]							)

						# Execute the circuit on the simulator
						lowercase_     :					Union[str, Any]													=	qiskit.execute(__SCREAMING_SNAKE_CASE				,				__SCREAMING_SNAKE_CASE				,				shots=1000							)

						# Return the histogram data of the results of the experiment.
						return job.result().get_counts(__SCREAMING_SNAKE_CASE							)


if __name__ == "__main__":
							print(f"""Total count for various states are: {single_qubit_measure(1, 1)}""")



