

'''simple docstring'''

import unittest

from transformers import ErnieMConfig, is_torch_available
from transformers.testing_utils import require_torch, slow, torch_device

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
			import torch

			from transformers import (
			    ErnieMForInformationExtraction,
			    ErnieMForMultipleChoice,
			    ErnieMForQuestionAnswering,
			    ErnieMForSequenceClassification,
			    ErnieMForTokenClassification,
			    ErnieMModel,
			)
			from transformers.models.ernie_m.modeling_ernie_m import ERNIE_M_PRETRAINED_MODEL_ARCHIVE_LIST







class   UpperCamelCase__   :


		"""simple docstring"""

		def __init__(			self   ,      snake_case   ,      snake_case=1_3   ,      snake_case=7   ,      snake_case=True   ,      snake_case=True   ,      snake_case=True   ,      snake_case=9_9   ,      snake_case=3_2   ,      snake_case=5   ,      snake_case=4   ,      snake_case=3_7   ,      snake_case="gelu"   ,      snake_case=0.1   ,      snake_case=0.1   ,      snake_case=5_1_2   ,      snake_case=1_6   ,      snake_case=2   ,      snake_case=0.02   ,      snake_case=3   ,      snake_case=4   ,      snake_case=None   ,      ):


							'''simple docstring'''

							UpperCAmelCase		:							Any        =       parent
							UpperCAmelCase		:							Optional[int]        =       batch_size
							UpperCAmelCase		:							Dict        =       seq_length
							UpperCAmelCase		:							int        =       is_training
							UpperCAmelCase		:							Dict        =       use_input_mask
							UpperCAmelCase		:							str        =       use_labels
							UpperCAmelCase		:							List[str]        =       vocab_size
							UpperCAmelCase		:							Tuple        =       hidden_size
							UpperCAmelCase		:							int        =       num_hidden_layers
							UpperCAmelCase		:							Optional[int]        =       num_attention_heads
							UpperCAmelCase		:							List[str]        =       intermediate_size
							UpperCAmelCase		:							Optional[int]        =       hidden_act
							UpperCAmelCase		:							Union[str, Any]        =       hidden_dropout_prob
							UpperCAmelCase		:							str        =       attention_probs_dropout_prob
							UpperCAmelCase		:							List[Any]        =       max_position_embeddings
							UpperCAmelCase		:							int        =       type_vocab_size
							UpperCAmelCase		:							Optional[int]        =       type_sequence_label_size
							UpperCAmelCase		:							str        =       initializer_range
							UpperCAmelCase		:							Any        =       num_labels
							UpperCAmelCase		:							Any        =       num_choices
							UpperCAmelCase		:							Optional[Any]        =       scope







		def 				A_	(			self      ):


							'''simple docstring'''

							UpperCAmelCase		:							Optional[Any]        =       ids_tensor([self.batch_size, self.seq_length]   ,      self.vocab_size      )

							UpperCAmelCase		:							Optional[int]        =       None
							if self.use_input_mask:
												UpperCAmelCase		:							List[str]        =       random_attention_mask([self.batch_size, self.seq_length]      )

							UpperCAmelCase		:							str        =       None
							UpperCAmelCase		:							List[str]        =       None
							UpperCAmelCase		:							Union[str, Any]        =       None
							if self.use_labels:
												UpperCAmelCase		:							Optional[int]        =       ids_tensor([self.batch_size]   ,      self.type_sequence_label_size      )
												UpperCAmelCase		:							Any        =       ids_tensor([self.batch_size, self.seq_length]   ,      self.num_labels      )
												UpperCAmelCase		:							Union[str, Any]        =       ids_tensor([self.batch_size]   ,      self.num_choices      )

							UpperCAmelCase		:							Any        =       self.get_config()

							return config, input_ids, input_mask, sequence_labels, token_labels, choice_labels







		def 				A_	(			self      ):


							'''simple docstring'''

							UpperCAmelCase		:							Tuple        =       ids_tensor([self.batch_size, self.seq_length]   ,      self.vocab_size      )

							UpperCAmelCase		:							str        =       None
							if self.use_input_mask:
												UpperCAmelCase		:							Dict        =       random_attention_mask([self.batch_size, self.seq_length]      )
							UpperCAmelCase		:							int        =       self.get_config()

							return config, input_ids, input_mask







		def 				A_	(			self      ):


							'''simple docstring'''

							return ErnieMConfig(
							    vocab_size=self.vocab_size   ,      hidden_size=self.hidden_size   ,      num_hidden_layers=self.num_hidden_layers   ,      num_attention_heads=self.num_attention_heads   ,      intermediate_size=self.intermediate_size   ,      hidden_act=self.hidden_act   ,      hidden_dropout_prob=self.hidden_dropout_prob   ,      attention_probs_dropout_prob=self.attention_probs_dropout_prob   ,      max_position_embeddings=self.max_position_embeddings   ,      type_vocab_size=self.type_vocab_size   ,      initializer_range=self.initializer_range   ,      )







		def 				A_	(			self   ,      snake_case   ,      snake_case   ,      snake_case   ,      snake_case   ,      snake_case   ,      snake_case      ):


							'''simple docstring'''

							UpperCAmelCase		:							List[Any]        =       ErnieMModel(config=UpperCamelCase__      )
							model.to(UpperCamelCase__      )
							model.eval()
							UpperCAmelCase		:							Optional[int]        =       model(UpperCamelCase__   ,      return_dict=UpperCamelCase__      )
							self.parent.assertEqual(result.last_hidden_state.shape   ,      (self.batch_size, self.seq_length, self.hidden_size)      )







		def 				A_	(			self   ,      snake_case   ,      snake_case   ,      snake_case   ,      snake_case   ,      snake_case   ,      snake_case      ):


							'''simple docstring'''

							UpperCAmelCase		:							Optional[int]        =       ErnieMForQuestionAnswering(config=UpperCamelCase__      )
							model.to(UpperCamelCase__      )
							model.eval()
							UpperCAmelCase		:							Optional[int]        =       model(
							    UpperCamelCase__   ,      attention_mask=UpperCamelCase__   ,      start_positions=UpperCamelCase__   ,      end_positions=UpperCamelCase__   ,      )
							self.parent.assertEqual(result.start_logits.shape   ,      (self.batch_size, self.seq_length)      )
							self.parent.assertEqual(result.end_logits.shape   ,      (self.batch_size, self.seq_length)      )







		def 				A_	(			self   ,      snake_case   ,      snake_case   ,      snake_case   ,      snake_case   ,      snake_case   ,      snake_case      ):


							'''simple docstring'''

							UpperCAmelCase		:							Optional[int]        =       ErnieMForInformationExtraction(config=UpperCamelCase__      )
							model.to(UpperCamelCase__      )
							model.eval()
							UpperCAmelCase		:							List[str]        =       torch.ones_like(UpperCamelCase__   ,      dtype=torch.floataa      )
							UpperCAmelCase		:							int        =       model(
							    UpperCamelCase__   ,      attention_mask=UpperCamelCase__   ,      start_positions=UpperCamelCase__   ,      end_positions=UpperCamelCase__   ,      )
							self.parent.assertEqual(result.start_logits.shape   ,      (self.batch_size, self.seq_length)      )
							self.parent.assertEqual(result.end_logits.shape   ,      (self.batch_size, self.seq_length)      )







		def 				A_	(			self   ,      snake_case   ,      snake_case   ,      snake_case   ,      snake_case   ,      snake_case   ,      snake_case      ):


							'''simple docstring'''

							UpperCAmelCase		:							List[str]        =       self.num_labels
							UpperCAmelCase		:							str        =       ErnieMForSequenceClassification(UpperCamelCase__      )
							model.to(UpperCamelCase__      )
							model.eval()
							UpperCAmelCase		:							Union[str, Any]        =       model(UpperCamelCase__   ,      attention_mask=UpperCamelCase__   ,      labels=UpperCamelCase__      )
							self.parent.assertEqual(result.logits.shape   ,      (self.batch_size, self.num_labels)      )







		def 				A_	(			self   ,      snake_case   ,      snake_case   ,      snake_case   ,      snake_case   ,      snake_case   ,      snake_case      ):


							'''simple docstring'''

							UpperCAmelCase		:							List[Any]        =       self.num_labels
							UpperCAmelCase		:							str        =       ErnieMForTokenClassification(config=UpperCamelCase__      )
							model.to(UpperCamelCase__      )
							model.eval()
							input_ids.to(UpperCamelCase__      )
							input_mask.to(UpperCamelCase__      )
							token_labels.to(UpperCamelCase__      )

							UpperCAmelCase		:							Dict        =       model(UpperCamelCase__   ,      attention_mask=UpperCamelCase__   ,      labels=UpperCamelCase__      )

							self.parent.assertEqual(result.logits.shape   ,      (self.batch_size, self.seq_length, self.num_labels)      )







		def 				A_	(			self   ,      snake_case   ,      snake_case   ,      snake_case   ,      snake_case   ,      snake_case   ,      snake_case      ):


							'''simple docstring'''

							UpperCAmelCase		:							Tuple        =       self.num_choices
							UpperCAmelCase		:							Optional[Any]        =       ErnieMForMultipleChoice(config=UpperCamelCase__      )
							model.to(UpperCamelCase__      )
							model.eval()
							UpperCAmelCase		:							Optional[Any]        =       input_ids.unsqueeze(1      ).expand(-1   ,      self.num_choices   ,      -1      ).contiguous()
							UpperCAmelCase		:							Optional[int]        =       input_mask.unsqueeze(1      ).expand(-1   ,      self.num_choices   ,      -1      ).contiguous()
							UpperCAmelCase		:							int        =       model(
							    UpperCamelCase__   ,      attention_mask=UpperCamelCase__   ,      labels=UpperCamelCase__   ,      )
							self.parent.assertEqual(result.logits.shape   ,      (self.batch_size, self.num_choices)      )







		def 				A_	(			self      ):


							'''simple docstring'''

							UpperCAmelCase		:							Optional[int]        =       self.prepare_config_and_inputs()
							(
							    UpperCAmelCase				
							)		:							int        =       config_and_inputs
							UpperCAmelCase		:							str        =       {"input_ids": input_ids, "attention_mask": input_mask}
							return config, inputs_dict







