





import io
import os
import unicodedata
from typing import Any, Dict, List, Optional, Tuple

import sentencepiece as spm

from ...tokenization_utils import PreTrainedTokenizer
from ...utils import logging


__UpperCAmelCase	:       Tuple    	=							logging.get_logger(__name__)

__UpperCAmelCase	:       List[Any]    	=							"▁"

__UpperCAmelCase	:       Optional[int]    	=							{"vocab_file": "vocab.txt", "sentencepiece_model_ckpt": "sentencepiece.bpe.model"}

__UpperCAmelCase	:       str    	=							{
    "sentencepiece_model_file": "sentencepiece.bpe.model",
    "vocab_file": "vocab.txt",
}

__UpperCAmelCase	:       Optional[Any]    	=							{
    "vocab_file": {
        "ernie-m-base": "https://huggingface.co/susnato/ernie-m-base_pytorch/blob/main/vocab.txt",
        "ernie-m-large": "https://huggingface.co/susnato/ernie-m-base_pytorch/blob/main/vocab.txt",
    },
    "sentencepiece_model_file": {
        "ernie-m-base": "https://huggingface.co/susnato/ernie-m-base_pytorch/blob/main/sentencepiece.bpe.model",
        "ernie-m-large": "https://huggingface.co/susnato/ernie-m-base_pytorch/blob/main/sentencepiece.bpe.model",
    },
}

__UpperCAmelCase	:       Any    	=							{
    "ernie-m-base": 514,
    "ernie-m-large": 514,
}

__UpperCAmelCase	:       Dict    	=							{
    "ernie-m-base": {"do_lower_case": False},
    "ernie-m-large": {"do_lower_case": False},
}







