



'''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 							lowerCAmelCase_		:





    def __init__(    self    :    Union[str, Any],    _snake_case    :    Union[str, Any],    _snake_case    :    int=13,    _snake_case    :    Optional[Any]=7,    _snake_case    :    Any=True,    _snake_case    :    List[str]=True,    _snake_case    :    Optional[int]=True,    _snake_case    :    List[str]=True,    _snake_case    :    Any=99,    _snake_case    :    Dict=32,    _snake_case    :    List[Any]=5,    _snake_case    :    str=4,    _snake_case    :    Union[str, Any]=37,    _snake_case    :    int="gelu",    _snake_case    :    int=0.1,    _snake_case    :    str=0.1,    _snake_case    :    str=512,    _snake_case    :    Dict=16,    _snake_case    :    int=2,    _snake_case    :    int=0.02,    _snake_case    :    Optional[Any]=3,    _snake_case    :    Optional[Any]=None,    _snake_case    :    List[Any]=20,    _snake_case    :    int=30,    _snake_case    :    Tuple=2,    _snake_case    :    Any=2,    _snake_case    :    Optional[Any]=10,    ):



       '''simple docstring'''







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





    def 					__snake_case       (    self    :    Tuple     ):



       '''simple docstring'''







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

       snake_case   :							List[Any]						  =ids_tensor(
           [self.batch_size, self.seq_length, self.max_depth],    self.max_xpath_tag_unit_embeddings     )

       snake_case   :							List[Any]						  =ids_tensor(
           [self.batch_size, self.seq_length, self.max_depth],    self.max_xpath_subs_unit_embeddings     )

       snake_case   :							Tuple						  =None
       if self.use_input_mask:
          snake_case   :							Union[str, Any]						  =ids_tensor([self.batch_size, self.seq_length],    vocab_size=2     )

       snake_case   :							List[Any]						  =None
       if self.use_token_type_ids:
          snake_case   :							List[str]						  =ids_tensor([self.batch_size, self.seq_length],    self.type_vocab_size     )

       snake_case   :							int						  =None
       snake_case   :							Tuple						  =None
       if self.use_labels:
          snake_case   :							Union[str, Any]						  =ids_tensor([self.batch_size],    self.type_sequence_label_size     )
          snake_case   :							Tuple						  =ids_tensor([self.batch_size, self.seq_length],    self.num_labels     )

       snake_case   :							Dict						  =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    :    Any     ):



       '''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    :    Union[str, Any],    _snake_case    :    Tuple,    _snake_case    :    Optional[int],    _snake_case    :    Dict,    _snake_case    :    List[str],    _snake_case    :    Any,    _snake_case    :    Any,    _snake_case    :    List[Any],    _snake_case    :    Optional[Any],    ):



       '''simple docstring'''







       snake_case   :							List[str]						  =MarkupLMModel(config=_snake_case     )
       model.to(_snake_case     )
       model.eval()
       print('''Configs:''',    model.config.tag_pad_id,    model.config.subs_pad_id     )
       snake_case   :							List[Any]						  =model(_snake_case,    attention_mask=_snake_case,    token_type_ids=_snake_case     )
       snake_case   :							List[Any]						  =model(_snake_case,    token_type_ids=_snake_case     )
       snake_case   :							Optional[Any]						  =model(_snake_case     )
       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    :    List[Any],    _snake_case    :    Any,    _snake_case    :    Dict,    _snake_case    :    Union[str, Any],    _snake_case    :    List[str],    _snake_case    :    Optional[Any],    _snake_case    :    Dict,    _snake_case    :    List[Any],    _snake_case    :    int,    ):



       '''simple docstring'''







       snake_case   :							Any						  =self.num_labels
       snake_case   :							List[Any]						  =MarkupLMForSequenceClassification(_snake_case     )
       model.to(_snake_case     )
       model.eval()
       snake_case   :							Optional[Any]						  =model(
           _snake_case,    xpath_tags_seq=_snake_case,    xpath_subs_seq=_snake_case,    attention_mask=_snake_case,    token_type_ids=_snake_case,    labels=_snake_case,    )
       self.parent.assertEqual(result.logits.shape,    (self.batch_size, self.num_labels)     )





    def 					__snake_case       (    self    :    int,    _snake_case    :    List[Any],    _snake_case    :    Optional[Any],    _snake_case    :    Tuple,    _snake_case    :    Optional[int],    _snake_case    :    str,    _snake_case    :    Any,    _snake_case    :    Tuple,    _snake_case    :    List[str],    ):



       '''simple docstring'''







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





    def 					__snake_case       (    self    :    Dict,    _snake_case    :    Union[str, Any],    _snake_case    :    List[Any],    _snake_case    :    Optional[Any],    _snake_case    :    Optional[Any],    _snake_case    :    Optional[Any],    _snake_case    :    str,    _snake_case    :    List[Any],    _snake_case    :    Any,    ):



       '''simple docstring'''







       snake_case   :							Optional[int]						  =MarkupLMForQuestionAnswering(config=_snake_case     )
       model.to(_snake_case     )
       model.eval()
       snake_case   :							int						  =model(
           _snake_case,    xpath_tags_seq=_snake_case,    xpath_subs_seq=_snake_case,    attention_mask=_snake_case,    token_type_ids=_snake_case,    start_positions=_snake_case,    end_positions=_snake_case,    )
       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    :    Optional[Any]     ):



       '''simple docstring'''







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





    def 					__snake_case       (    self    :    Optional[int],    _snake_case    :    List[Any],    _snake_case    :    Optional[int],    _snake_case    :    str,    _snake_case    :    Tuple,    _snake_case    :    str     ):



       '''simple docstring'''







       return True





    def 					__snake_case       (    self    :    List[Any]     ):



       '''simple docstring'''







       snake_case   :							List[Any]						  =MarkupLMModelTester(self     )
       snake_case   :							Optional[int]						  =ConfigTester(self,    config_class=_snake_case,    hidden_size=37     )





    def 					__snake_case       (    self    :    str     ):



       '''simple docstring'''







       self.config_tester.run_common_tests()





    def 					__snake_case       (    self    :    str     ):



       '''simple docstring'''







       snake_case   :							List[str]						  =self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_model(*_snake_case     )





    def 					__snake_case       (    self    :    Dict     ):



       '''simple docstring'''







       snake_case   :							Optional[Any]						  =self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_for_sequence_classification(*_snake_case     )





    def 					__snake_case       (    self    :    int     ):



       '''simple docstring'''







       snake_case   :							Tuple						  =self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_for_token_classification(*_snake_case     )






    def 					__snake_case       (    self    :    Optional[Any]     ):



       '''simple docstring'''







       snake_case   :							Tuple						  =self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_for_question_answering(*_snake_case     )