@require_torch
class   UpperCamelCase__   (       lowerCAmelCase__							,							lowerCAmelCase__							,							unittest.TestCase       ):


		"""simple docstring"""

		SCREAMING_SNAKE_CASE__  :     Dict       =							(
		    (
		        ErnieMModel,
		        ErnieMForMultipleChoice,
		        ErnieMForQuestionAnswering,
		        ErnieMForSequenceClassification,
		        ErnieMForTokenClassification,
		    )
		    if is_torch_available()
		    else ()
		)
		SCREAMING_SNAKE_CASE__  :     Union[str, Any]       =							()
		SCREAMING_SNAKE_CASE__  :     str       =							(
		    {
		        """feature-extraction""": ErnieMModel,
		        """question-answering""": ErnieMForQuestionAnswering,
		        """text-classification""": ErnieMForSequenceClassification,
		        """token-classification""": ErnieMForTokenClassification,
		        """zero-shot""": ErnieMForSequenceClassification,
		    }
		    if is_torch_available()
		    else {}
		)
		SCREAMING_SNAKE_CASE__  :     str       =							False







		def 				A_	(			self   ,      snake_case   ,      snake_case   ,      snake_case   ,      snake_case   ,      snake_case      ):


							'''simple docstring'''

							if pipeline_test_casse_name == "QAPipelineTests":
												return True

							return False







		def 				A_	(			self      ):


							'''simple docstring'''

							UpperCAmelCase		:							Tuple        =       ErnieMModelTester(self      )
							UpperCAmelCase		:							List[Any]        =       ConfigTester(self   ,      config_class=UpperCamelCase__   ,      hidden_size=3_7      )







		def 				A_	(			self      ):


							'''simple docstring'''

							self.config_tester.run_common_tests()







		def 				A_	(			self      ):


							'''simple docstring'''

							UpperCAmelCase		:							Optional[Any]        =       self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_model(*UpperCamelCase__      )







		def 				A_	(			self      ):


							'''simple docstring'''

							UpperCAmelCase		:							List[Any]        =       self.model_tester.prepare_config_and_inputs()
							for type in ["absolute", "relative_key", "relative_key_query"]:
												UpperCAmelCase		:							int        =       type
												self.model_tester.create_and_check_model(*UpperCamelCase__      )







		def 				A_	(			self      ):


							'''simple docstring'''

							UpperCAmelCase		:							int        =       self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_multiple_choice(*UpperCamelCase__      )







		def 				A_	(			self      ):


							'''simple docstring'''

							UpperCAmelCase		:							Optional[Any]        =       self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_question_answering(*UpperCamelCase__      )







		def 				A_	(			self      ):


							'''simple docstring'''

							UpperCAmelCase		:							Tuple        =       self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_sequence_classification(*UpperCamelCase__      )







		def 				A_	(			self      ):


							'''simple docstring'''

							UpperCAmelCase		:							Union[str, Any]        =       self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_information_extraction(*UpperCamelCase__      )







		def 				A_	(			self      ):


							'''simple docstring'''

							UpperCAmelCase		:							Any        =       self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_token_classification(*UpperCamelCase__      )







		@slow
		def 				A_	(			self      ):


							'''simple docstring'''

							for model_name in ERNIE_M_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
												UpperCAmelCase		:							Union[str, Any]        =       ErnieMModel.from_pretrained(UpperCamelCase__      )
												self.assertIsNotNone(UpperCamelCase__      )







