


import unittest

import numpy as np

from transformers import BlipTextConfig
from transformers.testing_utils import require_torch, slow, torch_device
from transformers.utils import is_torch_available

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


if is_torch_available():
						import torch

						from transformers import BlipTextModel
						from transformers.models.blip.modeling_blip import BLIP_PRETRAINED_MODEL_ARCHIVE_LIST







class     lowerCamelCase__		:






			"""simple docstring"""






			def __init__(							self ,  snake_case ,  snake_case=12 ,  snake_case=7 ,  snake_case=True ,  snake_case=True ,  snake_case=True ,  snake_case=99 ,  snake_case=32 ,  snake_case=32 ,  snake_case=5 ,  snake_case=4 ,  snake_case=37 ,  snake_case=0.1 ,  snake_case=0.1 ,  snake_case=512 ,  snake_case=0.02 ,  snake_case=0 ,  snake_case=None ,  ):

						'''simple docstring'''


						UpperCamelCase__   =    parent
						UpperCamelCase__   =    batch_size
						UpperCamelCase__   =    seq_length
						UpperCamelCase__   =    is_training
						UpperCamelCase__   =    use_input_mask
						UpperCamelCase__   =    use_labels
						UpperCamelCase__   =    vocab_size
						UpperCamelCase__   =    hidden_size
						UpperCamelCase__   =    projection_dim
						UpperCamelCase__   =    num_hidden_layers
						UpperCamelCase__   =    num_attention_heads
						UpperCamelCase__   =    intermediate_size
						UpperCamelCase__   =    dropout
						UpperCamelCase__   =    attention_dropout
						UpperCamelCase__   =    max_position_embeddings
						UpperCamelCase__   =    initializer_range
						UpperCamelCase__   =    scope
						UpperCamelCase__   =    bos_token_id




			def 			snake_case__			(							self       ):

						'''simple docstring'''


						UpperCamelCase__   =    ids_tensor([self.batch_size, self.seq_length] ,  self.vocab_size       )

						UpperCamelCase__   =    None
						if self.use_input_mask:
									UpperCamelCase__   =    random_attention_mask([self.batch_size, self.seq_length]       )

						if input_mask is not None:
									UpperCamelCase__, UpperCamelCase__   =    input_mask.shape
									UpperCamelCase__   =    np.random.randint(1 ,  seq_length - 1 ,  size=(batch_size,)       )
									for batch_idx, start_index in enumerate(_UpperCAmelCase       ):
												UpperCamelCase__   =    1
												UpperCamelCase__   =    0

						UpperCamelCase__   =    self.get_config()

						return config, input_ids, input_mask




			def 			snake_case__			(							self       ):

						'''simple docstring'''


						return BlipTextConfig(
						    vocab_size=self.vocab_size ,  hidden_size=self.hidden_size ,  projection_dim=self.projection_dim ,  num_hidden_layers=self.num_hidden_layers ,  num_attention_heads=self.num_attention_heads ,  intermediate_size=self.intermediate_size ,  dropout=self.dropout ,  attention_dropout=self.attention_dropout ,  max_position_embeddings=self.max_position_embeddings ,  initializer_range=self.initializer_range ,  bos_token_id=self.bos_token_id ,  )




			def 			snake_case__			(							self ,  snake_case ,  snake_case ,  snake_case       ):

						'''simple docstring'''


						UpperCamelCase__   =    BlipTextModel(config=_UpperCAmelCase       )
						model.to(_UpperCAmelCase       )
						model.eval()
						with torch.no_grad():
									UpperCamelCase__   =    model(_UpperCAmelCase ,  attention_mask=_UpperCAmelCase       )
									UpperCamelCase__   =    model(_UpperCAmelCase       )
						self.parent.assertEqual(result.last_hidden_state.shape ,  (self.batch_size, self.seq_length, self.hidden_size)       )
						self.parent.assertEqual(result.pooler_output.shape ,  (self.batch_size, self.hidden_size)       )







			def 			snake_case__			(							self       ):

						'''simple docstring'''


						UpperCamelCase__   =    self.prepare_config_and_inputs()
						UpperCamelCase__, UpperCamelCase__, UpperCamelCase__   =    config_and_inputs
						UpperCamelCase__   =    {"input_ids": input_ids, "attention_mask": input_mask}
						return config, inputs_dict







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






			"""simple docstring"""






			_UpperCamelCase						:   Optional[int]					=						(BlipTextModel,) if is_torch_available() else ()
			_UpperCamelCase						:   Tuple					=						False
			_UpperCamelCase						:   Optional[Any]					=						False
			_UpperCamelCase						:   Union[str, Any]					=						False




			def 			snake_case__			(							self       ):

						'''simple docstring'''


						UpperCamelCase__   =    BlipTextModelTester(self       )
						UpperCamelCase__   =    ConfigTester(self ,  config_class=_UpperCAmelCase ,  hidden_size=37       )




			def 			snake_case__			(							self       ):

						'''simple docstring'''


						self.config_tester.run_common_tests()




			def 			snake_case__			(							self       ):

						'''simple docstring'''


						UpperCamelCase__   =    self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_model(*_UpperCAmelCase       )




			def 			snake_case__			(							self       ):

						'''simple docstring'''


						pass




			def 			snake_case__			(							self       ):

						'''simple docstring'''


						pass




			@unittest.skip(reason="Blip does not use inputs_embeds"       )
			def 			snake_case__			(							self       ):

						'''simple docstring'''


						pass




			@unittest.skip(reason="BlipTextModel has no base class and is not available in MODEL_MAPPING"       )
			def 			snake_case__			(							self       ):

						'''simple docstring'''


						pass




			@unittest.skip(reason="BlipTextModel has no base class and is not available in MODEL_MAPPING"       )
			def 			snake_case__			(							self       ):

						'''simple docstring'''


						pass




			@slow
			def 			snake_case__			(							self       ):

						'''simple docstring'''


						for model_name in BLIP_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
									UpperCamelCase__   =    BlipTextModel.from_pretrained(_UpperCAmelCase       )
									self.assertIsNotNone(_UpperCAmelCase       )







			def 			snake_case__			(							self       ):

						'''simple docstring'''


						super().test_pt_tf_model_equivalence(allow_missing_keys=_UpperCAmelCase       )






