


"""simple docstring"""


from dataclasses import dataclass
from typing import Dict, Optional, Tuple, Union

import torch
import torch.nn as nn

from ..configuration_utils import ConfigMixin, register_to_config
from ..utils import BaseOutput, apply_forward_hook
from .attention_processor import AttentionProcessor, AttnProcessor
from .modeling_utils import ModelMixin
from .vae import Decoder, DecoderOutput, DiagonalGaussianDistribution, Encoder
@dataclass
class   _UpperCamelCase  (   lowerCAmelCase__		):
							'''simple docstring'''







							__UpperCAmelCase						:    "DiagonalGaussianDistribution"
class   _UpperCamelCase  (   lowerCAmelCase__       ,lowerCAmelCase__		):
							'''simple docstring'''







							__UpperCAmelCase						:    Optional[Any]				      =True

							@register_to_config
							def __init__(     self    ,   __a = 3    ,   __a = 3    ,   __a = ("DownEncoderBlock2D",)    ,   __a = ("UpDecoderBlock2D",)    ,   __a = (64,)    ,   __a = 1    ,   __a = "silu"    ,   __a = 4    ,   __a = 32    ,   __a = 32    ,   __a = 0.1_8_2_1_5    ,   ):
										super().__init__()

										# pass init params to Encoder
										__lowerCAmelCase				    =			Encoder(
										    in_channels=__a    ,   out_channels=__a    ,   down_block_types=__a    ,   block_out_channels=__a    ,   layers_per_block=__a    ,   act_fn=__a    ,   norm_num_groups=__a    ,   double_z=__a    ,   )

										# pass init params to Decoder
										__lowerCAmelCase				    =			Decoder(
										    in_channels=__a    ,   out_channels=__a    ,   up_block_types=__a    ,   block_out_channels=__a    ,   layers_per_block=__a    ,   norm_num_groups=__a    ,   act_fn=__a    ,   )

										__lowerCAmelCase				    =			nn.Convad(2 * latent_channels    ,   2 * latent_channels    ,   1	)
										__lowerCAmelCase				    =			nn.Convad(__a    ,   __a    ,   1	)

										__lowerCAmelCase				    =			False
										__lowerCAmelCase				    =			False

										# only relevant if vae tiling is enabled
										__lowerCAmelCase				    =			self.config.sample_size
										__lowerCAmelCase				    =			(
										    self.config.sample_size[0]
										    if isinstance(self.config.sample_size    ,   (list, tuple)	)
										    else self.config.sample_size
										)
										__lowerCAmelCase				    =			int(sample_size / (2 ** (len(self.config.block_out_channels	) - 1))	)
										__lowerCAmelCase				    =			0.2_5

							def 			snake_case				(     self    ,   __a    ,   __a=False	):
										if isinstance(__a    ,   (Encoder, Decoder)	):
													__lowerCAmelCase				    =			value

							def 			snake_case				(     self    ,   __a = True	):
										__lowerCAmelCase				    =			use_tiling

							def 			snake_case				(     self	):
										self.enable_tiling(__a	)

							def 			snake_case				(     self	):
										__lowerCAmelCase				    =			True

							def 			snake_case				(     self	):
										__lowerCAmelCase				    =			False

							@property
							# Copied from diffusers.models.unet_2d_condition.UNet2DConditionModel.attn_processors
							def 			snake_case				(     self	):
										__lowerCAmelCase				    =			{}

										def fn_recursive_add_processors(__a    ,   __a    ,   __a	):
													if hasattr(__a    ,   "set_processor"	):
																__lowerCAmelCase				    =			module.processor

													for sub_name, child in module.named_children():
																fn_recursive_add_processors(f"{name}.{sub_name}"    ,   __a    ,   __a	)

													return processors

										for name, module in self.named_children():
													fn_recursive_add_processors(__a    ,   __a    ,   __a	)

										return processors

							def 			snake_case				(     self    ,   __a	):
										__lowerCAmelCase				    =			len(self.attn_processors.keys()	)

										if isinstance(__a    ,   __a	) and len(__a	) != count:
													raise ValueError(
													    f"A dict of processors was passed, but the number of processors {len(__a	)} does not match the"
													    f" number of attention layers: {count}. Please make sure to pass {count} processor classes."	)

										def fn_recursive_attn_processor(__a    ,   __a    ,   __a	):
													if hasattr(__a    ,   "set_processor"	):
																if not isinstance(__a    ,   __a	):
																			module.set_processor(__a	)
																else:
																			module.set_processor(processor.pop(f"{name}.processor"	)	)

													for sub_name, child in module.named_children():
																fn_recursive_attn_processor(f"{name}.{sub_name}"    ,   __a    ,   __a	)

										for name, module in self.named_children():
													fn_recursive_attn_processor(__a    ,   __a    ,   __a	)

							def 			snake_case				(     self	):
										self.set_attn_processor(AttnProcessor()	)

							@apply_forward_hook
							def 			snake_case				(     self    ,   __a    ,   __a = True	):
										if self.use_tiling and (x.shape[-1] > self.tile_sample_min_size or x.shape[-2] > self.tile_sample_min_size):
													return self.tiled_encode(__a    ,   return_dict=__a	)

										if self.use_slicing and x.shape[0] > 1:
													__lowerCAmelCase				    =			[self.encoder(__a	) for x_slice in x.split(1	)]
													__lowerCAmelCase				    =			torch.cat(__a	)
										else:
													__lowerCAmelCase				    =			self.encoder(__a	)

										__lowerCAmelCase				    =			self.quant_conv(__a	)
										__lowerCAmelCase				    =			DiagonalGaussianDistribution(__a	)

										if not return_dict:
													return (posterior,)

										return AutoencoderKLOutput(latent_dist=__a	)

							def 			snake_case				(     self    ,   __a    ,   __a = True	):
										if self.use_tiling and (z.shape[-1] > self.tile_latent_min_size or z.shape[-2] > self.tile_latent_min_size):
													return self.tiled_decode(__a    ,   return_dict=__a	)

										__lowerCAmelCase				    =			self.post_quant_conv(__a	)
										__lowerCAmelCase				    =			self.decoder(__a	)

										if not return_dict:
													return (dec,)

										return DecoderOutput(sample=__a	)

							@apply_forward_hook
							def 			snake_case				(     self    ,   __a    ,   __a = True	):
										if self.use_slicing and z.shape[0] > 1:
													__lowerCAmelCase				    =			[self._decode(__a	).sample for z_slice in z.split(1	)]
													__lowerCAmelCase				    =			torch.cat(__a	)
										else:
													__lowerCAmelCase				    =			self._decode(__a	).sample

										if not return_dict:
													return (decoded,)

										return DecoderOutput(sample=__a	)

							def 			snake_case				(     self    ,   __a    ,   __a    ,   __a	):
										__lowerCAmelCase				    =			min(a.shape[2]    ,   b.shape[2]    ,   __a	)
										for y in range(__a	):
													__lowerCAmelCase				    =			a[:, :, -blend_extent + y, :] * (1 - y / blend_extent) + b[:, :, y, :] * (y / blend_extent)
										return b

							def 			snake_case				(     self    ,   __a    ,   __a    ,   __a	):
										__lowerCAmelCase				    =			min(a.shape[3]    ,   b.shape[3]    ,   __a	)
										for x in range(__a	):
													__lowerCAmelCase				    =			a[:, :, :, -blend_extent + x] * (1 - x / blend_extent) + b[:, :, :, x] * (x / blend_extent)
										return b

							def 			snake_case				(     self    ,   __a    ,   __a = True	):
										__lowerCAmelCase				    =			int(self.tile_sample_min_size * (1 - self.tile_overlap_factor)	)
										__lowerCAmelCase				    =			int(self.tile_latent_min_size * self.tile_overlap_factor	)
										__lowerCAmelCase				    =			self.tile_latent_min_size - blend_extent

										# Split the image into 512x512 tiles and encode them separately.
										__lowerCAmelCase				    =			[]
										for i in range(0    ,   x.shape[2]    ,   __a	):
													__lowerCAmelCase				    =			[]
													for j in range(0    ,   x.shape[3]    ,   __a	):
																__lowerCAmelCase				    =			x[:, :, i : i + self.tile_sample_min_size, j : j + self.tile_sample_min_size]
																__lowerCAmelCase				    =			self.encoder(__a	)
																__lowerCAmelCase				    =			self.quant_conv(__a	)
																row.append(__a	)
													rows.append(__a	)
										__lowerCAmelCase				    =			[]
										for i, row in enumerate(__a	):
													__lowerCAmelCase				    =			[]
													for j, tile in enumerate(__a	):
																# blend the above tile and the left tile
																# to the current tile and add the current tile to the result row
																if i > 0:
																			__lowerCAmelCase				    =			self.blend_v(rows[i - 1][j]    ,   __a    ,   __a	)
																if j > 0:
																			__lowerCAmelCase				    =			self.blend_h(row[j - 1]    ,   __a    ,   __a	)
																result_row.append(tile[:, :, :row_limit, :row_limit]	)
													result_rows.append(torch.cat(__a    ,   dim=3	)	)

										__lowerCAmelCase				    =			torch.cat(__a    ,   dim=2	)
										__lowerCAmelCase				    =			DiagonalGaussianDistribution(__a	)

										if not return_dict:
													return (posterior,)

										return AutoencoderKLOutput(latent_dist=__a	)

							def 			snake_case				(     self    ,   __a    ,   __a = True	):
										__lowerCAmelCase				    =			int(self.tile_latent_min_size * (1 - self.tile_overlap_factor)	)
										__lowerCAmelCase				    =			int(self.tile_sample_min_size * self.tile_overlap_factor	)
										__lowerCAmelCase				    =			self.tile_sample_min_size - blend_extent

										# Split z into overlapping 64x64 tiles and decode them separately.
										# The tiles have an overlap to avoid seams between tiles.
										__lowerCAmelCase				    =			[]
										for i in range(0    ,   z.shape[2]    ,   __a	):
													__lowerCAmelCase				    =			[]
													for j in range(0    ,   z.shape[3]    ,   __a	):
																__lowerCAmelCase				    =			z[:, :, i : i + self.tile_latent_min_size, j : j + self.tile_latent_min_size]
																__lowerCAmelCase				    =			self.post_quant_conv(__a	)
																__lowerCAmelCase				    =			self.decoder(__a	)
																row.append(__a	)
													rows.append(__a	)
										__lowerCAmelCase				    =			[]
										for i, row in enumerate(__a	):
													__lowerCAmelCase				    =			[]
													for j, tile in enumerate(__a	):
																# blend the above tile and the left tile
																# to the current tile and add the current tile to the result row
																if i > 0:
																			__lowerCAmelCase				    =			self.blend_v(rows[i - 1][j]    ,   __a    ,   __a	)
																if j > 0:
																			__lowerCAmelCase				    =			self.blend_h(row[j - 1]    ,   __a    ,   __a	)
																result_row.append(tile[:, :, :row_limit, :row_limit]	)
													result_rows.append(torch.cat(__a    ,   dim=3	)	)

										__lowerCAmelCase				    =			torch.cat(__a    ,   dim=2	)
										if not return_dict:
													return (dec,)

										return DecoderOutput(sample=__a	)



							def 			snake_case				(     self    ,   __a    ,   __a = False    ,   __a = True    ,   __a = None    ,   ):
										__lowerCAmelCase				    =			sample
										__lowerCAmelCase				    =			self.encode(__a	).latent_dist
										if sample_posterior:
													__lowerCAmelCase				    =			posterior.sample(generator=__a	)
										else:
													__lowerCAmelCase				    =			posterior.mode()
										__lowerCAmelCase				    =			self.decode(__a	).sample

										if not return_dict:
													return (dec,)

										return DecoderOutput(sample=__a	)











"""simple docstring"""
import qiskit



def      __lowerCamelCase   (							a_     :		int ,   a_     :		int							)			->      qiskit.result.counts.Counts:
      __SCREAMING_SNAKE_CASE   :Tuple						=  qiskit.Aer.get_backend('''aer_simulator'''							)

      # Create a Quantum Circuit acting on the q register
      __SCREAMING_SNAKE_CASE   :Union[str, Any]						=  qiskit.QuantumCircuit(a_ ,   a_							)

      # Apply X (NOT) Gate to Qubits 0 & 1
      circuit.x(0							)
      circuit.x(1							)

      # Map the quantum measurement to the classical bits
      circuit.measure([0, 1] ,   [0, 1]							)

      # Execute the circuit on the qasm simulator
      __SCREAMING_SNAKE_CASE   :Tuple						=  qiskit.execute(a_ ,   a_ ,   shots=10_00							)

      # Return the histogram data of the results of the experiment.
      return job.result().get_counts(a_							)


if __name__ == "__main__":
  lowerCamelCase_								=		single_qubit_measure(2, 2)
  print(f'Total count for various states are: {counts}')