
"""simple docstring"""

import torch

from diffusers import EulerDiscreteScheduler
from diffusers.utils import torch_device

from .test_schedulers import SchedulerCommonTest
class      _UpperCAmelCase							(		SCREAMING_SNAKE_CASE_							):
						__SCREAMING_SNAKE_CASE   :							List[str]							      =	(EulerDiscreteScheduler,)
						__SCREAMING_SNAKE_CASE   :							Dict							      =	1_0




						def     a_      (							self   ,       **lowercase_							)						->					Tuple:
										UpperCAmelCase									=					{
										    'num_train_timesteps': 1_1_0_0,
										    'beta_start': 0.0_0_0_1,
										    'beta_end': 0.0_2,
										    'beta_schedule': 'linear',
										}

										config.update(**lowercase_							)
										return config




						def     a_      (							self							)						->					Optional[int]:
										for timesteps in [1_0, 5_0, 1_0_0, 1_0_0_0]:
														self.check_over_configs(num_train_timesteps=lowercase_							)




						def     a_      (							self							)						->					List[Any]:
										for beta_start, beta_end in zip([0.0_0_0_0_1, 0.0_0_0_1, 0.0_0_1]   ,       [0.0_0_0_2, 0.0_0_2, 0.0_2]							):
														self.check_over_configs(beta_start=lowercase_   ,       beta_end=lowercase_							)




						def     a_      (							self							)						->					Optional[Any]:
										for schedule in ["linear", "scaled_linear"]:
														self.check_over_configs(beta_schedule=lowercase_							)




						def     a_      (							self							)						->					Tuple:
										for prediction_type in ["epsilon", "v_prediction"]:
														self.check_over_configs(prediction_type=lowercase_							)




						def     a_      (							self							)						->					Optional[int]:
										UpperCAmelCase									=					self.scheduler_classes[0]
										UpperCAmelCase									=					self.get_scheduler_config()
										UpperCAmelCase									=					scheduler_class(**lowercase_							)

										scheduler.set_timesteps(self.num_inference_steps							)

										UpperCAmelCase									=					torch.manual_seed(0							)

										UpperCAmelCase									=					self.dummy_model()
										UpperCAmelCase									=					self.dummy_sample_deter * scheduler.init_noise_sigma
										UpperCAmelCase									=					sample.to(lowercase_							)

										for i, t in enumerate(scheduler.timesteps							):
														UpperCAmelCase									=					scheduler.scale_model_input(lowercase_   ,       lowercase_							)

														UpperCAmelCase									=					model(lowercase_   ,       lowercase_							)

														UpperCAmelCase									=					scheduler.step(lowercase_   ,       lowercase_   ,       lowercase_   ,       generator=lowercase_							)
														UpperCAmelCase									=					output.prev_sample

										UpperCAmelCase									=					torch.sum(torch.abs(lowercase_							)							)
										UpperCAmelCase									=					torch.mean(torch.abs(lowercase_							)							)

										assert abs(result_sum.item() - 1_0.0_8_0_7							) < 1E-2
										assert abs(result_mean.item() - 0.0_1_3_1							) < 1E-3




						def     a_      (							self							)						->					Tuple:
										UpperCAmelCase									=					self.scheduler_classes[0]
										UpperCAmelCase									=					self.get_scheduler_config(prediction_type='v_prediction'							)
										UpperCAmelCase									=					scheduler_class(**lowercase_							)

										scheduler.set_timesteps(self.num_inference_steps							)

										UpperCAmelCase									=					torch.manual_seed(0							)

										UpperCAmelCase									=					self.dummy_model()
										UpperCAmelCase									=					self.dummy_sample_deter * scheduler.init_noise_sigma
										UpperCAmelCase									=					sample.to(lowercase_							)

										for i, t in enumerate(scheduler.timesteps							):
														UpperCAmelCase									=					scheduler.scale_model_input(lowercase_   ,       lowercase_							)

														UpperCAmelCase									=					model(lowercase_   ,       lowercase_							)

														UpperCAmelCase									=					scheduler.step(lowercase_   ,       lowercase_   ,       lowercase_   ,       generator=lowercase_							)
														UpperCAmelCase									=					output.prev_sample

										UpperCAmelCase									=					torch.sum(torch.abs(lowercase_							)							)
										UpperCAmelCase									=					torch.mean(torch.abs(lowercase_							)							)

										assert abs(result_sum.item() - 0.0_0_0_2							) < 1E-2
										assert abs(result_mean.item() - 2.2676E-06							) < 1E-3




						def     a_      (							self							)						->					List[str]:
										UpperCAmelCase									=					self.scheduler_classes[0]
										UpperCAmelCase									=					self.get_scheduler_config()
										UpperCAmelCase									=					scheduler_class(**lowercase_							)

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

										UpperCAmelCase									=					torch.manual_seed(0							)

										UpperCAmelCase									=					self.dummy_model()
										UpperCAmelCase									=					self.dummy_sample_deter * scheduler.init_noise_sigma.cpu()
										UpperCAmelCase									=					sample.to(lowercase_							)

										for t in scheduler.timesteps:
														UpperCAmelCase									=					scheduler.scale_model_input(lowercase_   ,       lowercase_							)

														UpperCAmelCase									=					model(lowercase_   ,       lowercase_							)

														UpperCAmelCase									=					scheduler.step(lowercase_   ,       lowercase_   ,       lowercase_   ,       generator=lowercase_							)
														UpperCAmelCase									=					output.prev_sample

										UpperCAmelCase									=					torch.sum(torch.abs(lowercase_							)							)
										UpperCAmelCase									=					torch.mean(torch.abs(lowercase_							)							)

										assert abs(result_sum.item() - 1_0.0_8_0_7							) < 1E-2
										assert abs(result_mean.item() - 0.0_1_3_1							) < 1E-3




						def     a_      (							self							)						->					List[str]:
										UpperCAmelCase									=					self.scheduler_classes[0]
										UpperCAmelCase									=					self.get_scheduler_config()
										UpperCAmelCase									=					scheduler_class(**lowercase_   ,       use_karras_sigmas=lowercase_							)

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

										UpperCAmelCase									=					torch.manual_seed(0							)

										UpperCAmelCase									=					self.dummy_model()
										UpperCAmelCase									=					self.dummy_sample_deter * scheduler.init_noise_sigma.cpu()
										UpperCAmelCase									=					sample.to(lowercase_							)

										for t in scheduler.timesteps:
														UpperCAmelCase									=					scheduler.scale_model_input(lowercase_   ,       lowercase_							)

														UpperCAmelCase									=					model(lowercase_   ,       lowercase_							)

														UpperCAmelCase									=					scheduler.step(lowercase_   ,       lowercase_   ,       lowercase_   ,       generator=lowercase_							)
														UpperCAmelCase									=					output.prev_sample

										UpperCAmelCase									=					torch.sum(torch.abs(lowercase_							)							)
										UpperCAmelCase									=					torch.mean(torch.abs(lowercase_							)							)

										assert abs(result_sum.item() - 1_2_4.5_2_2_9_9_4_9_9_5_1_1_7_1_9							) < 1E-2
										assert abs(result_mean.item() - 0.1_6_2_1_3_9_3_2_6_3_3_3_9_9_9_6_3							) < 1E-3





"""simple docstring"""

def     lowercase__						(					lowerCAmelCase				:					int ,				lowerCAmelCase				:					int ) ->      int:






    """simple docstring"""




    return int((input_a, input_a).count(0 ) == 0 )




def     lowercase__						(					) ->      None:






    """simple docstring"""




    assert and_gate(0 ,				0 ) == 0
    assert and_gate(0 ,				1 ) == 0
    assert and_gate(1 ,				0 ) == 0
    assert and_gate(1 ,				1 ) == 1


if __name__ == "__main__":
   test_and_gate()
   print(and_gate(1, 0))
   print(and_gate(0, 0))
   print(and_gate(0, 1))
   print(and_gate(1, 1))