@require_torch
class   UpperCamelCase__   (       unittest.TestCase       ):


		"""simple docstring"""

		@slow
		def 				A_	(			self      ):


							'''simple docstring'''

							UpperCAmelCase		:							Tuple        =       ErnieMModel.from_pretrained("susnato/ernie-m-base_pytorch"      )
							model.eval()
							UpperCAmelCase		:							Optional[Any]        =       torch.tensor([[0, 1, 2, 3, 4, 5]]      )
							UpperCAmelCase		:							Dict        =       model(UpperCamelCase__      )[0]

							# TODO Replace vocab size
							UpperCAmelCase		:							Optional[int]        =       7_6_8

							UpperCAmelCase		:							Optional[Any]        =       torch.Size((1, 6, hidden_size)      )
							self.assertEqual(output.shape   ,      UpperCamelCase__      )

							UpperCAmelCase		:							Dict        =       torch.tensor(
							    [[[-0.0012, 0.1245, -0.0214], [-0.0742, 0.0244, -0.0771], [-0.0333, 0.1164, -0.1554]]]      )

							self.assertTrue(torch.allclose(output[:, :3, :3]   ,      UpperCamelCase__   ,      atol=1e-3      )      )



'''simple docstring'''

import math

import qiskit
from qiskit import Aer, ClassicalRegister, QuantumCircuit, QuantumRegister, execute





