
'''simple docstring'''
import gc
import inspect
import unittest

import torch
from parameterized import parameterized

from diffusers import PriorTransformer
from diffusers.utils import floats_tensor, slow, torch_all_close, torch_device
from diffusers.utils.testing_utils import enable_full_determinism

from .test_modeling_common import ModelTesterMixin


enable_full_determinism()


class       _lowerCAmelCase   (   __snake_case					,							unittest.TestCase				):







							'''simple docstring'''

							lowerCAmelCase_ 						=						PriorTransformer
							lowerCAmelCase_ 						=						"hidden_states"

							@property
							def 	lowercase							(self  )					->       Any:
														_snake_case       =  4
														_snake_case       =  8
														_snake_case       =  7

														_snake_case       =  floats_tensor((batch_size, embedding_dim)  ).to(UpperCAmelCase  )

														_snake_case       =  floats_tensor((batch_size, embedding_dim)  ).to(UpperCAmelCase  )
														_snake_case       =  floats_tensor((batch_size, num_embeddings, embedding_dim)  ).to(UpperCAmelCase  )

														return {
														    "hidden_states": hidden_states,
														    "timestep": 2,
														    "proj_embedding": proj_embedding,
														    "encoder_hidden_states": encoder_hidden_states,
														}

							def 	lowercase							(self  ,  UpperCAmelCase=0  )					->       Union[str, Any]:
														torch.manual_seed(UpperCAmelCase  )
														_snake_case       =  4
														_snake_case       =  8
														_snake_case       =  7

														_snake_case       =  torch.randn((batch_size, embedding_dim)  ).to(UpperCAmelCase  )

														_snake_case       =  torch.randn((batch_size, embedding_dim)  ).to(UpperCAmelCase  )
														_snake_case       =  torch.randn((batch_size, num_embeddings, embedding_dim)  ).to(UpperCAmelCase  )

														return {
														    "hidden_states": hidden_states,
														    "timestep": 2,
														    "proj_embedding": proj_embedding,
														    "encoder_hidden_states": encoder_hidden_states,
														}

							@property
							def 	lowercase							(self  )					->       Dict:
														return (4, 8)

							@property
							def 	lowercase							(self  )					->       Any:
														return (4, 8)

							def 	lowercase							(self  )					->       Optional[int]:
														_snake_case       =  {
														    """num_attention_heads""": 2,
														    """attention_head_dim""": 4,
														    """num_layers""": 2,
														    """embedding_dim""": 8,
														    """num_embeddings""": 7,
														    """additional_embeddings""": 4,
														}
														_snake_case       =  self.dummy_input
														return init_dict, inputs_dict

							def 	lowercase							(self  )					->       Dict:
														_snake_case,							_snake_case       =  PriorTransformer.from_pretrained(
														    """hf-internal-testing/prior-dummy"""  ,  output_loading_info=UpperCAmelCase  )
														self.assertIsNotNone(UpperCAmelCase  )
														self.assertEqual(len(loading_info["""missing_keys"""]  )  ,  0  )

														model.to(UpperCAmelCase  )
														_snake_case       =  model(**self.dummy_input  )[0]

														assert hidden_states is not None, "Make sure output is not None"

							def 	lowercase							(self  )					->       Any:
														_snake_case,							_snake_case       =  self.prepare_init_args_and_inputs_for_common()

														_snake_case       =  self.model_class(**UpperCAmelCase  )
														_snake_case       =  inspect.signature(model.forward  )
														# signature.parameters is an OrderedDict => so arg_names order is deterministic
														_snake_case       =  [*signature.parameters.keys()]

														_snake_case       =  ["""hidden_states""", """timestep"""]
														self.assertListEqual(arg_names[:2]  ,  UpperCAmelCase  )





							def 	lowercase							(self  )					->       Optional[Any]:
														_snake_case       =  PriorTransformer.from_pretrained("""hf-internal-testing/prior-dummy"""  )
														_snake_case       =  model.to(UpperCAmelCase  )

														if hasattr(UpperCAmelCase  ,  """set_default_attn_processor"""  ):
																					model.set_default_attn_processor()

														_snake_case       =  self.get_dummy_seed_input()

														with torch.no_grad():
																					_snake_case       =  model(**UpperCAmelCase  )[0]

														_snake_case       =  output[0, :5].flatten().cpu()
														print(UpperCAmelCase  )

														# Since the VAE Gaussian prior's generator is seeded on the appropriate device,
														# the expected output slices are not the same for CPU and GPU.
														_snake_case       =  torch.tensor([-1.3436, -0.2870, 0.7538, 0.4368, -0.0239]  )
														self.assertTrue(torch_all_close(UpperCAmelCase  ,  UpperCAmelCase  ,  rtol=1e-2  )  )