class    __snake_case	(							__UpperCamelCase      ):





       '''simple docstring'''







       lowerCAmelCase__						=					["input_ids"]

       lowerCAmelCase__						=					VOCAB_FILES_NAMES
       lowerCAmelCase__						=					PRETRAINED_INIT_CONFIGURATION
       lowerCAmelCase__						=					PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
       lowerCAmelCase__						=					PRETRAINED_VOCAB_FILES_MAP
       lowerCAmelCase__						=					RESOURCE_FILES_NAMES




       def __init__(  self			:   int							,    A			:   Optional[int]							,    A			:   Dict=None							,    A			:   Dict=False							,    A			:   List[Any]="utf8"							,    A			:   Optional[Any]="[UNK]"							,    A			:   Optional[int]="[SEP]"							,    A			:   List[str]="[PAD]"							,    A			:   Dict="[CLS]"							,    A			:   List[Any]="[MASK]"							,    A			:   Optional[Dict[str, Any]] = None							,    **A			:   Any							,    ):
         # Mask token behave like a normal word, i.e. include the space before it and
         # is included in the raw text, there should be a match in a non-normalized sentence.

         __snake_case:						List[Any]			  =						{} if sp_model_kwargs is None else sp_model_kwargs
         super().__init__(
             do_lower_case=_lowerCAmelCase							,    unk_token=_lowerCAmelCase							,    sep_token=_lowerCAmelCase							,    pad_token=_lowerCAmelCase							,    cls_token=_lowerCAmelCase							,    mask_token=_lowerCAmelCase							,    vocab_file=_lowerCAmelCase							,    encoding=_lowerCAmelCase							,    sp_model_kwargs=self.sp_model_kwargs							,    **_lowerCAmelCase							,    )
         __snake_case:						List[Any]			  =						do_lower_case
         __snake_case:						Any			  =						sentencepiece_model_ckpt
         __snake_case:						int			  =						spm.SentencePieceProcessor(**self.sp_model_kwargs		)
         self.sp_model.Load(_lowerCAmelCase		)

         # to mimic paddlenlp.transformers.ernie_m.tokenizer.ErnieMTokenizer functioning
         if vocab_file is not None:
           __snake_case:						int			  =						self.load_vocab(filepath=_lowerCAmelCase		)
         else:
           __snake_case:						Tuple			  =						{self.sp_model.id_to_piece(_lowerCAmelCase		): id for id in range(self.sp_model.get_piece_size()		)}
         __snake_case:						str			  =						{v: k for k, v in self.vocab.items()}




       def 							UpperCAmelCase__			(  self			:   List[Any]							,    A			:   List[Any]		):
         if text is None:
           return None

         __snake_case:						List[Any]			  =						self.tokenize(_lowerCAmelCase		)
         __snake_case:						Optional[Any]			  =						"""""", []

         for i, ch in enumerate(_lowerCAmelCase		):
           if ch in self.SP_CHAR_MAPPING:
             __snake_case:						Any			  =						self.SP_CHAR_MAPPING.get(_lowerCAmelCase		)
           else:
             __snake_case:						Dict			  =						unicodedata.normalize("""NFKC"""							,    _lowerCAmelCase		)
           if self.is_whitespace(_lowerCAmelCase		):
             continue
           normalized_text += ch
           char_mapping.extend([i] * len(_lowerCAmelCase		)		)

         __snake_case:						str			  =						normalized_text, [], 0

         if self.do_lower_case:
           __snake_case:						int			  =						text.lower()

         for token in split_tokens:
           if token[:1] == "▁":
             __snake_case:						int			  =						token[1:]
           __snake_case:						Optional[int]			  =						text[offset:].index(_lowerCAmelCase		) + offset
           __snake_case:						int			  =						start + len(_lowerCAmelCase		)

           token_mapping.append((char_mapping[start], char_mapping[end - 1] + 1)		)
           __snake_case:						str			  =						end
         return token_mapping




       @property
       def 							UpperCAmelCase__			(  self			:   Tuple		):
         return len(self.vocab		)




       def 							UpperCAmelCase__			(  self			:   Dict		):
         return dict(self.vocab							,    **self.added_tokens_encoder		)




       def __getstate__(  self			:   int		):
         __snake_case:						str			  =						self.__dict__.copy()
         __snake_case:						Union[str, Any]			  =						None
         return state




       def __setstate__(  self			:   Optional[Any]							,    A			:   List[str]		):
         __snake_case:						Union[str, Any]			  =						d

         # for backward compatibility
         if not hasattr(self							,    """sp_model_kwargs"""		):
           __snake_case:						Optional[Any]			  =						{}

         __snake_case:						Union[str, Any]			  =						spm.SentencePieceProcessor(**self.sp_model_kwargs		)
         self.sp_model.Load(self.sentencepiece_model_ckpt		)




       def 							UpperCAmelCase__			(  self			:   str							,    A			:   Optional[int]		):
         return "".join((self.SP_CHAR_MAPPING.get(_lowerCAmelCase							,    _lowerCAmelCase		) for c in text)		)




       def 							UpperCAmelCase__			(  self			:   Optional[Any]							,    A			:   str							,    A			:   Tuple=False							,    A			:   Optional[Any]=64							,    A			:   Optional[int]=0.1		):

         if self.sp_model_kwargs.get("""enable_sampling"""		) is True:
           __snake_case:						List[str]			  =						True
         if self.sp_model_kwargs.get("""alpha"""		) is not None:
           __snake_case:						Dict			  =						self.sp_model_kwargs.get("""alpha"""		)
         if self.sp_model_kwargs.get("""nbest_size"""		) is not None:
           __snake_case:						List[Any]			  =						self.sp_model_kwargs.get("""nbest_size"""		)

         if not enable_sampling:
           __snake_case:						str			  =						self.sp_model.EncodeAsPieces(_lowerCAmelCase		)
         else:
           __snake_case:						Tuple			  =						self.sp_model.SampleEncodeAsPieces(_lowerCAmelCase							,    _lowerCAmelCase							,    _lowerCAmelCase		)
         __snake_case:						Union[str, Any]			  =						[]
         for pi, piece in enumerate(_lowerCAmelCase		):
           if piece == SPIECE_UNDERLINE:
             if not pieces[pi + 1].startswith(_lowerCAmelCase		) and pi != 0:
               new_pieces.append(_lowerCAmelCase		)
               continue
             else:
               continue
           __snake_case:						Optional[int]			  =						0
           for i, chunk in enumerate(_lowerCAmelCase		):
             if chunk == SPIECE_UNDERLINE:
               continue
             if self.is_ch_char(_lowerCAmelCase		) or self.is_punct(_lowerCAmelCase		):
               if i > lst_i and piece[lst_i:i] != SPIECE_UNDERLINE:
                 new_pieces.append(piece[lst_i:i]		)
               new_pieces.append(_lowerCAmelCase		)
               __snake_case:						Tuple			  =						i + 1
             elif chunk.isdigit() and i > 0 and not piece[i - 1].isdigit():
               if i > lst_i and piece[lst_i:i] != SPIECE_UNDERLINE:
                 new_pieces.append(piece[lst_i:i]		)
               __snake_case:						List[str]			  =						i
             elif not chunk.isdigit() and i > 0 and piece[i - 1].isdigit():
               if i > lst_i and piece[lst_i:i] != SPIECE_UNDERLINE:
                 new_pieces.append(piece[lst_i:i]		)
               __snake_case:						Tuple			  =						i
           if len(_lowerCAmelCase		) > lst_i:
             new_pieces.append(piece[lst_i:]		)
         return new_pieces




       def 							UpperCAmelCase__			(  self			:   Union[str, Any]							,    A			:   int		):
         __snake_case:						int			  =						"""""".join(_lowerCAmelCase		).replace(_lowerCAmelCase							,    """ """		).strip()
         return out_string




       def 							UpperCAmelCase__			(  self			:   Dict							,    A			:   Tuple		):
         __snake_case:						int			  =						self.convert_ids_to_tokens(_lowerCAmelCase		)
         __snake_case:						Any			  =						"""""".join(_lowerCAmelCase		).replace(_lowerCAmelCase							,    """ """		).strip()
         return out_string




       def 							UpperCAmelCase__			(  self			:   Dict							,    A			:   Tuple		):
         return self.vocab.get(_lowerCAmelCase							,    self.vocab.get(self.unk_token		)		)




       def 							UpperCAmelCase__			(  self			:   Union[str, Any]							,    A			:   Dict		):
         return self.reverse_vocab.get(_lowerCAmelCase							,    self.unk_token		)




       def 							UpperCAmelCase__			(  self			:   Any							,    A			:   Union[str, Any]							,    A			:   Union[str, Any]=None		):
         if token_ids_a is None:
           return [self.cls_token_id] + token_ids_a + [self.sep_token_id]
         __snake_case:						Union[str, Any]			  =						[self.cls_token_id]
         __snake_case:						Optional[Any]			  =						[self.sep_token_id]
         return _cls + token_ids_a + _sep + _sep + token_ids_a + _sep




       def 							UpperCAmelCase__			(  self			:   List[str]							,    A			:   Optional[Any]							,    A			:   Optional[Any]=None		):
         if offset_mapping_a is None:
           return [(0, 0)] + offset_mapping_a + [(0, 0)]

         return [(0, 0)] + offset_mapping_a + [(0, 0), (0, 0)] + offset_mapping_a + [(0, 0)]




       def 							UpperCAmelCase__			(  self			:   Optional[Any]							,    A			:   Optional[Any]							,    A			:   Optional[Any]=None							,    A			:   Optional[Any]=False		):

         if already_has_special_tokens:
           if token_ids_a is not None:
             raise ValueError(
                 """You should not supply a second sequence if the provided sequence of """
                 """ids is already formatted with special tokens for the model."""		)
           return [1 if x in [self.sep_token_id, self.cls_token_id] else 0 for x in token_ids_a]

         if token_ids_a is not None:
           return [1] + ([0] * len(_lowerCAmelCase		)) + [1, 1] + ([0] * len(_lowerCAmelCase		)) + [1]
         return [1] + ([0] * len(_lowerCAmelCase		)) + [1]




       def 							UpperCAmelCase__			(  self			:   Optional[int]							,    A			:   List[int]							,    A			:   Optional[List[int]] = None		):
         # called when `add_special_tokens` is True, so align with `build_inputs_with_special_tokens` method
         if token_ids_a is None:
           # [CLS] X [SEP]
           return (len(_lowerCAmelCase		) + 2) * [0]

         # [CLS] A [SEP] [SEP] B [SEP]
         return [0] * (len(_lowerCAmelCase		) + 1) + [1] * (len(_lowerCAmelCase		) + 3)




       def 							UpperCAmelCase__			(  self			:   Tuple							,    A			:   List[str]		):
         if "\u4e00" <= char <= "\u9fff":
           return True
         return False




       def 							UpperCAmelCase__			(  self			:   List[str]							,    A			:   Any		):
         if ("a" <= char <= "z") or ("A" <= char <= "Z"):
           return True
         return False




       def 							UpperCAmelCase__			(  self			:   int							,    A			:   List[Any]		):
         if char in ",;:.?!~，；：。？！《》【】":
           return True
         return False




       def 							UpperCAmelCase__			(  self			:   str							,    A			:   Optional[Any]		):
         if char == " " or char == "\t" or char == "\n" or char == "\r":
           return True
         if len(_lowerCAmelCase		) == 1:
           __snake_case:						Dict			  =						unicodedata.category(_lowerCAmelCase		)
           if cat == "Zs":
             return True
         return False




       def 							UpperCAmelCase__			(  self			:   str							,    A			:   List[Any]		):
         __snake_case:						Dict			  =						{}
         with io.open(_lowerCAmelCase							,    """r"""							,    encoding="""utf-8"""		) as f:
           for index, line in enumerate(_lowerCAmelCase		):
             __snake_case:						Tuple			  =						line.rstrip("""\n"""		)
             __snake_case:						List[str]			  =						int(_lowerCAmelCase		)

         return token_to_idx






       def 							UpperCAmelCase__			(  self			:   Union[str, Any]							,    A			:   str							,    A			:   Optional[str] = None		):
         __snake_case:						Optional[int]			  =						0
         if os.path.isdir(_lowerCAmelCase		):
           __snake_case:						int			  =						os.path.join(
               _lowerCAmelCase							,    (filename_prefix + """-""" if filename_prefix else """""") + VOCAB_FILES_NAMES["""vocab_file"""]		)
         else:
           __snake_case:						Optional[Any]			  =						(filename_prefix + """-""" if filename_prefix else """""") + save_directory
         with open(_lowerCAmelCase							,    """w"""							,    encoding="""utf-8"""		) as writer:
           for token, token_index in sorted(self.vocab.items()							,    key=lambda A		: kv[1]		):
             if index != token_index:
               logger.warning(
                   f'''Saving vocabulary to {vocab_file}: vocabulary indices are not consecutive.'''
                   """ Please check that the vocabulary is not corrupted!"""		)
               __snake_case:						Union[str, Any]			  =						token_index
             writer.write(token + """\n"""		)
             index += 1

         __snake_case:						List[Any]			  =						os.path.join(_lowerCAmelCase							,    """sentencepiece.bpe.model"""		)
         with open(_lowerCAmelCase							,    """wb"""		) as fi:
           __snake_case:						List[Any]			  =						self.sp_model.serialized_model_proto()
           fi.write(_lowerCAmelCase		)

         return (vocab_file,)








