"""simple docstring"""





import os
from typing import Any, Callable, Dict, List, Optional, Tuple, Union

import torch
from torch import nn

from ...models.controlnet import ControlNetModel, ControlNetOutput
from ...models.modeling_utils import ModelMixin
from ...utils import logging


lowerCAmelCase_     =	logging.get_logger(__name__)




class  _snake_case		(    __snake_case ):







				"""simple docstring"""






				def __init__(      self							:							List[Any]      ,    _A							:							Union[List[ControlNetModel], Tuple[ControlNetModel]]):



											"""simple docstring"""







											super().__init__()
											_SCREAMING_SNAKE_CASE		:						Dict			  =    nn.ModuleList(_A)





				def 		_lowerCAmelCase		(      self							:							List[Any]      ,    _A							:							torch.FloatTensor      ,    _A							:							Union[torch.Tensor, float, int]      ,    _A							:							torch.Tensor      ,    _A							:							List[torch.tensor]      ,    _A							:							List[float]      ,    _A							:							Optional[torch.Tensor] = None      ,    _A							:							Optional[torch.Tensor] = None      ,    _A							:							Optional[torch.Tensor] = None      ,    _A							:							Optional[Dict[str, Any]] = None      ,    _A							:							bool = False      ,    _A							:							bool = True      ,    ):



											"""simple docstring"""







											for i, (image, scale, controlnet) in enumerate(zip(_A      ,    _A      ,    self.nets)):
																		_SCREAMING_SNAKE_CASE  ,				_SCREAMING_SNAKE_CASE		:						int			  =    controlnet(
																		    _A      ,    _A      ,    _A      ,    _A      ,    _A      ,    _A      ,    _A      ,    _A      ,    _A      ,    _A      ,    _A      ,    )

																		# merge samples
																		if i == 0:
																									_SCREAMING_SNAKE_CASE  ,				_SCREAMING_SNAKE_CASE		:						Union[str, Any]			  =    down_samples, mid_sample
																		else:
																									_SCREAMING_SNAKE_CASE		:						int			  =    [
																									    samples_prev + samples_curr
																									    for samples_prev, samples_curr in zip(_A      ,    _A)
																									]
																									mid_block_res_sample += mid_sample

											return down_block_res_samples, mid_block_res_sample





				def 		_lowerCAmelCase		(      self							:							Any      ,    _A							:							Union[str, os.PathLike]      ,    _A							:							bool = True      ,    _A							:							Callable = None      ,    _A							:							bool = False      ,    _A							:							Optional[str] = None      ,    ):



											"""simple docstring"""







											_SCREAMING_SNAKE_CASE		:						Tuple			  =    0
											_SCREAMING_SNAKE_CASE		:						int			  =    save_directory
											for controlnet in self.nets:
																		controlnet.save_pretrained(
																		    _A      ,    is_main_process=_A      ,    save_function=_A      ,    safe_serialization=_A      ,    variant=_A      ,    )

																		idx += 1
																		_SCREAMING_SNAKE_CASE		:						int			  =    model_path_to_save + f"""_{idx}"""





				@classmethod
				def 		_lowerCAmelCase		(      cls							:							Optional[Any]      ,    _A							:							Optional[Union[str, os.PathLike]]      ,    **_A							:							Optional[int]):



											"""simple docstring"""







											_SCREAMING_SNAKE_CASE		:						List[Any]			  =    0
											_SCREAMING_SNAKE_CASE		:						Optional[int]			  =    []

											# load controlnet and append to list until no controlnet directory exists anymore
											# first controlnet has to be saved under `./mydirectory/controlnet` to be compliant with `DiffusionPipeline.from_prertained`
											# second, third, ... controlnets have to be saved under `./mydirectory/controlnet_1`, `./mydirectory/controlnet_2`, ...
											_SCREAMING_SNAKE_CASE		:						Optional[int]			  =    pretrained_model_path
											while os.path.isdir(_A):
																		_SCREAMING_SNAKE_CASE		:						List[str]			  =    ControlNetModel.from_pretrained(_A      ,    **_A)
																		controlnets.append(_A)

																		idx += 1
																		_SCREAMING_SNAKE_CASE		:						Optional[Any]			  =    pretrained_model_path + f"""_{idx}"""

											logger.info(f"""{len(_A)} controlnets loaded from {pretrained_model_path}.""")

											if len(_A) == 0:
																		raise ValueError(
																		    f"""No ControlNets found under {os.path.dirname(_A)}. Expected at least {pretrained_model_path + "_0"}.""")

											return cls(_A)



"""simple docstring"""





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



def      lowerCamelCase_(__SCREAMING_SNAKE_CASE  )->    str:

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

							_SCREAMING_SNAKE_CASE		:						int			  =    precision
							_SCREAMING_SNAKE_CASE		:						Dict			  =    ceil(precision / 14  )
							_SCREAMING_SNAKE_CASE		:						int			  =    426_880 * Decimal(10_005  ).sqrt()
							_SCREAMING_SNAKE_CASE		:						Union[str, Any]			  =    1
							_SCREAMING_SNAKE_CASE		:						str			  =    13_591_409
							_SCREAMING_SNAKE_CASE		:						Tuple			  =    Decimal(__SCREAMING_SNAKE_CASE  )
							for k in range(1     ,	__SCREAMING_SNAKE_CASE  ):
														_SCREAMING_SNAKE_CASE		:						Tuple			  =    factorial(6 * k  ) // (factorial(3 * k  ) * factorial(__SCREAMING_SNAKE_CASE  ) ** 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__":
			lowerCAmelCase_     =	50
			print(F"The first {n} digits of pi is: {pi(n)}")