@slow
class       _lowerCAmelCase   (   unittest.TestCase				):







							'''simple docstring'''

							def 	lowercase							(self  ,  UpperCAmelCase=1  ,  UpperCAmelCase=768  ,  UpperCAmelCase=77  ,  UpperCAmelCase=0  )					->       Optional[int]:
														torch.manual_seed(UpperCAmelCase  )
														_snake_case       =  batch_size
														_snake_case       =  embedding_dim
														_snake_case       =  num_embeddings

														_snake_case       =  torch.randn((batch_size, embedding_dim)  ).to(UpperCAmelCase  )

														_snake_case       =  torch.randn((batch_size, embedding_dim)  ).to(UpperCAmelCase  )
														_snake_case       =  torch.randn((batch_size, num_embeddings, embedding_dim)  ).to(UpperCAmelCase  )

														return {
														    "hidden_states": hidden_states,
														    "timestep": 2,
														    "proj_embedding": proj_embedding,
														    "encoder_hidden_states": encoder_hidden_states,
														}

							def 	lowercase							(self  )					->       List[str]:
														# clean up the VRAM after each test
														super().tearDown()
														gc.collect()
														torch.cuda.empty_cache()





							@parameterized.expand(
							    [
							        # fmt: off
							        [13, [-0.5861,  0.1283, -0.0931,  0.0882,  0.4476,  0.1329, -0.0498,  0.0640]],
							        [37, [-0.4913,  0.0110, -0.0483,  0.0541,  0.4954, -0.0170,  0.0354,  0.1651]],
							        # fmt: on
							    ]  )
							def 	lowercase							(self  ,  UpperCAmelCase  ,  UpperCAmelCase  )					->       List[Any]:
														_snake_case       =  PriorTransformer.from_pretrained("""kandinsky-community/kandinsky-2-1-prior"""  ,  subfolder="""prior"""  )
														model.to(UpperCAmelCase  )
														_snake_case       =  self.get_dummy_seed_input(seed=UpperCAmelCase  )

														with torch.no_grad():
																					_snake_case       =  model(**UpperCAmelCase  )[0]

														assert list(sample.shape  ) == [1, 768]

														_snake_case       =  sample[0, :8].flatten().cpu()
														print(UpperCAmelCase  )
														_snake_case       =  torch.tensor(UpperCAmelCase  )

														assert torch_all_close(UpperCAmelCase  ,  UpperCAmelCase  ,  atol=1e-3  )

'''simple docstring'''
import qiskit






def  __SCREAMING_SNAKE_CASE				(  _SCREAMING_SNAKE_CASE							, _SCREAMING_SNAKE_CASE				):
							_snake_case       =  qiskit.Aer.get_backend("""aer_simulator"""				)

							# Create a Quantum Circuit acting on the q register
							_snake_case       =  qiskit.QuantumCircuit(_SCREAMING_SNAKE_CASE							, _SCREAMING_SNAKE_CASE				)

							# 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
							_snake_case       =  qiskit.execute(_SCREAMING_SNAKE_CASE							, _SCREAMING_SNAKE_CASE							, shots=1000				)

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


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