

"""simple docstring"""


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 					snake_case			:

    def __init__(			self							:       Optional[int]  ,						UpperCamelCase__							:       int  ,						UpperCamelCase__							:       int=1_3  ,						UpperCamelCase__							:       Tuple=7  ,						UpperCamelCase__							:       int=True  ,						UpperCamelCase__							:       str=True  ,						UpperCamelCase__							:       Optional[Any]=True  ,						UpperCamelCase__							:       Optional[Any]=True  ,						UpperCamelCase__							:       Dict=9_9  ,						UpperCamelCase__							:       Union[str, Any]=3_2  ,						UpperCamelCase__							:       Union[str, Any]=5  ,						UpperCamelCase__							:       List[str]=4  ,						UpperCamelCase__							:       Tuple=3_7  ,						UpperCamelCase__							:       int="gelu"  ,						UpperCamelCase__							:       int=0.1  ,						UpperCamelCase__							:       Dict=0.1  ,						UpperCamelCase__							:       List[Any]=5_1_2  ,						UpperCamelCase__							:       Union[str, Any]=1_6  ,						UpperCamelCase__							:       Dict=2  ,						UpperCamelCase__							:       List[str]=0.02  ,						UpperCamelCase__							:       List[Any]=3  ,						UpperCamelCase__							:       List[str]=None  ,						UpperCamelCase__							:       Union[str, Any]=2_0  ,						UpperCamelCase__							:       List[str]=3_0  ,						UpperCamelCase__							:       Tuple=2  ,						UpperCamelCase__							:       Union[str, Any]=2  ,						UpperCamelCase__							:       List[str]=1_0  ,						)->     Union[str, Any]:



      '''simple docstring'''


      __lowerCAmelCase: Optional[int]					   =    parent
      __lowerCAmelCase: Dict					   =    batch_size
      __lowerCAmelCase: int					   =    seq_length
      __lowerCAmelCase: Optional[Any]					   =    is_training
      __lowerCAmelCase: List[Any]					   =    use_input_mask
      __lowerCAmelCase: Dict					   =    use_token_type_ids
      __lowerCAmelCase: str					   =    use_labels
      __lowerCAmelCase: Tuple					   =    vocab_size
      __lowerCAmelCase: str					   =    hidden_size
      __lowerCAmelCase: List[str]					   =    num_hidden_layers
      __lowerCAmelCase: str					   =    num_attention_heads
      __lowerCAmelCase: List[str]					   =    intermediate_size
      __lowerCAmelCase: Any					   =    hidden_act
      __lowerCAmelCase: int					   =    hidden_dropout_prob
      __lowerCAmelCase: Any					   =    attention_probs_dropout_prob
      __lowerCAmelCase: List[str]					   =    max_position_embeddings
      __lowerCAmelCase: Union[str, Any]					   =    type_vocab_size
      __lowerCAmelCase: Optional[Any]					   =    type_sequence_label_size
      __lowerCAmelCase: Optional[int]					   =    initializer_range
      __lowerCAmelCase: Union[str, Any]					   =    num_labels
      __lowerCAmelCase: Optional[int]					   =    scope
      __lowerCAmelCase: Optional[Any]					   =    max_xpath_tag_unit_embeddings
      __lowerCAmelCase: List[Any]					   =    max_xpath_subs_unit_embeddings
      __lowerCAmelCase: List[str]					   =    tag_pad_id
      __lowerCAmelCase: Dict					   =    subs_pad_id
      __lowerCAmelCase: Optional[int]					   =    max_depth

    def 							lowercase_  (			self							:       List[Any])->     List[str]:



      '''simple docstring'''


      __lowerCAmelCase: Optional[int]					   =    ids_tensor([self.batch_size, self.seq_length]  ,						self.vocab_size)

      __lowerCAmelCase: Union[str, Any]					   =    ids_tensor(
          [self.batch_size, self.seq_length, self.max_depth]  ,						self.max_xpath_tag_unit_embeddings)

      __lowerCAmelCase: str					   =    ids_tensor(
          [self.batch_size, self.seq_length, self.max_depth]  ,						self.max_xpath_subs_unit_embeddings)

      __lowerCAmelCase: List[str]					   =    None
      if self.use_input_mask:
        __lowerCAmelCase: Optional[int]					   =    ids_tensor([self.batch_size, self.seq_length]  ,						vocab_size=2)

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

      __lowerCAmelCase: Any					   =    None
      __lowerCAmelCase: List[Any]					   =    None
      if self.use_labels:
        __lowerCAmelCase: str					   =    ids_tensor([self.batch_size]  ,						self.type_sequence_label_size)
        __lowerCAmelCase: Dict					   =    ids_tensor([self.batch_size, self.seq_length]  ,						self.num_labels)

      __lowerCAmelCase: Optional[Any]					   =    self.get_config()

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

    def 							lowercase_  (			self							:       Tuple)->     Tuple:



      '''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 							lowercase_  (			self							:       Any  ,						UpperCamelCase__							:       List[str]  ,						UpperCamelCase__							:       List[Any]  ,						UpperCamelCase__							:       int  ,						UpperCamelCase__							:       Dict  ,						UpperCamelCase__							:       List[str]  ,						UpperCamelCase__							:       Tuple  ,						UpperCamelCase__							:       Union[str, Any]  ,						UpperCamelCase__							:       Any  ,						)->     str:



      '''simple docstring'''


      __lowerCAmelCase: str					   =    MarkupLMModel(config=UpperCamelCase__)
      model.to(UpperCamelCase__)
      model.eval()
      print("Configs:"  ,						model.config.tag_pad_id  ,						model.config.subs_pad_id)
      __lowerCAmelCase: str					   =    model(UpperCamelCase__  ,						attention_mask=UpperCamelCase__  ,						token_type_ids=UpperCamelCase__)
      __lowerCAmelCase: int					   =    model(UpperCamelCase__  ,						token_type_ids=UpperCamelCase__)
      __lowerCAmelCase: Tuple					   =    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 							lowercase_  (			self							:       Any  ,						UpperCamelCase__							:       Optional[int]  ,						UpperCamelCase__							:       Union[str, Any]  ,						UpperCamelCase__							:       Union[str, Any]  ,						UpperCamelCase__							:       Tuple  ,						UpperCamelCase__							:       Union[str, Any]  ,						UpperCamelCase__							:       int  ,						UpperCamelCase__							:       Tuple  ,						UpperCamelCase__							:       str  ,						)->     Any:



      '''simple docstring'''


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

    def 							lowercase_  (			self							:       str  ,						UpperCamelCase__							:       Union[str, Any]  ,						UpperCamelCase__							:       int  ,						UpperCamelCase__							:       List[Any]  ,						UpperCamelCase__							:       str  ,						UpperCamelCase__							:       List[str]  ,						UpperCamelCase__							:       Optional[int]  ,						UpperCamelCase__							:       Any  ,						UpperCamelCase__							:       Optional[Any]  ,						)->     str:



      '''simple docstring'''


      __lowerCAmelCase: str					   =    self.num_labels
      __lowerCAmelCase: int					   =    MarkupLMForTokenClassification(config=UpperCamelCase__)
      model.to(UpperCamelCase__)
      model.eval()
      __lowerCAmelCase: List[str]					   =    model(
          UpperCamelCase__  ,						xpath_tags_seq=UpperCamelCase__  ,						xpath_subs_seq=UpperCamelCase__  ,						attention_mask=UpperCamelCase__  ,						token_type_ids=UpperCamelCase__  ,						labels=UpperCamelCase__  ,						)
      self.parent.assertEqual(result.logits.shape  ,						(self.batch_size, self.seq_length, self.num_labels))

    def 							lowercase_  (			self							:       Optional[Any]  ,						UpperCamelCase__							:       Dict  ,						UpperCamelCase__							:       int  ,						UpperCamelCase__							:       List[Any]  ,						UpperCamelCase__							:       Optional[Any]  ,						UpperCamelCase__							:       List[str]  ,						UpperCamelCase__							:       str  ,						UpperCamelCase__							:       List[Any]  ,						UpperCamelCase__							:       Any  ,						)->     List[Any]:



      '''simple docstring'''


      __lowerCAmelCase: List[Any]					   =    MarkupLMForQuestionAnswering(config=UpperCamelCase__)
      model.to(UpperCamelCase__)
      model.eval()
      __lowerCAmelCase: Union[str, Any]					   =    model(
          UpperCamelCase__  ,						xpath_tags_seq=UpperCamelCase__  ,						xpath_subs_seq=UpperCamelCase__  ,						attention_mask=UpperCamelCase__  ,						token_type_ids=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 							lowercase_  (			self							:       Optional[Any])->     List[str]:



      '''simple docstring'''


      __lowerCAmelCase: Any					   =    self.prepare_config_and_inputs()
      (
          (
          __lowerCAmelCase       
      )   ,				(
          __lowerCAmelCase       
      )   ,				(
          __lowerCAmelCase       
      )   ,				(
          __lowerCAmelCase       
      )   ,				(
          __lowerCAmelCase       
      )   ,				(
          __lowerCAmelCase       
      )   ,				(
          __lowerCAmelCase       
      )   ,				(
          __lowerCAmelCase       
      )   ,				       
      ): List[str]					   =    config_and_inputs
      __lowerCAmelCase: int					   =    {
          "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 					snake_case			(       _UpperCAmelCase,							_UpperCAmelCase,							unittest.TestCase						):
    SCREAMING_SNAKE_CASE_     :   str        =						(
        (
            MarkupLMModel,
            MarkupLMForSequenceClassification,
            MarkupLMForTokenClassification,
            MarkupLMForQuestionAnswering,
        )
        if is_torch_available()
        else None
    )
    SCREAMING_SNAKE_CASE_     :   Optional[Any]        =						(
        {
            """feature-extraction""": MarkupLMModel,
            """question-answering""": MarkupLMForQuestionAnswering,
            """text-classification""": MarkupLMForSequenceClassification,
            """token-classification""": MarkupLMForTokenClassification,
            """zero-shot""": MarkupLMForSequenceClassification,
        }
        if is_torch_available()
        else {}
    )

    def 							lowercase_  (			self							:       Union[str, Any]  ,						UpperCamelCase__							:       Optional[Any]  ,						UpperCamelCase__							:       Optional[Any]  ,						UpperCamelCase__							:       Union[str, Any]  ,						UpperCamelCase__							:       Dict  ,						UpperCamelCase__							:       int)->     Dict:



      '''simple docstring'''


      return True

    def 							lowercase_  (			self							:       Optional[Any])->     Union[str, Any]:



      '''simple docstring'''


      __lowerCAmelCase: Union[str, Any]					   =    MarkupLMModelTester(self)
      __lowerCAmelCase: Union[str, Any]					   =    ConfigTester(self  ,						config_class=UpperCamelCase__  ,						hidden_size=3_7)

    def 							lowercase_  (			self							:       Optional[int])->     Tuple:



      '''simple docstring'''


      self.config_tester.run_common_tests()

    def 							lowercase_  (			self							:       List[Any])->     Tuple:



      '''simple docstring'''


      __lowerCAmelCase: Dict					   =    self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_model(*UpperCamelCase__)

    def 							lowercase_  (			self							:       Dict)->     Any:



      '''simple docstring'''


      __lowerCAmelCase: Any					   =    self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_for_sequence_classification(*UpperCamelCase__)

    def 							lowercase_  (			self							:       Tuple)->     List[str]:



      '''simple docstring'''


      __lowerCAmelCase: Tuple					   =    self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_for_token_classification(*UpperCamelCase__)




    def 							lowercase_  (			self							:       List[str])->     Union[str, Any]:



      '''simple docstring'''


      __lowerCAmelCase: List[str]					   =    self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_for_question_answering(*UpperCamelCase__)






def 					a__					(					)			->			Optional[Any]:
  __lowerCAmelCase: Optional[Any]					   =    "\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 					snake_case			(       unittest.TestCase						):

    @cached_property
    def 							lowercase_  (			self							:       Dict)->     str:



      '''simple docstring'''


      __lowerCAmelCase: int					   =    MarkupLMFeatureExtractor()
      __lowerCAmelCase: Dict					   =    MarkupLMTokenizer.from_pretrained("microsoft/markuplm-base")

      return MarkupLMProcessor(UpperCamelCase__  ,						UpperCamelCase__)




    @slow
    def 							lowercase_  (			self							:       Optional[Any])->     Tuple:



      '''simple docstring'''


      __lowerCAmelCase: List[str]					   =    MarkupLMModel.from_pretrained("microsoft/markuplm-base").to(UpperCamelCase__)

      __lowerCAmelCase: str					   =    self.default_processor

      __lowerCAmelCase: List[str]					   =    processor(prepare_html_string()  ,						return_tensors="pt")
      __lowerCAmelCase: List[str]					   =    inputs.to(UpperCamelCase__)

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

      # verify the last hidden states
      __lowerCAmelCase: Optional[int]					   =    torch.Size([1, 1_4, 7_6_8])
      self.assertEqual(outputs.last_hidden_state.shape  ,						UpperCamelCase__)

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

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





"""simple docstring"""


import math

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






def 					a__					(					__SCREAMING_SNAKE_CASE = 1      ,				__SCREAMING_SNAKE_CASE = 1				)			->			qiskit.result.counts.Counts:
		if isinstance(__SCREAMING_SNAKE_CASE      ,				__SCREAMING_SNAKE_CASE				) or isinstance(__SCREAMING_SNAKE_CASE      ,				__SCREAMING_SNAKE_CASE				):
				raise TypeError("inputs must be integers."				)
		if (bit_a < 0) or (bit_a < 0):
				raise ValueError("inputs must be positive."				)
		if (math.floor(__SCREAMING_SNAKE_CASE				) != bit_a) or (math.floor(__SCREAMING_SNAKE_CASE				) != 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
		__lowerCAmelCase: str					   =    QuantumRegister(2      ,				"qr"				)
		__lowerCAmelCase: Optional[Any]					   =    ClassicalRegister(2      ,				"cr"				)

		__lowerCAmelCase: Dict					   =    QuantumCircuit(__SCREAMING_SNAKE_CASE      ,				__SCREAMING_SNAKE_CASE				)

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

		# send the information
		__lowerCAmelCase: Dict					   =    str(__SCREAMING_SNAKE_CASE				) + str(__SCREAMING_SNAKE_CASE				)

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

		__lowerCAmelCase: List[str]					   =    Aer.get_backend("aer_simulator"				)
		__lowerCAmelCase: Dict					   =    execute(__SCREAMING_SNAKE_CASE      ,				__SCREAMING_SNAKE_CASE      ,				shots=1_0_0_0				)

		return job.result().get_counts(__SCREAMING_SNAKE_CASE				)


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


