
'''simple docstring'''







import unittest

import torch

from diffusers import DDIMScheduler, DDPMScheduler, UNetaDModel
from diffusers.training_utils import set_seed
from diffusers.utils.testing_utils import slow


_lowercase			:  Dict   							=	False






class 			lowerCAmelCase__       (  unittest.TestCase					):






					def      _snake_case   (       self    ,							__SCREAMING_SNAKE_CASE=32		):


											"""simple docstring"""





											set_seed(0		)
											lowercase_     :					List[str]													=	UNetaDModel(sample_size=lowerCamelCase_    ,							in_channels=3    ,							out_channels=3		)
											lowercase_     :					Dict													=	torch.optim.SGD(model.parameters()    ,							lr=0.0_001		)
											return model, optimizer






					@slow
					def      _snake_case   (       self		):


											"""simple docstring"""





											lowercase_     :					Union[str, Any]													=	'''cpu'''  # ensure full determinism without setting the CUBLAS_WORKSPACE_CONFIG env variable
											lowercase_     :					List[Any]													=	DDPMScheduler(
											    num_train_timesteps=10_00    ,							beta_start=0.0_001    ,							beta_end=0.02    ,							beta_schedule='''linear'''    ,							clip_sample=lowerCamelCase_    ,							)
											lowercase_     :					Any													=	DDIMScheduler(
											    num_train_timesteps=10_00    ,							beta_start=0.0_001    ,							beta_end=0.02    ,							beta_schedule='''linear'''    ,							clip_sample=lowerCamelCase_    ,							)

											assert ddpm_scheduler.config.num_train_timesteps == ddim_scheduler.config.num_train_timesteps

											# shared batches for DDPM and DDIM
											set_seed(0		)
											lowercase_     :					Dict													=	[torch.randn((4, 3, 32, 32)		).clip(-1    ,							1		).to(lowerCamelCase_		) for _ in range(4		)]
											lowercase_     :					Union[str, Any]													=	[torch.randn((4, 3, 32, 32)		).to(lowerCamelCase_		) for _ in range(4		)]
											lowercase_     :					List[Any]													=	[torch.randint(0    ,							10_00    ,							(4,)		).long().to(lowerCamelCase_		) for _ in range(4		)]

											# train with a DDPM scheduler
											lowercase_						,			lowercase_     :					Tuple													=	self.get_model_optimizer(resolution=32		)
											model.train().to(lowerCamelCase_		)
											for i in range(4		):
																	optimizer.zero_grad()
																	lowercase_     :					List[str]													=	ddpm_scheduler.add_noise(clean_images[i]    ,							noise[i]    ,							timesteps[i]		)
																	lowercase_     :					Optional[int]													=	model(lowerCamelCase_    ,							timesteps[i]		).sample
																	lowercase_     :					Union[str, Any]													=	torch.nn.functional.mse_loss(lowerCamelCase_    ,							noise[i]		)
																	loss.backward()
																	optimizer.step()
											del model, optimizer

											# recreate the model and optimizer, and retry with DDIM
											lowercase_						,			lowercase_     :					List[Any]													=	self.get_model_optimizer(resolution=32		)
											model.train().to(lowerCamelCase_		)
											for i in range(4		):
																	optimizer.zero_grad()
																	lowercase_     :					str													=	ddim_scheduler.add_noise(clean_images[i]    ,							noise[i]    ,							timesteps[i]		)
																	lowercase_     :					Dict													=	model(lowerCamelCase_    ,							timesteps[i]		).sample
																	lowercase_     :					Dict													=	torch.nn.functional.mse_loss(lowerCamelCase_    ,							noise[i]		)
																	loss.backward()
																	optimizer.step()
											del model, optimizer

											self.assertTrue(torch.allclose(lowerCamelCase_    ,							lowerCamelCase_    ,							atol=1E-5		)		)
											self.assertTrue(torch.allclose(lowerCamelCase_    ,							lowerCamelCase_    ,							atol=1E-5		)		)





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



