

import gc
import unittest

from diffusers import FlaxDPMSolverMultistepScheduler, FlaxStableDiffusionPipeline
from diffusers.utils import is_flax_available, slow
from diffusers.utils.testing_utils import require_flax


if is_flax_available():
       import jax
       import jax.numpy as jnp
       from flax.jax_utils import replicate
       from flax.training.common_utils import shard







@slow
@require_flax
class 						__magic_name__			(							unittest.TestCase							):

   '''simple docstring'''




   def  _UpperCAmelCase (				self       )							->    Optional[int]:






     """simple docstring"""






     super().tearDown()
     gc.collect()



   def  _UpperCAmelCase (				self       )							->    Any:






     """simple docstring"""






     a__,      a__  =FlaxStableDiffusionPipeline.from_pretrained(
         '''stabilityai/stable-diffusion-2''',    revision='''bf16''',    dtype=jnp.bfloataa,    )

     a__  ='''A painting of a squirrel eating a burger'''
     a__  =jax.device_count()
     a__  =num_samples * [prompt]
     a__  =sd_pipe.prepare_inputs(lowercase_       )

     a__  =replicate(lowercase_       )
     a__  =shard(lowercase_       )

     a__  =jax.random.PRNGKey(0       )
     a__  =jax.random.split(lowercase_,    jax.device_count()       )

     a__  =sd_pipe(lowercase_,    lowercase_,    lowercase_,    num_inference_steps=25,    jit=lowercase_       )[0]
     assert images.shape == (jax.device_count(), 1, 768, 768, 3)

     a__  =images.reshape((images.shape[0] * images.shape[1],) + images.shape[-3:]       )
     a__  =images[0, 253:256, 253:256, -1]

     a__  =jnp.asarray(jax.device_get(image_slice.flatten()       )       )
     a__  =jnp.array([0.4238, 0.4414, 0.4395, 0.4453, 0.4629, 0.4590, 0.4531, 0.45508, 0.4512]       )
     print(F"""output_slice: {output_slice}"""       )
     assert jnp.abs(output_slice - expected_slice       ).max() < 1E-2



   def  _UpperCAmelCase (				self       )							->    Optional[Any]:






     """simple docstring"""






     a__  ='''stabilityai/stable-diffusion-2'''
     a__,      a__  =FlaxDPMSolverMultistepScheduler.from_pretrained(lowercase_,    subfolder='''scheduler'''       )
     a__,      a__  =FlaxStableDiffusionPipeline.from_pretrained(
         lowercase_,    scheduler=lowercase_,    revision='''bf16''',    dtype=jnp.bfloataa,    )
     a__  =scheduler_params

     a__  ='''A painting of a squirrel eating a burger'''
     a__  =jax.device_count()
     a__  =num_samples * [prompt]
     a__  =sd_pipe.prepare_inputs(lowercase_       )

     a__  =replicate(lowercase_       )
     a__  =shard(lowercase_       )

     a__  =jax.random.PRNGKey(0       )
     a__  =jax.random.split(lowercase_,    jax.device_count()       )

     a__  =sd_pipe(lowercase_,    lowercase_,    lowercase_,    num_inference_steps=25,    jit=lowercase_       )[0]
     assert images.shape == (jax.device_count(), 1, 768, 768, 3)

     a__  =images.reshape((images.shape[0] * images.shape[1],) + images.shape[-3:]       )
     a__  =images[0, 253:256, 253:256, -1]

     a__  =jnp.asarray(jax.device_get(image_slice.flatten()       )       )
     a__  =jnp.array([0.4336, 0.42969, 0.4453, 0.4199, 0.4297, 0.4531, 0.4434, 0.4434, 0.4297]       )
     print(F"""output_slice: {output_slice}"""       )
     assert jnp.abs(output_slice - expected_slice       ).max() < 1E-2



from __future__ import annotations




def 			UpperCAmelCase__				(			_A      : float	,      _A      : float	,      _A      : float	,      ):





  '''simple docstring'''







  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()
