






from __future__ import annotations


def   _A   (				SCREAMING_SNAKE_CASE__  :	float     ,  SCREAMING_SNAKE_CASE__  :	float     ,  SCREAMING_SNAKE_CASE__  :	float     ,  ):







    if (electron_conc, hole_conc, intrinsic_conc).count(0       ) != 1:
        raise ValueError('''You cannot supply more or less than 2 values'''       )
    elif electron_conc < 0:
        raise ValueError('''Electron concentration cannot be negative in a semiconductor'''       )
    elif hole_conc < 0:
        raise ValueError('''Hole concentration cannot be negative in a semiconductor'''       )
    elif intrinsic_conc < 0:
        raise ValueError(
            '''Intrinsic concentration cannot be negative in a semiconductor'''       )
    elif electron_conc == 0:
        return (
            "electron_conc",
            intrinsic_conc**2 / hole_conc,
        )
    elif hole_conc == 0:
        return (
            "hole_conc",
            intrinsic_conc**2 / electron_conc,
        )
    elif intrinsic_conc == 0:
        return (
            "intrinsic_conc",
            (electron_conc * hole_conc) ** 0.5,
        )
    else:
        return (-1, -1)


if __name__ == "__main__":
 import doctest

 doctest.testmod()






'''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


__SCREAMING_SNAKE_CASE       :     str     =  logging.get_logger(__name__)

class 	lowerCamelCase_	(snake_case__    ):
      '''simple docstring'''

      def __init__(       self						:				Optional[int]						,					A						:				Union[List[ControlNetModel], Tuple[ControlNetModel]]       ):
             super().__init__()
             _UpperCAmelCase     :  Optional[int]							      =    nn.ModuleList(A       )




      def      _A	(       self						:				Dict						,					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						,					):
             for i, (image, scale, controlnet) in enumerate(zip(A						,					A						,					self.nets       )       ):
                    _UpperCAmelCase      ,  _UpperCAmelCase     :  str							      =    controlnet(
                        A						,					A						,					A						,					A						,					A						,					A						,					A						,					A						,					A						,					A						,					A						,					)

                    # merge samples
                    if i == 0:
                           _UpperCAmelCase      ,  _UpperCAmelCase     :  List[Any]							      =    down_samples, mid_sample
                    else:
                           _UpperCAmelCase     :  Optional[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      _A	(       self						:				List[str]						,					A						:				Union[str, os.PathLike]						,					A						:				bool = True						,					A						:				Callable = None						,					A						:				bool = False						,					A						:				Optional[str] = None						,					):
             _UpperCAmelCase     :  str							      =    0
             _UpperCAmelCase     :  str							      =    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
                    _UpperCAmelCase     :  Tuple							      =    model_path_to_save + F"""_{idx}"""





      @classmethod
      def      _A	(       cls						:				int						,					A						:				Optional[Union[str, os.PathLike]]						,					**A						:				Tuple       ):
             _UpperCAmelCase     :  str							      =    0
             _UpperCAmelCase     :  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`, ...
             _UpperCAmelCase     :  int							      =    pretrained_model_path
             while os.path.isdir(A       ):
                    _UpperCAmelCase     :  List[str]							      =    ControlNetModel.from_pretrained(A						,					**A       )
                    controlnets.append(A       )

                    idx += 1
                    _UpperCAmelCase     :  Dict							      =    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       )

