


"""simple docstring"""


import torch

from diffusers import EulerDiscreteScheduler
from diffusers.utils import torch_device

from .test_schedulers import SchedulerCommonTest






class  lowercase(					__a			):







 '''simple docstring'''





 lowercase__			 = (EulerDiscreteScheduler,)
 lowercase__			 = 10


 def 			UpperCamelCase_       (    self:		str,				**a_:		List[Any]		):




   '''simple docstring'''



   _snake_case							:		int								=  {
       """num_train_timesteps""": 1_100,
       """beta_start""": 0.0_001,
       """beta_end""": 0.02,
       """beta_schedule""": """linear""",
   }

   config.update(**a_		)
   return config


 def 			UpperCamelCase_       (    self:		Optional[int]		):




   '''simple docstring'''



   for timesteps in [10, 50, 100, 1_000]:
     self.check_over_configs(num_train_timesteps=a_		)


 def 			UpperCamelCase_       (    self:		str		):




   '''simple docstring'''



   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=a_,				beta_end=a_		)


 def 			UpperCamelCase_       (    self:		Optional[Any]		):




   '''simple docstring'''



   for schedule in ["linear", "scaled_linear"]:
     self.check_over_configs(beta_schedule=a_		)


 def 			UpperCamelCase_       (    self:		Tuple		):




   '''simple docstring'''



   for prediction_type in ["epsilon", "v_prediction"]:
     self.check_over_configs(prediction_type=a_		)


 def 			UpperCamelCase_       (    self:		str		):




   '''simple docstring'''



   _snake_case							:		str								=  self.scheduler_classes[0]
   _snake_case							:		Optional[Any]								=  self.get_scheduler_config()
   _snake_case							:		Optional[Any]								=  scheduler_class(**a_		)

   scheduler.set_timesteps(self.num_inference_steps		)

   _snake_case							:		str								=  torch.manual_seed(0		)

   _snake_case							:		Optional[Any]								=  self.dummy_model()
   _snake_case							:		Optional[int]								=  self.dummy_sample_deter * scheduler.init_noise_sigma
   _snake_case							:		List[Any]								=  sample.to(a_		)

   for i, t in enumerate(scheduler.timesteps		):
     _snake_case							:		Tuple								=  scheduler.scale_model_input(a_,				a_		)

     _snake_case							:		int								=  model(a_,				a_		)

     _snake_case							:		str								=  scheduler.step(a_,				a_,				a_,				generator=a_		)
     _snake_case							:		Dict								=  output.prev_sample

   _snake_case							:		Tuple								=  torch.sum(torch.abs(a_		)		)
   _snake_case							:		str								=  torch.mean(torch.abs(a_		)		)

   assert abs(result_sum.item() - 10.0_807		) < 1E-2
   assert abs(result_mean.item() - 0.0_131		) < 1E-3


 def 			UpperCamelCase_       (    self:		Optional[int]		):




   '''simple docstring'''



   _snake_case							:		Union[str, Any]								=  self.scheduler_classes[0]
   _snake_case							:		int								=  self.get_scheduler_config(prediction_type="""v_prediction"""		)
   _snake_case							:		Any								=  scheduler_class(**a_		)

   scheduler.set_timesteps(self.num_inference_steps		)

   _snake_case							:		List[Any]								=  torch.manual_seed(0		)

   _snake_case							:		List[Any]								=  self.dummy_model()
   _snake_case							:		Any								=  self.dummy_sample_deter * scheduler.init_noise_sigma
   _snake_case							:		Any								=  sample.to(a_		)

   for i, t in enumerate(scheduler.timesteps		):
     _snake_case							:		Dict								=  scheduler.scale_model_input(a_,				a_		)

     _snake_case							:		List[Any]								=  model(a_,				a_		)

     _snake_case							:		Tuple								=  scheduler.step(a_,				a_,				a_,				generator=a_		)
     _snake_case							:		Any								=  output.prev_sample

   _snake_case							:		Any								=  torch.sum(torch.abs(a_		)		)
   _snake_case							:		str								=  torch.mean(torch.abs(a_		)		)

   assert abs(result_sum.item() - 0.0_002		) < 1E-2
   assert abs(result_mean.item() - 2.26_76E-06		) < 1E-3


 def 			UpperCamelCase_       (    self:		List[str]		):




   '''simple docstring'''



   _snake_case							:		Dict								=  self.scheduler_classes[0]
   _snake_case							:		Any								=  self.get_scheduler_config()
   _snake_case							:		Tuple								=  scheduler_class(**a_		)

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

   _snake_case							:		List[str]								=  torch.manual_seed(0		)

   _snake_case							:		Dict								=  self.dummy_model()
   _snake_case							:		List[str]								=  self.dummy_sample_deter * scheduler.init_noise_sigma.cpu()
   _snake_case							:		List[str]								=  sample.to(a_		)

   for t in scheduler.timesteps:
     _snake_case							:		Optional[int]								=  scheduler.scale_model_input(a_,				a_		)

     _snake_case							:		Union[str, Any]								=  model(a_,				a_		)

     _snake_case							:		Union[str, Any]								=  scheduler.step(a_,				a_,				a_,				generator=a_		)
     _snake_case							:		Any								=  output.prev_sample

   _snake_case							:		List[Any]								=  torch.sum(torch.abs(a_		)		)
   _snake_case							:		Optional[Any]								=  torch.mean(torch.abs(a_		)		)

   assert abs(result_sum.item() - 10.0_807		) < 1E-2
   assert abs(result_mean.item() - 0.0_131		) < 1E-3


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




   '''simple docstring'''



   _snake_case							:		str								=  self.scheduler_classes[0]
   _snake_case							:		List[str]								=  self.get_scheduler_config()
   _snake_case							:		Any								=  scheduler_class(**a_,				use_karras_sigmas=a_		)

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

   _snake_case							:		Any								=  torch.manual_seed(0		)

   _snake_case							:		str								=  self.dummy_model()
   _snake_case							:		List[str]								=  self.dummy_sample_deter * scheduler.init_noise_sigma.cpu()
   _snake_case							:		Any								=  sample.to(a_		)

   for t in scheduler.timesteps:
     _snake_case							:		Tuple								=  scheduler.scale_model_input(a_,				a_		)

     _snake_case							:		int								=  model(a_,				a_		)

     _snake_case							:		Optional[Any]								=  scheduler.step(a_,				a_,				a_,				generator=a_		)
     _snake_case							:		Dict								=  output.prev_sample

   _snake_case							:		Union[str, Any]								=  torch.sum(torch.abs(a_		)		)
   _snake_case							:		Tuple								=  torch.mean(torch.abs(a_		)		)

   assert abs(result_sum.item() - 124.52_299_499_511_719		) < 1E-2
   assert abs(result_mean.item() - 0.16_213_932_633_399_963		) < 1E-3