import qiskit
from qiskit.providers import Backend
def     UpperCamelCase_(			_A				:int			,       _A				:int					)->						tuple[qiskit.QuantumCircuit, str, str]:
			UpperCamelCase__, UpperCamelCase__   =    bin(_A					)[2:], bin(_A					)[2:]  # Remove leading '0b'

			# Ensure that both strings are of the same length
			if len(_A					) > len(_A					):
						UpperCamelCase__   =    y.zfill(len(_A					)					)
			else:
						UpperCamelCase__   =    x.zfill(len(_A					)					)

			# We need (3 * number of bits in the larger number)+1 qBits
			# The second parameter is the number of classical registers, to measure the result
			UpperCamelCase__   =    qiskit.QuantumCircuit((len(_A					) * 3) + 1			,       len(_A					) + 1					)

			# We are essentially "not-ing" the bits that are 1
			# Reversed because it's easier to perform ops on more significant bits
			for i in range(len(_A					)					):
						if x[::-1][i] == "1":
									circuit.x(_A					)
			for j in range(len(_A					)					):
						if y[::-1][j] == "1":
									circuit.x(len(_A					) + j					)

			return circuit, x, y
def     UpperCamelCase_(			_A				:qiskit.QuantumCircuit			,       _A				:int			,       _A				:int			,       _A				:int			,       _A				:int			,       )->						Union[str, Any]:
			circuit.ccx(_A			,       _A			,       _A					)
			circuit.cx(_A			,       _A					)
			circuit.ccx(_A			,       _A			,       _A					)
			circuit.cx(_A			,       _A					)
			circuit.cx(_A			,       _A					)
def     UpperCamelCase_(			_A				:int			,       _A				:int			,       _A				:Backend = qiskit.Aer.get_backend("aer_simulator"					)			,       )->						int:

			if vala < 0 or vala < 0:
						raise ValueError("Both Integers must be positive!"					)

			# Store the Integers
			UpperCamelCase__, UpperCamelCase__, UpperCamelCase__   =    store_two_classics(_A			,       _A					)
			for i in range(len(_A					)					):
						full_adder(_A			,       _A			,       len(_A					) + i			,       len(_A					) + len(_A					) + i			,       len(_A					) + len(_A					) + i + 1					)
						circuit.barrier()  # Optional, just for aesthetics

			# Measure the resultant qBits
			for i in range(len(_A					) + 1					):
						circuit.measure([(len(_A					) * 2) + i]			,       [i]					)

			UpperCamelCase__   =    qiskit.execute(_A			,       _A			,       shots=1					).result()

			# The result is in binary. Convert it back to int
			return int(list(res.get_counts()					)[0]			,       2					)


if __name__ == "__main__":
						import doctest

						doctest.testmod()


