




'''simple docstring'''





import torch

from diffusers import DPMSolverSDEScheduler
from diffusers.utils import torch_device
from diffusers.utils.testing_utils import require_torchsde

from .test_schedulers import SchedulerCommonTest

@require_torchsde
class        _a    (						__lowerCAmelCase							):
     SCREAMING_SNAKE_CASE_							:   Optional[Any]       =						(DPMSolverSDEScheduler,)
     SCREAMING_SNAKE_CASE_							:   List[str]       =						10






     def     _lowercase     (			self ,**_SCREAMING_SNAKE_CASE   )							->      List[str]:
          _snake_case							=				{
              "num_train_timesteps": 1_100,
              "beta_start": 0.0_0_0_1,
              "beta_end": 0.0_2,
              "beta_schedule": "linear",
              "noise_sampler_seed": 0,
          }

          config.update(**_SCREAMING_SNAKE_CASE   )
          return config






     def     _lowercase     (			self   )							->      Union[str, Any]:
          for timesteps in [10, 50, 100, 1_000]:
               self.check_over_configs(num_train_timesteps=_SCREAMING_SNAKE_CASE   )






     def     _lowercase     (			self   )							->      Dict:
          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=_SCREAMING_SNAKE_CASE ,beta_end=_SCREAMING_SNAKE_CASE   )






     def     _lowercase     (			self   )							->      Union[str, Any]:
          for schedule in ["linear", "scaled_linear"]:
               self.check_over_configs(beta_schedule=_SCREAMING_SNAKE_CASE   )






     def     _lowercase     (			self   )							->      Optional[Any]:
          for prediction_type in ["epsilon", "v_prediction"]:
               self.check_over_configs(prediction_type=_SCREAMING_SNAKE_CASE   )






     def     _lowercase     (			self   )							->      Optional[Any]:
          _snake_case							=				self.scheduler_classes[0]
          _snake_case							=				self.get_scheduler_config()
          _snake_case							=				scheduler_class(**_SCREAMING_SNAKE_CASE   )

          scheduler.set_timesteps(self.num_inference_steps   )

          _snake_case							=				self.dummy_model()
          _snake_case							=				self.dummy_sample_deter * scheduler.init_noise_sigma
          _snake_case							=				sample.to(_SCREAMING_SNAKE_CASE   )

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

               _snake_case							=				model(_SCREAMING_SNAKE_CASE ,_SCREAMING_SNAKE_CASE   )

               _snake_case							=				scheduler.step(_SCREAMING_SNAKE_CASE ,_SCREAMING_SNAKE_CASE ,_SCREAMING_SNAKE_CASE   )
               _snake_case							=				output.prev_sample

          _snake_case							=				torch.sum(torch.abs(_SCREAMING_SNAKE_CASE   )   )
          _snake_case							=				torch.mean(torch.abs(_SCREAMING_SNAKE_CASE   )   )

          if torch_device in ["mps"]:
               assert abs(result_sum.item() - 1_6_7.4_7_8_2_1_0_4_4_9_2_1_8_7_5   ) < 1e-2
               assert abs(result_mean.item() - 0.2_1_7_8_7_0_5_9_6_4_5_6_5_2_7_7   ) < 1e-3
          elif torch_device in ["cuda"]:
               assert abs(result_sum.item() - 1_7_1.5_9_3_5_2_1_1_1_8_1_6_4_0_6   ) < 1e-2
               assert abs(result_mean.item() - 0.2_2_3_4_2_9_0_6_8_9_2_2_9_9_6_5_2   ) < 1e-3
          else:
               assert abs(result_sum.item() - 1_6_2.5_2_3_8_3_4_2_2_8_5_1_5_6_2   ) < 1e-2
               assert abs(result_mean.item() - 0.2_1_1_6_1_9_5_7_0_8_5_1_3_2_6   ) < 1e-3






     def     _lowercase     (			self   )							->      List[str]:
          _snake_case							=				self.scheduler_classes[0]
          _snake_case							=				self.get_scheduler_config(prediction_type="v_prediction"   )
          _snake_case							=				scheduler_class(**_SCREAMING_SNAKE_CASE   )

          scheduler.set_timesteps(self.num_inference_steps   )

          _snake_case							=				self.dummy_model()
          _snake_case							=				self.dummy_sample_deter * scheduler.init_noise_sigma
          _snake_case							=				sample.to(_SCREAMING_SNAKE_CASE   )

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

               _snake_case							=				model(_SCREAMING_SNAKE_CASE ,_SCREAMING_SNAKE_CASE   )

               _snake_case							=				scheduler.step(_SCREAMING_SNAKE_CASE ,_SCREAMING_SNAKE_CASE ,_SCREAMING_SNAKE_CASE   )
               _snake_case							=				output.prev_sample

          _snake_case							=				torch.sum(torch.abs(_SCREAMING_SNAKE_CASE   )   )
          _snake_case							=				torch.mean(torch.abs(_SCREAMING_SNAKE_CASE   )   )

          if torch_device in ["mps"]:
               assert abs(result_sum.item() - 1_2_4.7_7_1_4_9_2_0_0_4_3_9_4_5_3   ) < 1e-2
               assert abs(result_mean.item() - 0.1_6_2_2_6_2_8_9_0_1_4_8_1_6_2_8_4   ) < 1e-3
          elif torch_device in ["cuda"]:
               assert abs(result_sum.item() - 1_2_8.1_6_6_3_3_6_0_5_9_5_7_0_3   ) < 1e-2
               assert abs(result_mean.item() - 0.1_6_6_8_8_3_2_6_0_0_1_1_6_7_2_9_7   ) < 1e-3
          else:
               assert abs(result_sum.item() - 1_1_9.8_4_8_7_5_4_8_8_2_8_1_2_5   ) < 1e-2
               assert abs(result_mean.item() - 0.1_5_6_0_5_3_0_6_6_2_5_3_6_6_2_1   ) < 1e-3






     def     _lowercase     (			self   )							->      Union[str, Any]:
          _snake_case							=				self.scheduler_classes[0]
          _snake_case							=				self.get_scheduler_config()
          _snake_case							=				scheduler_class(**_SCREAMING_SNAKE_CASE   )

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

          _snake_case							=				self.dummy_model()
          _snake_case							=				self.dummy_sample_deter.to(_SCREAMING_SNAKE_CASE   ) * scheduler.init_noise_sigma

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

               _snake_case							=				model(_SCREAMING_SNAKE_CASE ,_SCREAMING_SNAKE_CASE   )

               _snake_case							=				scheduler.step(_SCREAMING_SNAKE_CASE ,_SCREAMING_SNAKE_CASE ,_SCREAMING_SNAKE_CASE   )
               _snake_case							=				output.prev_sample

          _snake_case							=				torch.sum(torch.abs(_SCREAMING_SNAKE_CASE   )   )
          _snake_case							=				torch.mean(torch.abs(_SCREAMING_SNAKE_CASE   )   )

          if torch_device in ["mps"]:
               assert abs(result_sum.item() - 1_6_7.4_6_9_5_7_3_9_7_4_6_0_9_3_8   ) < 1e-2
               assert abs(result_mean.item() - 0.2_1_8_0_5_9_3_4_6_0_7_9_8_2_6_3_5   ) < 1e-3
          elif torch_device in ["cuda"]:
               assert abs(result_sum.item() - 1_7_1.5_9_3_5_3_6_3_7_6_9_5_3_1_2   ) < 1e-2
               assert abs(result_mean.item() - 0.2_2_3_4_2_9_0_8_3_8_2_4_1_5_7_7_1   ) < 1e-3
          else:
               assert abs(result_sum.item() - 1_6_2.5_2_3_8_3_4_2_2_8_5_1_5_6_2   ) < 1e-2
               assert abs(result_mean.item() - 0.2_1_1_6_1_9_5_7_0_8_5_1_3_2_6   ) < 1e-3






     def     _lowercase     (			self   )							->      Dict:
          _snake_case							=				self.scheduler_classes[0]
          _snake_case							=				self.get_scheduler_config()
          _snake_case							=				scheduler_class(**_SCREAMING_SNAKE_CASE ,use_karras_sigmas=_SCREAMING_SNAKE_CASE   )

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

          _snake_case							=				self.dummy_model()
          _snake_case							=				self.dummy_sample_deter.to(_SCREAMING_SNAKE_CASE   ) * scheduler.init_noise_sigma
          _snake_case							=				sample.to(_SCREAMING_SNAKE_CASE   )

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

               _snake_case							=				model(_SCREAMING_SNAKE_CASE ,_SCREAMING_SNAKE_CASE   )

               _snake_case							=				scheduler.step(_SCREAMING_SNAKE_CASE ,_SCREAMING_SNAKE_CASE ,_SCREAMING_SNAKE_CASE   )
               _snake_case							=				output.prev_sample

          _snake_case							=				torch.sum(torch.abs(_SCREAMING_SNAKE_CASE   )   )
          _snake_case							=				torch.mean(torch.abs(_SCREAMING_SNAKE_CASE   )   )

          if torch_device in ["mps"]:
               assert abs(result_sum.item() - 1_7_6.6_6_9_7_4_1_3_5_7_4_2_1_8_8   ) < 1e-2
               assert abs(result_mean.item() - 0.2_3_0_0_3_8_7_2_7_3_0_9_8_1_8_1_1   ) < 1e-2
          elif torch_device in ["cuda"]:
               assert abs(result_sum.item() - 1_7_7.6_3_6_5_3_5_6_4_4_5_3_1_2_5   ) < 1e-2
               assert abs(result_mean.item() - 0.2_3_0_0_3_8_7_2_7_3_0_9_8_1_8_1_1   ) < 1e-2
          else:
               assert abs(result_sum.item() - 1_7_0.3_1_3_5_2_2_3_3_8_8_6_7_2   ) < 1e-2
               assert abs(result_mean.item() - 0.2_3_0_0_3_8_7_2_7_3_0_9_8_1_8_1_1   ) < 1e-2








'''simple docstring'''





from decimal import Decimal, getcontext
from math import ceil, factorial





def      __a     (       _UpperCamelCase:   int   )						->			str:

     """simple docstring"""




     if not isinstance(_UpperCamelCase ,						_UpperCamelCase   ):
          raise TypeError("Undefined for non-integers"   )
     elif precision < 1:
          raise ValueError("Undefined for non-natural numbers"   )

     _snake_case							=				precision
     _snake_case							=				ceil(precision / 14   )
     _snake_case							=				426_880 * Decimal(10_005   ).sqrt()
     _snake_case							=				1
     _snake_case							=				13_591_409
     _snake_case							=				Decimal(_UpperCamelCase   )
     for k in range(1 ,						_UpperCamelCase   ):
          _snake_case							=				factorial(6 * k   ) // (factorial(3 * k   ) * factorial(_UpperCamelCase   ) ** 3)
          linear_term += 545_140_134
          exponential_term *= -262_537_412_640_768_000
          partial_sum += Decimal(multinomial_term * linear_term   ) / exponential_term
     return str(constant_term / partial_sum   )[:-1]


if __name__ == "__main__":
   UpperCamelCase_						:      Any       =						50
   print(F'The first {n} digits of pi is: {pi(n)}')