"""simple docstring"""


import math

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


def  UpperCAmelCase__	(snake_case__							: int = 3   ):
  """simple docstring"""

  if isinstance(snake_case__		,       snake_case__   ):
    raise TypeError("""number of qubits must be a integer."""   )
  if number_of_qubits <= 0:
    raise ValueError("""number of qubits must be > 0."""   )
  if math.floor(snake_case__   ) != number_of_qubits:
    raise ValueError("""number of qubits must be exact integer."""   )
  if number_of_qubits > 10:
    raise ValueError("""number of qubits too large to simulate(>10)."""   )

  _snake_case							:		Optional[int]								=  QuantumRegister(snake_case__		,       """qr"""   )
  _snake_case							:		List[Any]								=  ClassicalRegister(snake_case__		,       """cr"""   )

  _snake_case							:		Optional[int]								=  QuantumCircuit(snake_case__		,       snake_case__   )

  _snake_case							:		Dict								=  number_of_qubits

  for i in range(snake_case__   ):
    quantum_circuit.h(number_of_qubits - i - 1   )
    counter -= 1
    for j in range(snake_case__   ):
      quantum_circuit.cp(np.pi / 2 ** (counter - j)		,       snake_case__		,       snake_case__   )

  for k in range(number_of_qubits // 2   ):
    quantum_circuit.swap(snake_case__		,       number_of_qubits - k - 1   )

  # measure all the qubits
  quantum_circuit.measure(snake_case__		,       snake_case__   )
  # simulate with 10000 shots
  _snake_case							:		Optional[int]								=  Aer.get_backend("""qasm_simulator"""   )
  _snake_case							:		Optional[int]								=  execute(snake_case__		,       snake_case__		,       shots=1_00_00   )

  return job.result().get_counts(snake_case__   )


if __name__ == "__main__":
     print(
         F'''Total count for quantum fourier transform state is: \
    {quantum_fourier_transform(3)}'''
     )


