





"""simple docstring"""




import torch

from diffusers import KDPMaDiscreteScheduler
from diffusers.utils import torch_device

from .test_schedulers import SchedulerCommonTest


class  __UpperCamelCase       (		a__		):
							lowerCamelCase     :      Tuple         =(KDPMaDiscreteScheduler,)
							lowerCamelCase     :      Any         =10






							def 					__a     (     self   ,      **lowerCAmelCase__   )			->				Optional[Any]:
								a   :	Optional[Any]			=       {
								    "num_train_timesteps": 1100,
								    "beta_start": 0.0_001,
								    "beta_end": 0.02,
								    "beta_schedule": "linear",
								}

								config.update(**lowerCAmelCase__   )
								return config






							def 					__a     (     self   )			->				Optional[int]:
								for timesteps in [10, 50, 100, 1000]:
									self.check_over_configs(num_train_timesteps=lowerCAmelCase__   )






							def 					__a     (     self   )			->				Optional[Any]:
								for beta_start, beta_end in zip([0.00_001, 0.0_001, 0.001]   ,      [0.0_002, 0.002, 0.02]   ):
									self.check_over_configs(beta_start=lowerCAmelCase__   ,      beta_end=lowerCAmelCase__   )






							def 					__a     (     self   )			->				Dict:
								for schedule in ["linear", "scaled_linear"]:
									self.check_over_configs(beta_schedule=lowerCAmelCase__   )






							def 					__a     (     self   )			->				List[Any]:
								for prediction_type in ["epsilon", "v_prediction"]:
									self.check_over_configs(prediction_type=lowerCAmelCase__   )






							def 					__a     (     self   )			->				Dict:
								a   :	Optional[Any]			=       self.scheduler_classes[0]
								a   :	Dict			=       self.get_scheduler_config(prediction_type="v_prediction"   )
								a   :	Dict			=       scheduler_class(**lowerCAmelCase__   )

								scheduler.set_timesteps(self.num_inference_steps   )

								a   :	List[str]			=       self.dummy_model()
								a   :	Dict			=       self.dummy_sample_deter * scheduler.init_noise_sigma
								a   :	Dict			=       sample.to(lowerCAmelCase__   )

								for i, t in enumerate(scheduler.timesteps   ):
									a   :	List[str]			=       scheduler.scale_model_input(lowerCAmelCase__   ,      lowerCAmelCase__   )

									a   :	List[str]			=       model(lowerCAmelCase__   ,      lowerCAmelCase__   )

									a   :	List[str]			=       scheduler.step(lowerCAmelCase__   ,      lowerCAmelCase__   ,      lowerCAmelCase__   )
									a   :	Optional[Any]			=       output.prev_sample

								a   :	Tuple			=       torch.sum(torch.abs(lowerCAmelCase__   )   )
								a   :	List[Any]			=       torch.mean(torch.abs(lowerCAmelCase__   )   )

								if torch_device in ["cpu", "mps"]:
									assert abs(result_sum.item() - 4.6_934E-07   ) < 1E-2
									assert abs(result_mean.item() - 6.1_112E-10   ) < 1E-3
								else:
									# CUDA
									assert abs(result_sum.item() - 4.693_428_650_170_972E-07   ) < 1E-2
									assert abs(result_mean.item() - 0.0_002   ) < 1E-3






							def 					__a     (     self   )			->				Tuple:
								if torch_device == "mps":
									return
								a   :	str			=       self.scheduler_classes[0]
								a   :	str			=       self.get_scheduler_config()
								a   :	Dict			=       scheduler_class(**lowerCAmelCase__   )

								scheduler.set_timesteps(self.num_inference_steps   )

								a   :	Dict			=       self.dummy_model()
								a   :	List[Any]			=       self.dummy_sample_deter * scheduler.init_noise_sigma
								a   :	Tuple			=       sample.to(lowerCAmelCase__   )

								for i, t in enumerate(scheduler.timesteps   ):
									a   :	List[str]			=       scheduler.scale_model_input(lowerCAmelCase__   ,      lowerCAmelCase__   )

									a   :	Union[str, Any]			=       model(lowerCAmelCase__   ,      lowerCAmelCase__   )

									a   :	List[Any]			=       scheduler.step(lowerCAmelCase__   ,      lowerCAmelCase__   ,      lowerCAmelCase__   )
									a   :	int			=       output.prev_sample

								a   :	List[str]			=       torch.sum(torch.abs(lowerCAmelCase__   )   )
								a   :	List[str]			=       torch.mean(torch.abs(lowerCAmelCase__   )   )

								if torch_device in ["cpu", "mps"]:
									assert abs(result_sum.item() - 20.4_125   ) < 1E-2
									assert abs(result_mean.item() - 0.0_266   ) < 1E-3
								else:
									# CUDA
									assert abs(result_sum.item() - 20.4_125   ) < 1E-2
									assert abs(result_mean.item() - 0.0_266   ) < 1E-3






							def 					__a     (     self   )			->				Dict:
								if torch_device == "mps":
									return
								a   :	Any			=       self.scheduler_classes[0]
								a   :	Tuple			=       self.get_scheduler_config()
								a   :	List[Any]			=       scheduler_class(**lowerCAmelCase__   )

								scheduler.set_timesteps(self.num_inference_steps   ,      device=lowerCAmelCase__   )

								a   :	Optional[Any]			=       self.dummy_model()
								a   :	int			=       self.dummy_sample_deter.to(lowerCAmelCase__   ) * scheduler.init_noise_sigma

								for t in scheduler.timesteps:
									a   :	str			=       scheduler.scale_model_input(lowerCAmelCase__   ,      lowerCAmelCase__   )

									a   :	Optional[int]			=       model(lowerCAmelCase__   ,      lowerCAmelCase__   )

									a   :	List[str]			=       scheduler.step(lowerCAmelCase__   ,      lowerCAmelCase__   ,      lowerCAmelCase__   )
									a   :	Dict			=       output.prev_sample

								a   :	Dict			=       torch.sum(torch.abs(lowerCAmelCase__   )   )
								a   :	List[str]			=       torch.mean(torch.abs(lowerCAmelCase__   )   )

								if str(lowerCAmelCase__   ).startswith("cpu"   ):
									# The following sum varies between 148 and 156 on mps. Why?
									assert abs(result_sum.item() - 20.4_125   ) < 1E-2
									assert abs(result_mean.item() - 0.0_266   ) < 1E-3
								else:
									# CUDA
									assert abs(result_sum.item() - 20.4_125   ) < 1E-2
									assert abs(result_mean.item() - 0.0_266   ) < 1E-3









"""simple docstring"""




import qiskit






def    _SCREAMING_SNAKE_CASE	(			_lowercase		:					int					, _lowercase		:					int      )				->qiskit.result.counts.Counts:






	'''simple docstring'''






	a   :	Union[str, Any]			=       qiskit.Aer.get_backend("aer_simulator"      )

	# Create a Quantum Circuit acting on the q register
	a   :	Optional[Any]			=       qiskit.QuantumCircuit(_lowercase					, _lowercase      )

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

	# Execute the circuit on the simulator
	a   :	Optional[int]			=       qiskit.execute(_lowercase					, _lowercase					, shots=1000      )

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


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


