




"""simple docstring"""

import gc
import unittest

import numpy as np
import torch

from diffusers import StableDiffusionKDiffusionPipeline
from diffusers.utils import slow, torch_device
from diffusers.utils.testing_utils import enable_full_determinism, require_torch_gpu


enable_full_determinism()

@slow
@require_torch_gpu
class        lowercase      (    unittest.TestCase):







				def 					a_  (							self   :					Any       ):



					"""simple docstring"""

					super().tearDown()
					gc.collect()
					torch.cuda.empty_cache()







				def 					a_  (							self   :					Any       ):



					"""simple docstring"""

					A_  :				Optional[Any]	   =		StableDiffusionKDiffusionPipeline.from_pretrained('''CompVis/stable-diffusion-v1-4'''       )
					A_  :				Optional[Any]	   =		sd_pipe.to(_lowerCamelCase       )
					sd_pipe.set_progress_bar_config(disable=_lowerCamelCase       )

					sd_pipe.set_scheduler('''sample_euler'''       )

					A_  :				int	   =		'''A painting of a squirrel eating a burger'''
					A_  :				Optional[int]	   =		torch.manual_seed(0       )
					A_  :				Optional[Any]	   =		sd_pipe([prompt]      ,     generator=_lowerCamelCase      ,     guidance_scale=9.0      ,     num_inference_steps=20      ,     output_type='''np'''       )

					A_  :				List[str]	   =		output.images

					A_  :				Any	   =		image[0, -3:, -3:, -1]

					assert image.shape == (1, 5_12, 5_12, 3)
					A_  :				List[Any]	   =		np.array([0.0447, 0.0492, 0.0468, 0.0408, 0.0383, 0.0408, 0.0354, 0.0380, 0.0339]       )

					assert np.abs(image_slice.flatten() - expected_slice       ).max() < 1E-2







				def 					a_  (							self   :					Optional[int]       ):



					"""simple docstring"""

					A_  :				List[Any]	   =		StableDiffusionKDiffusionPipeline.from_pretrained('''stabilityai/stable-diffusion-2-1-base'''       )
					A_  :				Optional[int]	   =		sd_pipe.to(_lowerCamelCase       )
					sd_pipe.set_progress_bar_config(disable=_lowerCamelCase       )

					sd_pipe.set_scheduler('''sample_euler'''       )

					A_  :				Union[str, Any]	   =		'''A painting of a squirrel eating a burger'''
					A_  :				str	   =		torch.manual_seed(0       )
					A_  :				int	   =		sd_pipe([prompt]      ,     generator=_lowerCamelCase      ,     guidance_scale=9.0      ,     num_inference_steps=20      ,     output_type='''np'''       )

					A_  :				List[str]	   =		output.images

					A_  :				List[Any]	   =		image[0, -3:, -3:, -1]

					assert image.shape == (1, 5_12, 5_12, 3)
					A_  :				Optional[Any]	   =		np.array([0.1237, 0.1320, 0.1438, 0.1359, 0.1390, 0.1132, 0.1277, 0.1175, 0.1112]       )

					assert np.abs(image_slice.flatten() - expected_slice       ).max() < 5E-1







				def 					a_  (							self   :					Optional[int]       ):



					"""simple docstring"""

					A_  :				List[str]	   =		StableDiffusionKDiffusionPipeline.from_pretrained('''stabilityai/stable-diffusion-2-1-base'''       )
					A_  :				List[Any]	   =		sd_pipe.to(_lowerCamelCase       )
					sd_pipe.set_progress_bar_config(disable=_lowerCamelCase       )

					sd_pipe.set_scheduler('''sample_dpmpp_2m'''       )

					A_  :				Union[str, Any]	   =		'''A painting of a squirrel eating a burger'''
					A_  :				int	   =		torch.manual_seed(0       )
					A_  :				int	   =		sd_pipe(
					    [prompt]      ,     generator=_lowerCamelCase      ,     guidance_scale=7.5      ,     num_inference_steps=15      ,     output_type='''np'''      ,     use_karras_sigmas=_lowerCamelCase      ,     )

					A_  :				Any	   =		output.images

					A_  :				Dict	   =		image[0, -3:, -3:, -1]

					assert image.shape == (1, 5_12, 5_12, 3)
					A_  :				Union[str, Any]	   =		np.array(
					    [0.11381689, 0.12112921, 0.1389457, 0.12549606, 0.1244964, 0.10831517, 0.11562866, 0.10867816, 0.10499048]       )

					assert np.abs(image_slice.flatten() - expected_slice       ).max() < 1E-2











