


'''simple docstring'''
import torch

from diffusers import KDPMaAncestralDiscreteScheduler
from diffusers.utils import torch_device

from .test_schedulers import SchedulerCommonTest






class 		UpperCamelCase_		(					A   ):





						"""simple docstring"""




						UpperCAmelCase__	:       List[Any]         =     (KDPMaAncestralDiscreteScheduler,)
						UpperCAmelCase__	:       List[str]         =     10
						def 					__A					( self				:					Any	,				**_lowerCamelCase				:					Optional[Any]  )							->					Optional[int]:
										__magic_name__	  = {
										    "num_train_timesteps": 11_00,
										    "beta_start": 0.0_001,
										    "beta_end": 0.02,
										    "beta_schedule": "linear",
										}

										config.update(**_lowerCamelCase  )
										return config
						def 					__A					( self				:					List[str]  )							->					List[Any]:
										for timesteps in [10, 50, 1_00, 10_00]:
														self.check_over_configs(num_train_timesteps=_lowerCamelCase  )
						def 					__A					( self				:					List[str]  )							->					int:
										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				:					Optional[Any]  )							->					Dict:
										for schedule in ["linear", "scaled_linear"]:
														self.check_over_configs(beta_schedule=_lowerCamelCase  )
						def 					__A					( self				:					List[str]  )							->					Dict:
										if torch_device == "mps":
														return
										__magic_name__	  = self.scheduler_classes[0]
										__magic_name__	  = self.get_scheduler_config()
										__magic_name__	  = scheduler_class(**_lowerCamelCase  )

										scheduler.set_timesteps(self.num_inference_steps  )

										__magic_name__	  = torch.manual_seed(0  )

										__magic_name__	  = self.dummy_model()
										__magic_name__	  = self.dummy_sample_deter * scheduler.init_noise_sigma
										__magic_name__	  = sample.to(_lowerCamelCase  )

										for i, t in enumerate(scheduler.timesteps  ):
														__magic_name__	  = scheduler.scale_model_input(_lowerCamelCase	,				_lowerCamelCase  )

														__magic_name__	  = model(_lowerCamelCase	,				_lowerCamelCase  )

														__magic_name__	  = scheduler.step(_lowerCamelCase	,				_lowerCamelCase	,				_lowerCamelCase	,				generator=_lowerCamelCase  )
														__magic_name__	  = output.prev_sample

										__magic_name__	  = torch.sum(torch.abs(_lowerCamelCase  )  )
										__magic_name__	  = torch.mean(torch.abs(_lowerCamelCase  )  )

										assert abs(result_sum.item() - 13_849.3_877  ) < 1e-2
										assert abs(result_mean.item() - 18.0_331  ) < 5e-3
						def 					__A					( self				:					int  )							->					Any:
										for prediction_type in ["epsilon", "v_prediction"]:
														self.check_over_configs(prediction_type=_lowerCamelCase  )
						def 					__A					( self				:					Dict  )							->					Dict:
										if torch_device == "mps":
														return
										__magic_name__	  = self.scheduler_classes[0]
										__magic_name__	  = self.get_scheduler_config(prediction_type="v_prediction"  )
										__magic_name__	  = scheduler_class(**_lowerCamelCase  )

										scheduler.set_timesteps(self.num_inference_steps  )

										__magic_name__	  = self.dummy_model()
										__magic_name__	  = self.dummy_sample_deter * scheduler.init_noise_sigma
										__magic_name__	  = sample.to(_lowerCamelCase  )

										__magic_name__	  = torch.manual_seed(0  )

										for i, t in enumerate(scheduler.timesteps  ):
														__magic_name__	  = scheduler.scale_model_input(_lowerCamelCase	,				_lowerCamelCase  )

														__magic_name__	  = model(_lowerCamelCase	,				_lowerCamelCase  )

														__magic_name__	  = scheduler.step(_lowerCamelCase	,				_lowerCamelCase	,				_lowerCamelCase	,				generator=_lowerCamelCase  )
														__magic_name__	  = output.prev_sample

										__magic_name__	  = torch.sum(torch.abs(_lowerCamelCase  )  )
										__magic_name__	  = torch.mean(torch.abs(_lowerCamelCase  )  )

										assert abs(result_sum.item() - 328.9_970  ) < 1e-2
										assert abs(result_mean.item() - 0.4_284  ) < 1e-3

						def 					__A					( self				:					Dict  )							->					List[str]:
										if torch_device == "mps":
														return
										__magic_name__	  = self.scheduler_classes[0]
										__magic_name__	  = self.get_scheduler_config()
										__magic_name__	  = scheduler_class(**_lowerCamelCase  )

										scheduler.set_timesteps(self.num_inference_steps	,				device=_lowerCamelCase  )
										__magic_name__	  = torch.manual_seed(0  )

										__magic_name__	  = self.dummy_model()
										__magic_name__	  = self.dummy_sample_deter.to(_lowerCamelCase  ) * scheduler.init_noise_sigma

										for t in scheduler.timesteps:
														__magic_name__	  = scheduler.scale_model_input(_lowerCamelCase	,				_lowerCamelCase  )

														__magic_name__	  = model(_lowerCamelCase	,				_lowerCamelCase  )

														__magic_name__	  = scheduler.step(_lowerCamelCase	,				_lowerCamelCase	,				_lowerCamelCase	,				generator=_lowerCamelCase  )
														__magic_name__	  = output.prev_sample

										__magic_name__	  = torch.sum(torch.abs(_lowerCamelCase  )  )
										__magic_name__	  = torch.mean(torch.abs(_lowerCamelCase  )  )

										assert abs(result_sum.item() - 13_849.3_818  ) < 1e-1
										assert abs(result_mean.item() - 18.0_331  ) < 1e-3







'''simple docstring'''
import os
import sys
import time

from . import transposition_cipher as trans_cipher




def      __snake_case       (       ):
				'''simple docstring'''




				__magic_name__	  = "Prehistoric Men.txt"
				__magic_name__	  = "Output.txt"
				__magic_name__	  = int(input("Enter key: "						)						)
				__magic_name__	  = input("Encrypt/Decrypt [e/d]: "						)

				if not os.path.exists(lowerCamelCase_						):
								print(F'File {input_file} does not exist. Quitting...'						)
								sys.exit()
				if os.path.exists(lowerCamelCase_						):
								print(F'Overwrite {output_file}? [y/n]'						)
								__magic_name__	  = input("> "						)
								if not response.lower().startswith("y"						):
												sys.exit()

				__magic_name__	  = time.time()
				if mode.lower().startswith("e"						):
								with open(lowerCamelCase_						) as f:
												__magic_name__	  = f.read()
								__magic_name__	  = trans_cipher.encrypt_message(lowerCamelCase_	,  lowerCamelCase_						)
				elif mode.lower().startswith("d"						):
								with open(lowerCamelCase_						) as f:
												__magic_name__	  = f.read()
								__magic_name__	  = trans_cipher.decrypt_message(lowerCamelCase_	,  lowerCamelCase_						)

				with open(lowerCamelCase_	,  "w"						) as output_obj:
								output_obj.write(lowerCamelCase_						)

				__magic_name__	  = round(time.time() - start_time	,  2						)
				print(("Done (", total_time, "seconds )")						)


if __name__ == "__main__":
						main()



