"""simple docstring"""






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 					_A		(			unittest.TestCase      ):

      def 							A__			(		self		):







            """simple docstring"""



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

      def 							A__			(		self		):







            """simple docstring"""



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

            lowercase								=      """A painting of a squirrel eating a burger"""
            lowercase								=      jax.device_count()
            lowercase								=      num_samples * [prompt]
            lowercase								=      sd_pipe.prepare_inputs(__lowerCAmelCase		)

            lowercase								=      replicate(__lowerCAmelCase		)
            lowercase								=      shard(__lowerCAmelCase		)

            lowercase								=      jax.random.PRNGKey(0		)
            lowercase								=      jax.random.split(__lowerCAmelCase						,			jax.device_count()		)

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

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

            lowercase								=      jnp.asarray(jax.device_get(image_slice.flatten()		)		)
            lowercase								=      jnp.array([0.4_2_3_8, 0.4_4_1_4, 0.4_3_9_5, 0.4_4_5_3, 0.4_6_2_9, 0.4_5_9_0, 0.4_5_3_1, 0.4_5_5_0_8, 0.4_5_1_2]		)
            print(f'output_slice: {output_slice}'		)
            assert jnp.abs(output_slice - expected_slice		).max() < 1E-2







      def 							A__			(		self		):







            """simple docstring"""



            lowercase								=      """stabilityai/stable-diffusion-2"""
            lowercase				,				lowercase								=      FlaxDPMSolverMultistepScheduler.from_pretrained(__lowerCAmelCase						,			subfolder="""scheduler"""		)
            lowercase				,				lowercase								=      FlaxStableDiffusionPipeline.from_pretrained(
                __lowerCAmelCase						,			scheduler=__lowerCAmelCase						,			revision="""bf16"""						,			dtype=jnp.bfloataa						,			)
            lowercase								=      scheduler_params

            lowercase								=      """A painting of a squirrel eating a burger"""
            lowercase								=      jax.device_count()
            lowercase								=      num_samples * [prompt]
            lowercase								=      sd_pipe.prepare_inputs(__lowerCAmelCase		)

            lowercase								=      replicate(__lowerCAmelCase		)
            lowercase								=      shard(__lowerCAmelCase		)

            lowercase								=      jax.random.PRNGKey(0		)
            lowercase								=      jax.random.split(__lowerCAmelCase						,			jax.device_count()		)

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

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

            lowercase								=      jnp.asarray(jax.device_get(image_slice.flatten()		)		)
            lowercase								=      jnp.array([0.4_3_3_6, 0.4_2_9_6_9, 0.4_4_5_3, 0.4_1_9_9, 0.4_2_9_7, 0.4_5_3_1, 0.4_4_3_4, 0.4_4_3_4, 0.4_2_9_7]		)
            print(f'output_slice: {output_slice}'		)
            assert jnp.abs(output_slice - expected_slice		).max() < 1E-2




"""simple docstring"""






def      UpperCAmelCase__			(							lowerCAmelCase__	:int = 1_0**9						)					->       int:
      '''simple docstring'''


      lowercase								=      1
      lowercase								=      2

      lowercase								=      0
      lowercase								=      0
      lowercase								=      0
      while perimeter <= max_perimeter:
            perimeters_sum += perimeter

            prev_value += 2 * value
            value += prev_value

            lowercase								=      2 * value + 2 if i % 2 == 0 else 2 * value - 2
            i += 1

      return perimeters_sum


if __name__ == "__main__":
       print(F"""{solution() = }""")



