


import unittest

from transformers import MarkupLMConfig, is_torch_available
from transformers.testing_utils import require_torch, slow, torch_device
from transformers.utils import cached_property

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


if is_torch_available():
						import torch

						from transformers import (
						    MarkupLMForQuestionAnswering,
						    MarkupLMForSequenceClassification,
						    MarkupLMForTokenClassification,
						    MarkupLMModel,
						)

# TODO check dependencies
from transformers import MarkupLMFeatureExtractor, MarkupLMProcessor, MarkupLMTokenizer







class     lowerCamelCase__		:






			"""simple docstring"""






			def __init__(							self ,  snake_case ,  snake_case=13 ,  snake_case=7 ,  snake_case=True ,  snake_case=True ,  snake_case=True ,  snake_case=True ,  snake_case=99 ,  snake_case=32 ,  snake_case=5 ,  snake_case=4 ,  snake_case=37 ,  snake_case="gelu" ,  snake_case=0.1 ,  snake_case=0.1 ,  snake_case=512 ,  snake_case=16 ,  snake_case=2 ,  snake_case=0.02 ,  snake_case=3 ,  snake_case=None ,  snake_case=20 ,  snake_case=30 ,  snake_case=2 ,  snake_case=2 ,  snake_case=10 ,  ):

						'''simple docstring'''


						UpperCamelCase__   =    parent
						UpperCamelCase__   =    batch_size
						UpperCamelCase__   =    seq_length
						UpperCamelCase__   =    is_training
						UpperCamelCase__   =    use_input_mask
						UpperCamelCase__   =    use_token_type_ids
						UpperCamelCase__   =    use_labels
						UpperCamelCase__   =    vocab_size
						UpperCamelCase__   =    hidden_size
						UpperCamelCase__   =    num_hidden_layers
						UpperCamelCase__   =    num_attention_heads
						UpperCamelCase__   =    intermediate_size
						UpperCamelCase__   =    hidden_act
						UpperCamelCase__   =    hidden_dropout_prob
						UpperCamelCase__   =    attention_probs_dropout_prob
						UpperCamelCase__   =    max_position_embeddings
						UpperCamelCase__   =    type_vocab_size
						UpperCamelCase__   =    type_sequence_label_size
						UpperCamelCase__   =    initializer_range
						UpperCamelCase__   =    num_labels
						UpperCamelCase__   =    scope
						UpperCamelCase__   =    max_xpath_tag_unit_embeddings
						UpperCamelCase__   =    max_xpath_subs_unit_embeddings
						UpperCamelCase__   =    tag_pad_id
						UpperCamelCase__   =    subs_pad_id
						UpperCamelCase__   =    max_depth




			def 			snake_case__			(							self       ):

						'''simple docstring'''


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

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

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

						UpperCamelCase__   =    None
						if self.use_input_mask:
									UpperCamelCase__   =    ids_tensor([self.batch_size, self.seq_length] ,  vocab_size=2       )

						UpperCamelCase__   =    None
						if self.use_token_type_ids:
									UpperCamelCase__   =    ids_tensor([self.batch_size, self.seq_length] ,  self.type_vocab_size       )

						UpperCamelCase__   =    None
						UpperCamelCase__   =    None
						if self.use_labels:
									UpperCamelCase__   =    ids_tensor([self.batch_size] ,  self.type_sequence_label_size       )
									UpperCamelCase__   =    ids_tensor([self.batch_size, self.seq_length] ,  self.num_labels       )

						UpperCamelCase__   =    self.get_config()

						return (
						    config,
						    input_ids,
						    xpath_tags_seq,
						    xpath_subs_seq,
						    token_type_ids,
						    input_mask,
						    sequence_labels,
						    token_labels,
						)




			def 			snake_case__			(							self       ):

						'''simple docstring'''


						return MarkupLMConfig(
						    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 ,  max_xpath_tag_unit_embeddings=self.max_xpath_tag_unit_embeddings ,  max_xpath_subs_unit_embeddings=self.max_xpath_subs_unit_embeddings ,  tag_pad_id=self.tag_pad_id ,  subs_pad_id=self.subs_pad_id ,  max_depth=self.max_depth ,  )




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

						'''simple docstring'''


						UpperCamelCase__   =    MarkupLMModel(config=_A       )
						model.to(_A       )
						model.eval()
						print("Configs:" ,  model.config.tag_pad_id ,  model.config.subs_pad_id       )
						UpperCamelCase__   =    model(_A ,  attention_mask=_A ,  token_type_ids=_A       )
						UpperCamelCase__   =    model(_A ,  token_type_ids=_A       )
						UpperCamelCase__   =    model(_A       )
						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 ,  snake_case ,  snake_case ,  snake_case ,  snake_case ,  snake_case ,  snake_case ,  snake_case ,  snake_case ,  ):

						'''simple docstring'''


						UpperCamelCase__   =    self.num_labels
						UpperCamelCase__   =    MarkupLMForSequenceClassification(_A       )
						model.to(_A       )
						model.eval()
						UpperCamelCase__   =    model(
						    _A ,  xpath_tags_seq=_A ,  xpath_subs_seq=_A ,  attention_mask=_A ,  token_type_ids=_A ,  labels=_A ,  )
						self.parent.assertEqual(result.logits.shape ,  (self.batch_size, self.num_labels)       )




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

						'''simple docstring'''


						UpperCamelCase__   =    self.num_labels
						UpperCamelCase__   =    MarkupLMForTokenClassification(config=_A       )
						model.to(_A       )
						model.eval()
						UpperCamelCase__   =    model(
						    _A ,  xpath_tags_seq=_A ,  xpath_subs_seq=_A ,  attention_mask=_A ,  token_type_ids=_A ,  labels=_A ,  )
						self.parent.assertEqual(result.logits.shape ,  (self.batch_size, self.seq_length, self.num_labels)       )




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

						'''simple docstring'''


						UpperCamelCase__   =    MarkupLMForQuestionAnswering(config=_A       )
						model.to(_A       )
						model.eval()
						UpperCamelCase__   =    model(
						    _A ,  xpath_tags_seq=_A ,  xpath_subs_seq=_A ,  attention_mask=_A ,  token_type_ids=_A ,  start_positions=_A ,  end_positions=_A ,  )
						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 			snake_case__			(							self       ):

						'''simple docstring'''


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







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






			"""simple docstring"""






			_UpperCamelCase						:   Any					=						(
			    (
			        MarkupLMModel,
			        MarkupLMForSequenceClassification,
			        MarkupLMForTokenClassification,
			        MarkupLMForQuestionAnswering,
			    )
			    if is_torch_available()
			    else None
			)
			_UpperCamelCase						:   int					=						(
			    {
			        'feature-extraction': MarkupLMModel,
			        'question-answering': MarkupLMForQuestionAnswering,
			        'text-classification': MarkupLMForSequenceClassification,
			        'token-classification': MarkupLMForTokenClassification,
			        'zero-shot': MarkupLMForSequenceClassification,
			    }
			    if is_torch_available()
			    else {}
			)




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

						'''simple docstring'''


						return True




			def 			snake_case__			(							self       ):

						'''simple docstring'''


						UpperCamelCase__   =    MarkupLMModelTester(self       )
						UpperCamelCase__   =    ConfigTester(self ,  config_class=_A ,  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(*_A       )




			def 			snake_case__			(							self       ):

						'''simple docstring'''


						UpperCamelCase__   =    self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_sequence_classification(*_A       )




			def 			snake_case__			(							self       ):

						'''simple docstring'''


						UpperCamelCase__   =    self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_token_classification(*_A       )







			def 			snake_case__			(							self       ):

						'''simple docstring'''


						UpperCamelCase__   =    self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_question_answering(*_A       )



def     UpperCamelCase_(			)->						int:
			UpperCamelCase__   =    "\n    <!DOCTYPE html>\n    <html>\n    <head>\n    <title>Page Title</title>\n    </head>\n    <body>\n\n    <h1>This is a Heading</h1>\n    <p>This is a paragraph.</p>\n\n    </body>\n    </html>\n    "

			return html_string







@require_torch
class     lowerCamelCase__		(							unittest.TestCase ):






			"""simple docstring"""






			@cached_property
			def 			snake_case__			(							self       ):

						'''simple docstring'''


						UpperCamelCase__   =    MarkupLMFeatureExtractor()
						UpperCamelCase__   =    MarkupLMTokenizer.from_pretrained("microsoft/markuplm-base"       )

						return MarkupLMProcessor(_A ,  _A       )







			@slow
			def 			snake_case__			(							self       ):

						'''simple docstring'''


						UpperCamelCase__   =    MarkupLMModel.from_pretrained("microsoft/markuplm-base"       ).to(_A       )

						UpperCamelCase__   =    self.default_processor

						UpperCamelCase__   =    processor(prepare_html_string() ,  return_tensors="pt"       )
						UpperCamelCase__   =    inputs.to(_A       )

						# forward pass
						with torch.no_grad():
									UpperCamelCase__   =    model(**_A       )

						# verify the last hidden states
						UpperCamelCase__   =    torch.Size([1, 14, 768]       )
						self.assertEqual(outputs.last_hidden_state.shape ,  _A       )

						UpperCamelCase__   =    torch.tensor(
						    [[0.0675, -0.0052, 0.5001], [-0.2281, 0.0802, 0.2192], [-0.0583, -0.3311, 0.1185]]       ).to(_A       )

						self.assertTrue(torch.allclose(outputs.last_hidden_state[0, :3, :3] ,  _A ,  atol=1E-4       )       )






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()