import math

import numpy as np
import qiskit
from qiskit import Aer, ClassicalRegister, QuantumCircuit, QuantumRegister, execute







def       A__							(   SCREAMING_SNAKE_CASE__ = 3)       ->   qiskit.result.counts.Counts:
  if isinstance(SCREAMING_SNAKE_CASE__ , SCREAMING_SNAKE_CASE__):
    raise TypeError("""number of qubits must be a integer.""")
  if number_of_qubits <= 0:
    raise ValueError("""number of qubits must be > 0.""")
  if math.floor(SCREAMING_SNAKE_CASE__) != number_of_qubits:
    raise ValueError("""number of qubits must be exact integer.""")
  if number_of_qubits > 10:
    raise ValueError("""number of qubits too large to simulate(>10).""")

  __snake_case:						int			  =						QuantumRegister(SCREAMING_SNAKE_CASE__ , """qr""")
  __snake_case:						List[str]			  =						ClassicalRegister(SCREAMING_SNAKE_CASE__ , """cr""")

  __snake_case:						Optional[Any]			  =						QuantumCircuit(SCREAMING_SNAKE_CASE__ , SCREAMING_SNAKE_CASE__)

  __snake_case:						Tuple			  =						number_of_qubits

  for i in range(SCREAMING_SNAKE_CASE__):
    quantum_circuit.h(number_of_qubits - i - 1)
    counter -= 1
    for j in range(SCREAMING_SNAKE_CASE__):
      quantum_circuit.cp(np.pi / 2 ** (counter - j) , SCREAMING_SNAKE_CASE__ , SCREAMING_SNAKE_CASE__)

  for k in range(number_of_qubits // 2):
    quantum_circuit.swap(SCREAMING_SNAKE_CASE__ , number_of_qubits - k - 1)

  # measure all the qubits
  quantum_circuit.measure(SCREAMING_SNAKE_CASE__ , SCREAMING_SNAKE_CASE__)
  # simulate with 10000 shots
  __snake_case:						Union[str, Any]			  =						Aer.get_backend("""qasm_simulator""")
  __snake_case:						Optional[Any]			  =						execute(SCREAMING_SNAKE_CASE__ , SCREAMING_SNAKE_CASE__ , shots=1_0000)

  return job.result().get_counts(SCREAMING_SNAKE_CASE__)


if __name__ == "__main__":
      print(
          f'Total count for quantum fourier transform state is: \
    {quantum_fourier_transform(3)}'
      )