"""simple docstring"""

from queue import PriorityQueue
from typing import Any

import numpy as np

def 		lowercase_      (		_UpperCAmelCase  ,      _UpperCAmelCase  ,      _UpperCAmelCase  ,      _UpperCAmelCase  ,      _UpperCAmelCase  ,      _UpperCAmelCase  ,      _UpperCAmelCase  ,      _UpperCAmelCase  ,      _UpperCAmelCase  ,      ):




	"""simple docstring"""






	for nxt, d in graph[v]:
		if nxt in visited_forward:
			continue
		A_  :				Tuple	   =		cst_fwd.get(_UpperCAmelCase  ,      np.inf	)
		A_  :				Any	   =		cst_fwd[v] + d
		if new_cost_f < old_cost_f:
			queue.put((new_cost_f, nxt)	)
			A_  :				Tuple	   =		new_cost_f
			A_  :				Dict	   =		v
		if nxt in visited_backward:
			if cst_fwd[v] + d + cst_bwd[nxt] < shortest_distance:
				A_  :				Optional[Any]	   =		cst_fwd[v] + d + cst_bwd[nxt]
	return shortest_distance

def 		lowercase_      (		_UpperCAmelCase  ,      _UpperCAmelCase  ,      _UpperCAmelCase  ,      _UpperCAmelCase	):




	"""simple docstring"""






	A_  :				Tuple	   =		-1

	A_  :				Any	   =		set()
	A_  :				Tuple	   =		set()
	A_  :				Optional[int]	   =		{source: 0}
	A_  :				Dict	   =		{destination: 0}
	A_  :				Any	   =		{source: None}
	A_  :				Optional[Any]	   =		{destination: None}
	A_  :				PriorityQueue[Any]	   =		PriorityQueue()
	A_  :				PriorityQueue[Any]	   =		PriorityQueue()

	A_  :				Union[str, Any]	   =		np.inf

	queue_forward.put((0, source)	)
	queue_backward.put((0, destination)	)

	if source == destination:
		return 0

	while not queue_forward.empty() and not queue_backward.empty():
		A_   , A_  :				Union[str, Any]	   =		queue_forward.get()
		visited_forward.add(_UpperCAmelCase	)

		A_   , A_  :				Optional[int]	   =		queue_backward.get()
		visited_backward.add(_UpperCAmelCase	)

		A_  :				Any	   =		pass_and_relaxation(
		    _UpperCAmelCase  ,      _UpperCAmelCase  ,      _UpperCAmelCase  ,      _UpperCAmelCase  ,      _UpperCAmelCase  ,      _UpperCAmelCase  ,      _UpperCAmelCase  ,      _UpperCAmelCase  ,      _UpperCAmelCase  ,      )

		A_  :				Dict	   =		pass_and_relaxation(
		    _UpperCAmelCase  ,      _UpperCAmelCase  ,      _UpperCAmelCase  ,      _UpperCAmelCase  ,      _UpperCAmelCase  ,      _UpperCAmelCase  ,      _UpperCAmelCase  ,      _UpperCAmelCase  ,      _UpperCAmelCase  ,      )

		if cst_fwd[v_fwd] + cst_bwd[v_bwd] >= shortest_distance:
			break

	if shortest_distance != np.inf:
		A_  :				Optional[Any]	   =		shortest_distance
	return shortest_path_distance


_lowerCamelCase  :			Optional[Any]        =       {
    'B': [['C', 1]],
    'C': [['D', 1]],
    'D': [['F', 1]],
    'E': [['B', 1], ['G', 2]],
    'F': [],
    'G': [['F', 1]],
}
_lowerCamelCase  :			Any        =       {
    'B': [['E', 1]],
    'C': [['B', 1]],
    'D': [['C', 1]],
    'F': [['D', 1], ['G', 1]],
    'E': [[None, np.inf]],
    'G': [['E', 2]],
}

if __name__ == "__main__":
		import doctest

		doctest.testmod()





