



'''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       UpperCamelCase_    (					self   :							Tuple					):







							'''simple docstring'''
							# clean up the VRAM after each test
							super().tearDown()
							gc.collect()
							torch.cuda.empty_cache()





	def       UpperCamelCase_    (					self   :							Optional[Any]					):







							'''simple docstring'''
							_UpperCamelCase   :						List[str]												=  StableDiffusionKDiffusionPipeline.from_pretrained('CompVis/stable-diffusion-v1-4'					)
							_UpperCamelCase   :						Optional[int]												=  sd_pipe.to(lowerCamelCase__					)
							sd_pipe.set_progress_bar_config(disable=lowerCamelCase__					)

							sd_pipe.set_scheduler('sample_euler'					)

							_UpperCamelCase   :						Dict												=  'A painting of a squirrel eating a burger'
							_UpperCamelCase   :						Tuple												=  torch.manual_seed(0					)
							_UpperCamelCase   :						List[str]												=  sd_pipe([prompt]					,generator=lowerCamelCase__					,guidance_scale=9.0					,num_inference_steps=20					,output_type='np'					)

							_UpperCamelCase   :						Any												=  output.images

							_UpperCamelCase   :						Optional[int]												=  image[0, -3:, -3:, -1]

							assert image.shape == (1, 512, 512, 3)
							_UpperCamelCase   :						List[str]												=  np.array([0.0_4_4_7, 0.0_4_9_2, 0.0_4_6_8, 0.0_4_0_8, 0.0_3_8_3, 0.0_4_0_8, 0.0_3_5_4, 0.0_3_8_0, 0.0_3_3_9]					)

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





	def       UpperCamelCase_    (					self   :							Any					):







							'''simple docstring'''
							_UpperCamelCase   :						Optional[Any]												=  StableDiffusionKDiffusionPipeline.from_pretrained('stabilityai/stable-diffusion-2-1-base'					)
							_UpperCamelCase   :						Optional[Any]												=  sd_pipe.to(lowerCamelCase__					)
							sd_pipe.set_progress_bar_config(disable=lowerCamelCase__					)

							sd_pipe.set_scheduler('sample_euler'					)

							_UpperCamelCase   :						Dict												=  'A painting of a squirrel eating a burger'
							_UpperCamelCase   :						List[Any]												=  torch.manual_seed(0					)
							_UpperCamelCase   :						str												=  sd_pipe([prompt]					,generator=lowerCamelCase__					,guidance_scale=9.0					,num_inference_steps=20					,output_type='np'					)

							_UpperCamelCase   :						Dict												=  output.images

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

							assert image.shape == (1, 512, 512, 3)
							_UpperCamelCase   :						List[str]												=  np.array([0.1_2_3_7, 0.1_3_2_0, 0.1_4_3_8, 0.1_3_5_9, 0.1_3_9_0, 0.1_1_3_2, 0.1_2_7_7, 0.1_1_7_5, 0.1_1_1_2]					)

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





	def       UpperCamelCase_    (					self   :							Optional[Any]					):







							'''simple docstring'''
							_UpperCamelCase   :						Optional[Any]												=  StableDiffusionKDiffusionPipeline.from_pretrained('stabilityai/stable-diffusion-2-1-base'					)
							_UpperCamelCase   :						Optional[int]												=  sd_pipe.to(lowerCamelCase__					)
							sd_pipe.set_progress_bar_config(disable=lowerCamelCase__					)

							sd_pipe.set_scheduler('sample_dpmpp_2m'					)

							_UpperCamelCase   :						Optional[Any]												=  'A painting of a squirrel eating a burger'
							_UpperCamelCase   :						Tuple												=  torch.manual_seed(0					)
							_UpperCamelCase   :						List[str]												=  sd_pipe(
							    [prompt]					,generator=lowerCamelCase__					,guidance_scale=7.5					,num_inference_steps=15					,output_type='np'					,use_karras_sigmas=lowerCamelCase__					,)

							_UpperCamelCase   :						Optional[int]												=  output.images

							_UpperCamelCase   :						str												=  image[0, -3:, -3:, -1]

							assert image.shape == (1, 512, 512, 3)
							_UpperCamelCase   :						Any												=  np.array(
							    [0.1_1_3_8_1_6_8_9, 0.1_2_1_1_2_9_2_1, 0.1_3_8_9_4_5_7, 0.1_2_5_4_9_6_0_6, 0.1_2_4_4_9_6_4, 0.1_0_8_3_1_5_1_7, 0.1_1_5_6_2_8_6_6, 0.1_0_8_6_7_8_1_6, 0.1_0_4_9_9_0_4_8]					)

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







'''simple docstring'''
from __future__ import annotations






def A__       (	UpperCAmelCase_    ,    UpperCAmelCase_				):
						_UpperCamelCase							,     _UpperCamelCase   :						Dict												=  position
						_UpperCamelCase   :						Any												=  [
						    (y + 1, x + 2),
						    (y - 1, x + 2),
						    (y + 1, x - 2),
						    (y - 1, x - 2),
						    (y + 2, x + 1),
						    (y + 2, x - 1),
						    (y - 2, x + 1),
						    (y - 2, x - 1),
						]
						_UpperCamelCase   :						Optional[Any]												=  []

						for position in positions:
												_UpperCamelCase							,     _UpperCamelCase   :						Any												=  position
												if 0 <= y_test < n and 0 <= x_test < n:
																		permissible_positions.append(UpperCAmelCase_				)

						return permissible_positions






def A__       (	UpperCAmelCase_				):
						return not any(elem == 0 for row in board for elem in row				)






def A__       (	UpperCAmelCase_    ,    UpperCAmelCase_    ,    UpperCAmelCase_				):

						if is_complete(UpperCAmelCase_				):
												return True

						for position in get_valid_pos(UpperCAmelCase_    ,    len(UpperCAmelCase_				)				):
												_UpperCamelCase							,     _UpperCamelCase   :						Any												=  position

												if board[y][x] == 0:
																		_UpperCamelCase   :						int												=  curr + 1
																		if open_knight_tour_helper(UpperCAmelCase_    ,    UpperCAmelCase_    ,    curr + 1				):
																								return True
																		_UpperCamelCase   :						Union[str, Any]												=  0

						return False






def A__       (	UpperCAmelCase_				):
						_UpperCamelCase   :						Dict												=  [[0 for i in range(UpperCAmelCase_				)] for j in range(UpperCAmelCase_				)]

						for i in range(UpperCAmelCase_				):
												for j in range(UpperCAmelCase_				):
																		_UpperCamelCase   :						Tuple												=  1
																		if open_knight_tour_helper(UpperCAmelCase_    ,    (i, j)    ,    1				):
																								return board
																		_UpperCamelCase   :						Union[str, Any]												=  0

						_UpperCamelCase   :						int												=  f'Open Kight Tour cannot be performed on a board of size {n}'
						raise ValueError(UpperCAmelCase_				)


if __name__ == "__main__":
					import doctest

					doctest.testmod()


