



"""simple docstring"""

import torch

from diffusers import DDPMParallelScheduler

from .test_schedulers import SchedulerCommonTest




class SCREAMING_SNAKE_CASE__					(       _UpperCAmelCase      ):
						_lowerCAmelCase							=					(DDPMParallelScheduler,)



						def     lowerCAmelCase__(self						,     **_lowercase							):





													'''simple docstring'''

													__a		:		Optional[Any]									=       {
													    '''num_train_timesteps''': 1000,
													    '''beta_start''': 0.0001,
													    '''beta_end''': 0.02,
													    '''beta_schedule''': '''linear''',
													    '''variance_type''': '''fixed_small''',
													    '''clip_sample''': True,
													}

													config.update(**lowerCamelCase_							)
													return config



						def     lowerCAmelCase__(self							):





													'''simple docstring'''

													for timesteps in [1, 5, 100, 1000]:
																				self.check_over_configs(num_train_timesteps=lowerCamelCase_							)



						def     lowerCAmelCase__(self							):





													'''simple docstring'''

													for beta_start, beta_end in zip([0.0001, 0.001, 0.01, 0.1]						,     [0.002, 0.02, 0.2, 2]							):
																				self.check_over_configs(beta_start=lowerCamelCase_						,     beta_end=lowerCamelCase_							)



						def     lowerCAmelCase__(self							):





													'''simple docstring'''

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



						def     lowerCAmelCase__(self							):





													'''simple docstring'''

													for variance in ["fixed_small", "fixed_large", "other"]:
																				self.check_over_configs(variance_type=lowerCamelCase_							)



						def     lowerCAmelCase__(self							):





													'''simple docstring'''

													for clip_sample in [True, False]:
																				self.check_over_configs(clip_sample=lowerCamelCase_							)



						def     lowerCAmelCase__(self							):





													'''simple docstring'''

													self.check_over_configs(thresholding=lowerCamelCase_							)
													for threshold in [0.5, 1.0, 2.0]:
																				for prediction_type in ["epsilon", "sample", "v_prediction"]:
																											self.check_over_configs(
																											    thresholding=lowerCamelCase_						,     prediction_type=lowerCamelCase_						,     sample_max_value=lowerCamelCase_						,     )



						def     lowerCAmelCase__(self							):





													'''simple docstring'''

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



						def     lowerCAmelCase__(self							):





													'''simple docstring'''

													for t in [0, 500, 999]:
																				self.check_over_forward(time_step=lowerCamelCase_							)



						def     lowerCAmelCase__(self							):





													'''simple docstring'''

													__a		:		List[Any]									=       self.scheduler_classes[0]
													__a		:		Union[str, Any]									=       self.get_scheduler_config()
													__a		:		Tuple									=       scheduler_class(**lowerCamelCase_							)

													assert torch.sum(torch.abs(scheduler._get_variance(0							) - 0.0							)							) < 1e-5
													assert torch.sum(torch.abs(scheduler._get_variance(487							) - 0.0_0979							)							) < 1e-5
													assert torch.sum(torch.abs(scheduler._get_variance(999							) - 0.02							)							) < 1e-5



						def     lowerCAmelCase__(self							):





													'''simple docstring'''

													__a		:		Union[str, Any]									=       self.scheduler_classes[0]
													__a		:		List[Any]									=       self.get_scheduler_config()
													__a		:		Union[str, Any]									=       scheduler_class(**lowerCamelCase_							)

													__a		:		Any									=       len(lowerCamelCase_							)

													__a		:		Optional[int]									=       self.dummy_model()
													__a		:		Dict									=       self.dummy_sample_deter
													__a		:		Dict									=       self.dummy_sample_deter + 0.1
													__a		:		int									=       self.dummy_sample_deter - 0.1

													__a		:		List[str]									=       samplea.shape[0]
													__a		:		Optional[int]									=       torch.stack([samplea, samplea, samplea]						,     dim=0							)
													__a		:		List[str]									=       torch.arange(lowerCamelCase_							)[0:3, None].repeat(1						,     lowerCamelCase_							)

													__a		:		Dict									=       model(samples.flatten(0						,     1							)						,     timesteps.flatten(0						,     1							)							)
													__a		:		List[str]									=       scheduler.batch_step_no_noise(lowerCamelCase_						,     timesteps.flatten(0						,     1							)						,     samples.flatten(0						,     1							)							)

													__a		:		Any									=       torch.sum(torch.abs(lowerCamelCase_							)							)
													__a		:		Any									=       torch.mean(torch.abs(lowerCamelCase_							)							)

													assert abs(result_sum.item() - 1153.1833							) < 1e-2
													assert abs(result_mean.item() - 0.5005							) < 1e-3



						def     lowerCAmelCase__(self							):





													'''simple docstring'''

													__a		:		Optional[int]									=       self.scheduler_classes[0]
													__a		:		List[Any]									=       self.get_scheduler_config()
													__a		:		Dict									=       scheduler_class(**lowerCamelCase_							)

													__a		:		List[str]									=       len(lowerCamelCase_							)

													__a		:		Dict									=       self.dummy_model()
													__a		:		Union[str, Any]									=       self.dummy_sample_deter
													__a		:		Union[str, Any]									=       torch.manual_seed(0							)

													for t in reversed(range(lowerCamelCase_							)							):
																				# 1. predict noise residual
																				__a		:		Tuple									=       model(lowerCamelCase_						,     lowerCamelCase_							)

																				# 2. predict previous mean of sample x_t-1
																				__a		:		Union[str, Any]									=       scheduler.step(lowerCamelCase_						,     lowerCamelCase_						,     lowerCamelCase_						,     generator=lowerCamelCase_							).prev_sample

																				__a		:		Tuple									=       pred_prev_sample

													__a		:		Dict									=       torch.sum(torch.abs(lowerCamelCase_							)							)
													__a		:		str									=       torch.mean(torch.abs(lowerCamelCase_							)							)

													assert abs(result_sum.item() - 258.9606							) < 1e-2
													assert abs(result_mean.item() - 0.3372							) < 1e-3



						def     lowerCAmelCase__(self							):





													'''simple docstring'''

													__a		:		Optional[int]									=       self.scheduler_classes[0]
													__a		:		Optional[Any]									=       self.get_scheduler_config(prediction_type="""v_prediction"""							)
													__a		:		Any									=       scheduler_class(**lowerCamelCase_							)

													__a		:		List[Any]									=       len(lowerCamelCase_							)

													__a		:		Dict									=       self.dummy_model()
													__a		:		Optional[int]									=       self.dummy_sample_deter
													__a		:		List[str]									=       torch.manual_seed(0							)

													for t in reversed(range(lowerCamelCase_							)							):
																				# 1. predict noise residual
																				__a		:		Optional[int]									=       model(lowerCamelCase_						,     lowerCamelCase_							)

																				# 2. predict previous mean of sample x_t-1
																				__a		:		Tuple									=       scheduler.step(lowerCamelCase_						,     lowerCamelCase_						,     lowerCamelCase_						,     generator=lowerCamelCase_							).prev_sample

																				__a		:		Optional[int]									=       pred_prev_sample

													__a		:		Any									=       torch.sum(torch.abs(lowerCamelCase_							)							)
													__a		:		Dict									=       torch.mean(torch.abs(lowerCamelCase_							)							)

													assert abs(result_sum.item() - 202.0296							) < 1e-2
													assert abs(result_mean.item() - 0.2631							) < 1e-3



						def     lowerCAmelCase__(self							):





													'''simple docstring'''

													__a		:		Optional[Any]									=       self.scheduler_classes[0]
													__a		:		Optional[Any]									=       self.get_scheduler_config()
													__a		:		Optional[int]									=       scheduler_class(**lowerCamelCase_							)

													__a		:		Any									=       [100, 87, 50, 1, 0]

													scheduler.set_timesteps(timesteps=lowerCamelCase_							)

													__a		:		List[Any]									=       scheduler.timesteps

													for i, timestep in enumerate(lowerCamelCase_							):
																				if i == len(lowerCamelCase_							) - 1:
																											__a		:		List[str]									=       -1
																				else:
																											__a		:		int									=       timesteps[i + 1]

																				__a		:		List[Any]									=       scheduler.previous_timestep(lowerCamelCase_							)
																				__a		:		Optional[Any]									=       prev_t.item()

																				self.assertEqual(lowerCamelCase_						,     lowerCamelCase_							)



						def     lowerCAmelCase__(self							):





													'''simple docstring'''

													__a		:		List[Any]									=       self.scheduler_classes[0]
													__a		:		Tuple									=       self.get_scheduler_config()
													__a		:		Optional[Any]									=       scheduler_class(**lowerCamelCase_							)

													__a		:		Optional[Any]									=       [100, 87, 50, 51, 0]

													with self.assertRaises(lowerCamelCase_						,     msg="""`custom_timesteps` must be in descending order."""							):
																				scheduler.set_timesteps(timesteps=lowerCamelCase_							)



						def     lowerCAmelCase__(self							):





													'''simple docstring'''

													__a		:		Optional[Any]									=       self.scheduler_classes[0]
													__a		:		Optional[Any]									=       self.get_scheduler_config()
													__a		:		int									=       scheduler_class(**lowerCamelCase_							)

													__a		:		Tuple									=       [100, 87, 50, 1, 0]
													__a		:		Optional[int]									=       len(lowerCamelCase_							)

													with self.assertRaises(lowerCamelCase_						,     msg="""Can only pass one of `num_inference_steps` or `custom_timesteps`."""							):
																				scheduler.set_timesteps(num_inference_steps=lowerCamelCase_						,     timesteps=lowerCamelCase_							)





						def     lowerCAmelCase__(self							):





													'''simple docstring'''

													__a		:		int									=       self.scheduler_classes[0]
													__a		:		Any									=       self.get_scheduler_config()
													__a		:		List[Any]									=       scheduler_class(**lowerCamelCase_							)

													__a		:		List[Any]									=       [scheduler.config.num_train_timesteps]

													with self.assertRaises(
													    lowerCamelCase_						,     msg="""`timesteps` must start before `self.config.train_timesteps`: {scheduler.config.num_train_timesteps}}"""						,     ):
																				scheduler.set_timesteps(timesteps=lowerCamelCase_							)