def 		_a   (  ):
   snake_case   :							str						  ='''
    <!DOCTYPE html>
    <html>
    <head>
    <title>Page Title</title>
    </head>
    <body>

    <h1>This is a Heading</h1>
    <p>This is a paragraph.</p>

    </body>
    </html>
    '''

   return html_string





@require_torch
class 							lowerCAmelCase_		(	unittest.TestCase						):





    @cached_property
    def 					__snake_case       (    self    :    List[Any]     ):



       '''simple docstring'''







       snake_case   :							int						  =MarkupLMFeatureExtractor()
       snake_case   :							Optional[Any]						  =MarkupLMTokenizer.from_pretrained('''microsoft/markuplm-base'''     )

       return MarkupLMProcessor(_snake_case,    _snake_case     )






    @slow
    def 					__snake_case       (    self    :    List[str]     ):



       '''simple docstring'''







       snake_case   :							str						  =MarkupLMModel.from_pretrained('''microsoft/markuplm-base'''     ).to(_snake_case     )

       snake_case   :							Tuple						  =self.default_processor

       snake_case   :							int						  =processor(prepare_html_string(),    return_tensors='''pt'''     )
       snake_case   :							Union[str, Any]						  =inputs.to(_snake_case     )

       # forward pass
       with torch.no_grad():
          snake_case   :							Tuple						  =model(**_snake_case     )

       # verify the last hidden states
       snake_case   :							List[str]						  =torch.Size([1, 14, 768]     )
       self.assertEqual(outputs.last_hidden_state.shape,    _snake_case     )

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

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










'''simple docstring'''





import doctest

import projectq
from projectq.ops import H, Measure
def 		_a   (  lowerCamelCase_							):
   snake_case   :							str						  =quantum_engine.allocate_qubit()
   H | qubit
   Measure | qubit
   return int(lowerCamelCase_							)


if __name__ == "__main__":
      doctest.testmod()

      # initialises a new quantum backend
      A			:   Dict			=      projectq.MainEngine()

      # Generate a list of 10 random numbers
      A			:   Dict			=      [get_random_number(quantum_engine) for _ in range(10)]

      # Flushes the quantum engine from memory
      quantum_engine.flush()

      print("""Random numbers""", random_numbers_list)