def 				lowercase (					__magic_name__ = 1			,   __magic_name__ = 1							):



					'''simple docstring'''







					if isinstance(__magic_name__			,   __magic_name__							) or isinstance(__magic_name__			,   __magic_name__							):
										raise TypeError("inputs must be integers."							)
					if (bit_a < 0) or (bit_a < 0):
										raise ValueError("inputs must be positive."							)
					if (math.floor(__magic_name__							) != bit_a) or (math.floor(__magic_name__							) != bit_a):
										raise ValueError("inputs must be exact integers."							)
					if (bit_a > 1) or (bit_a > 1):
										raise ValueError("inputs must be less or equal to 1."							)

					# build registers
					UpperCAmelCase		:							List[Any]        =       QuantumRegister(2			,   "qr"							)
					UpperCAmelCase		:							Optional[int]        =       ClassicalRegister(2			,   "cr"							)

					UpperCAmelCase		:							Optional[int]        =       QuantumCircuit(__magic_name__			,   __magic_name__							)

					# entanglement the qubits
					quantum_circuit.h(1							)
					quantum_circuit.cx(1			,   0							)

					# send the information
					UpperCAmelCase		:							Any        =       str(__magic_name__							) + str(__magic_name__							)

					if c_information == "11":
										quantum_circuit.x(1							)
										quantum_circuit.z(1							)
					elif c_information == "10":
										quantum_circuit.z(1							)
					elif c_information == "01":
										quantum_circuit.x(1							)
					else:
										quantum_circuit.i(1							)

					# unentangled the circuit
					quantum_circuit.cx(1			,   0							)
					quantum_circuit.h(1							)

					# measure the circuit
					quantum_circuit.measure(__magic_name__			,   __magic_name__							)

					UpperCAmelCase		:							Tuple        =       Aer.get_backend("aer_simulator"							)
					UpperCAmelCase		:							Any        =       execute(__magic_name__			,   __magic_name__			,   shots=1000							)

					return job.result().get_counts(__magic_name__							)


if __name__ == "__main__":
				print(F'Counts for classical state send: {superdense_coding(1,1)}')