"""simple docstring"""

import os





def       __magic_name__    (   _lowerCamelCase				: Dict					):
							__a		:		List[str]									=       len(grid[0]					)
							__a		:		int									=       len(_lowerCamelCase					)

							__a		:		Tuple									=       0
							__a		:		List[Any]									=       0
							__a		:		List[str]									=       0

							# Check vertically, horizontally, diagonally at the same time (only works
							# for nxn grid)
							for i in range(_lowerCamelCase					):
														for j in range(n_rows - 3					):
																					__a		:		List[Any]									=       grid[j][i] * grid[j + 1][i] * grid[j + 2][i] * grid[j + 3][i]
																					__a		:		Tuple									=       grid[i][j] * grid[i][j + 1] * grid[i][j + 2] * grid[i][j + 3]

																					# Left-to-right diagonal (\) product
																					if i < n_columns - 3:
																												__a		:		List[Any]									=       (
																												    grid[i][j]
																												    * grid[i + 1][j + 1]
																												    * grid[i + 2][j + 2]
																												    * grid[i + 3][j + 3]
																												)

																					# Right-to-left diagonal(/) product
																					if i > 2:
																												__a		:		List[Any]									=       (
																												    grid[i][j]
																												    * grid[i - 1][j + 1]
																												    * grid[i - 2][j + 2]
																												    * grid[i - 3][j + 3]
																												)

																					__a		:		str									=       max(
																					    _lowerCamelCase  ,       _lowerCamelCase  ,       _lowerCamelCase  ,       _lowerCamelCase					)
																					if max_product > largest:
																												__a		:		Optional[Any]									=       max_product

							return largest





def       __magic_name__    (   ):
							__a		:		Tuple									=       []
							with open(os.path.dirname(_lowerCamelCase					) + """/grid.txt"""					) as file:
														for line in file:
																					grid.append(line.strip("""\n"""					).split(""" """					)					)

							__a		:		Tuple									=       [[int(_lowerCamelCase					) for i in grid[j]] for j in range(len(_lowerCamelCase					)					)]

							return largest_product(_lowerCamelCase					)


if __name__ == "__main__":
	print(solution())

