




"""simple docstring"""




import tempfile

import torch

from diffusers import (
    DEISMultistepScheduler,
    DPMSolverMultistepScheduler,
    DPMSolverSinglestepScheduler,
    UniPCMultistepScheduler,
)

from .test_schedulers import SchedulerCommonTest

class   UpperCAmelCase_    (			snake_case		):
		UpperCamelCase							=(DPMSolverSinglestepScheduler,)
		UpperCamelCase							=(("num_inference_steps", 25),)
		def 	_lowerCamelCase							(						self				,						**UpperCamelCase_       )						->       List[str]:
					__lowercase			:  int								=       {
					    '''num_train_timesteps''': 10_00,
					    '''beta_start''': 0.0_0_0_1,
					    '''beta_end''': 0.0_2,
					    '''beta_schedule''': '''linear''',
					    '''solver_order''': 2,
					    '''prediction_type''': '''epsilon''',
					    '''thresholding''': False,
					    '''sample_max_value''': 1.0,
					    '''algorithm_type''': '''dpmsolver++''',
					    '''solver_type''': '''midpoint''',
					    '''lambda_min_clipped''': -float('''inf'''       ),
					    '''variance_type''': None,
					}

					config.update(**UpperCamelCase_       )
					return config
		def 	_lowerCamelCase							(						self				,						UpperCamelCase_=0				,						**UpperCamelCase_       )						->       List[str]:
					__lowercase			:  Any								=       dict(self.forward_default_kwargs       )
					__lowercase			:  str								=       kwargs.pop('''num_inference_steps'''				,						UpperCamelCase_       )
					__lowercase			:  Union[str, Any]								=       self.dummy_sample
					__lowercase			:  Dict								=       0.1 * sample
					__lowercase			:  int								=       [residual + 0.2, residual + 0.1_5, residual + 0.1_0]

					for scheduler_class in self.scheduler_classes:
								__lowercase			:  Dict								=       self.get_scheduler_config(**UpperCamelCase_       )
								__lowercase			:  str								=       scheduler_class(**UpperCamelCase_       )
								scheduler.set_timesteps(UpperCamelCase_       )
								# copy over dummy past residuals
								__lowercase			:  Dict								=       dummy_past_residuals[: scheduler.config.solver_order]

								with tempfile.TemporaryDirectory() as tmpdirname:
											scheduler.save_config(UpperCamelCase_       )
											__lowercase			:  Optional[Any]								=       scheduler_class.from_pretrained(UpperCamelCase_       )
											new_scheduler.set_timesteps(UpperCamelCase_       )
											# copy over dummy past residuals
											__lowercase			:  Optional[Any]								=       dummy_past_residuals[: new_scheduler.config.solver_order]

								__lowercase			,__lowercase			:  Dict								=       sample, sample
								for t in range(UpperCamelCase_				,						time_step + scheduler.config.solver_order + 1       ):
											__lowercase			:  Optional[int]								=       scheduler.step(UpperCamelCase_				,						UpperCamelCase_				,						UpperCamelCase_				,						**UpperCamelCase_       ).prev_sample
											__lowercase			:  List[str]								=       new_scheduler.step(UpperCamelCase_				,						UpperCamelCase_				,						UpperCamelCase_				,						**UpperCamelCase_       ).prev_sample

											assert torch.sum(torch.abs(output - new_output       )       ) < 1E-5, "Scheduler outputs are not identical"
		def 	_lowerCamelCase							(						self       )						->       Optional[Any]:
					pass
		def 	_lowerCamelCase							(						self				,						UpperCamelCase_=0				,						**UpperCamelCase_       )						->       Dict:
					__lowercase			:  Optional[Any]								=       dict(self.forward_default_kwargs       )
					__lowercase			:  Optional[Any]								=       kwargs.pop('''num_inference_steps'''				,						UpperCamelCase_       )
					__lowercase			:  int								=       self.dummy_sample
					__lowercase			:  Union[str, Any]								=       0.1 * sample
					__lowercase			:  Optional[Any]								=       [residual + 0.2, residual + 0.1_5, residual + 0.1_0]

					for scheduler_class in self.scheduler_classes:
								__lowercase			:  Union[str, Any]								=       self.get_scheduler_config()
								__lowercase			:  int								=       scheduler_class(**UpperCamelCase_       )
								scheduler.set_timesteps(UpperCamelCase_       )

								# copy over dummy past residuals (must be after setting timesteps)
								__lowercase			:  str								=       dummy_past_residuals[: scheduler.config.solver_order]

								with tempfile.TemporaryDirectory() as tmpdirname:
											scheduler.save_config(UpperCamelCase_       )
											__lowercase			:  Any								=       scheduler_class.from_pretrained(UpperCamelCase_       )
											# copy over dummy past residuals
											new_scheduler.set_timesteps(UpperCamelCase_       )

											# copy over dummy past residual (must be after setting timesteps)
											__lowercase			:  Union[str, Any]								=       dummy_past_residuals[: new_scheduler.config.solver_order]

								__lowercase			:  str								=       scheduler.step(UpperCamelCase_				,						UpperCamelCase_				,						UpperCamelCase_				,						**UpperCamelCase_       ).prev_sample
								__lowercase			:  List[Any]								=       new_scheduler.step(UpperCamelCase_				,						UpperCamelCase_				,						UpperCamelCase_				,						**UpperCamelCase_       ).prev_sample

								assert torch.sum(torch.abs(output - new_output       )       ) < 1E-5, "Scheduler outputs are not identical"
		def 	_lowerCamelCase							(						self				,						UpperCamelCase_=None				,						**UpperCamelCase_       )						->       List[Any]:
					if scheduler is None:
								__lowercase			:  Any								=       self.scheduler_classes[0]
								__lowercase			:  Union[str, Any]								=       self.get_scheduler_config(**UpperCamelCase_       )
								__lowercase			:  Tuple								=       scheduler_class(**UpperCamelCase_       )

					__lowercase			:  Tuple								=       self.scheduler_classes[0]
					__lowercase			:  int								=       self.get_scheduler_config(**UpperCamelCase_       )
					__lowercase			:  List[str]								=       scheduler_class(**UpperCamelCase_       )

					__lowercase			:  str								=       10
					__lowercase			:  Tuple								=       self.dummy_model()
					__lowercase			:  Tuple								=       self.dummy_sample_deter
					scheduler.set_timesteps(UpperCamelCase_       )

					for i, t in enumerate(scheduler.timesteps       ):
								__lowercase			:  Union[str, Any]								=       model(UpperCamelCase_				,						UpperCamelCase_       )
								__lowercase			:  str								=       scheduler.step(UpperCamelCase_				,						UpperCamelCase_				,						UpperCamelCase_       ).prev_sample

					return sample
		def 	_lowerCamelCase							(						self       )						->       str:
					__lowercase			:  Union[str, Any]								=       DPMSolverSinglestepScheduler(**self.get_scheduler_config()       )
					__lowercase			:  Any								=       50
					__lowercase			:  Optional[Any]								=       self.dummy_model()
					__lowercase			:  Union[str, Any]								=       self.dummy_sample_deter
					scheduler.set_timesteps(UpperCamelCase_       )

					# make sure that the first t is uneven
					for i, t in enumerate(scheduler.timesteps[3:]       ):
								__lowercase			:  int								=       model(UpperCamelCase_				,						UpperCamelCase_       )
								__lowercase			:  int								=       scheduler.step(UpperCamelCase_				,						UpperCamelCase_				,						UpperCamelCase_       ).prev_sample

					__lowercase			:  Any								=       torch.mean(torch.abs(UpperCamelCase_       )       )

					assert abs(result_mean.item() - 0.2_5_7_4       ) < 1E-3
		def 	_lowerCamelCase							(						self       )						->       List[str]:
					for timesteps in [25, 50, 1_00, 9_99, 10_00]:
								self.check_over_configs(num_train_timesteps=UpperCamelCase_       )
		def 	_lowerCamelCase							(						self       )						->       List[str]:
					# make sure that iterating over schedulers with same config names gives same results
					# for defaults
					__lowercase			:  int								=       DPMSolverSinglestepScheduler(**self.get_scheduler_config()       )
					__lowercase			:  Optional[int]								=       self.full_loop(scheduler=UpperCamelCase_       )
					__lowercase			:  Any								=       torch.mean(torch.abs(UpperCamelCase_       )       )

					assert abs(result_mean.item() - 0.2_7_9_1       ) < 1E-3

					__lowercase			:  int								=       DEISMultistepScheduler.from_config(scheduler.config       )
					__lowercase			:  Union[str, Any]								=       DPMSolverMultistepScheduler.from_config(scheduler.config       )
					__lowercase			:  Optional[Any]								=       UniPCMultistepScheduler.from_config(scheduler.config       )
					__lowercase			:  str								=       DPMSolverSinglestepScheduler.from_config(scheduler.config       )

					__lowercase			:  List[str]								=       self.full_loop(scheduler=UpperCamelCase_       )
					__lowercase			:  Tuple								=       torch.mean(torch.abs(UpperCamelCase_       )       )

					assert abs(result_mean.item() - 0.2_7_9_1       ) < 1E-3
		def 	_lowerCamelCase							(						self       )						->       Optional[int]:
					self.check_over_configs(thresholding=UpperCamelCase_       )
					for order in [1, 2, 3]:
								for solver_type in ["midpoint", "heun"]:
											for threshold in [0.5, 1.0, 2.0]:
														for prediction_type in ["epsilon", "sample"]:
																	self.check_over_configs(
																	    thresholding=UpperCamelCase_				,						prediction_type=UpperCamelCase_				,						sample_max_value=UpperCamelCase_				,						algorithm_type='''dpmsolver++'''				,						solver_order=UpperCamelCase_				,						solver_type=UpperCamelCase_				,						)
		def 	_lowerCamelCase							(						self       )						->       int:
					for prediction_type in ["epsilon", "v_prediction"]:
								self.check_over_configs(prediction_type=UpperCamelCase_       )
		def 	_lowerCamelCase							(						self       )						->       Union[str, Any]:
					for algorithm_type in ["dpmsolver", "dpmsolver++"]:
								for solver_type in ["midpoint", "heun"]:
											for order in [1, 2, 3]:
														for prediction_type in ["epsilon", "sample"]:
																	self.check_over_configs(
																	    solver_order=UpperCamelCase_				,						solver_type=UpperCamelCase_				,						prediction_type=UpperCamelCase_				,						algorithm_type=UpperCamelCase_				,						)
																	__lowercase			:  List[str]								=       self.full_loop(
																	    solver_order=UpperCamelCase_				,						solver_type=UpperCamelCase_				,						prediction_type=UpperCamelCase_				,						algorithm_type=UpperCamelCase_				,						)
																	assert not torch.isnan(UpperCamelCase_       ).any(), "Samples have nan numbers"
		def 	_lowerCamelCase							(						self       )						->       Dict:
					self.check_over_configs(lower_order_final=UpperCamelCase_       )
					self.check_over_configs(lower_order_final=UpperCamelCase_       )
		def 	_lowerCamelCase							(						self       )						->       List[Any]:
					self.check_over_configs(lambda_min_clipped=-float('''inf'''       )       )
					self.check_over_configs(lambda_min_clipped=-5.1       )
		def 	_lowerCamelCase							(						self       )						->       Any:
					self.check_over_configs(variance_type=UpperCamelCase_       )
					self.check_over_configs(variance_type='''learned_range'''       )
		def 	_lowerCamelCase							(						self       )						->       int:
					for num_inference_steps in [1, 2, 3, 5, 10, 50, 1_00, 9_99, 10_00]:
								self.check_over_forward(num_inference_steps=UpperCamelCase_				,						time_step=0       )
		def 	_lowerCamelCase							(						self       )						->       Optional[int]:
					__lowercase			:  int								=       self.full_loop()
					__lowercase			:  Union[str, Any]								=       torch.mean(torch.abs(UpperCamelCase_       )       )

					assert abs(result_mean.item() - 0.2_7_9_1       ) < 1E-3
		def 	_lowerCamelCase							(						self       )						->       Tuple:
					__lowercase			:  List[Any]								=       self.full_loop(use_karras_sigmas=UpperCamelCase_       )
					__lowercase			:  Optional[int]								=       torch.mean(torch.abs(UpperCamelCase_       )       )

					assert abs(result_mean.item() - 0.2_2_4_8       ) < 1E-3
		def 	_lowerCamelCase							(						self       )						->       int:
					__lowercase			:  Optional[int]								=       self.full_loop(prediction_type='''v_prediction'''       )
					__lowercase			:  Tuple								=       torch.mean(torch.abs(UpperCamelCase_       )       )

					assert abs(result_mean.item() - 0.1_4_5_3       ) < 1E-3
		def 	_lowerCamelCase							(						self       )						->       Optional[Any]:
					__lowercase			:  Optional[Any]								=       self.full_loop(prediction_type='''v_prediction'''				,						use_karras_sigmas=UpperCamelCase_       )
					__lowercase			:  int								=       torch.mean(torch.abs(UpperCamelCase_       )       )

					assert abs(result_mean.item() - 0.0_6_4_9       ) < 1E-3
		def 	_lowerCamelCase							(						self       )						->       Any:
					__lowercase			:  Dict								=       self.scheduler_classes[0]
					__lowercase			:  Optional[Any]								=       self.get_scheduler_config(thresholding=UpperCamelCase_				,						dynamic_thresholding_ratio=0       )
					__lowercase			:  Optional[int]								=       scheduler_class(**UpperCamelCase_       )

					__lowercase			:  Optional[Any]								=       10
					__lowercase			:  Union[str, Any]								=       self.dummy_model()
					__lowercase			:  Tuple								=       self.dummy_sample_deter.half()
					scheduler.set_timesteps(UpperCamelCase_       )

					for i, t in enumerate(scheduler.timesteps       ):
								__lowercase			:  str								=       model(UpperCamelCase_				,						UpperCamelCase_       )
								__lowercase			:  Union[str, Any]								=       scheduler.step(UpperCamelCase_				,						UpperCamelCase_				,						UpperCamelCase_       ).prev_sample

					assert sample.dtype == torch.floataa










"""simple docstring"""



def 						__lowercase	(  snake_case_    :    int							,snake_case_    :    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))




