


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			:  Any     =logging.get_logger(__name__)

_UpperCAmelCase			:  Dict     ="""▁"""

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

_UpperCAmelCase			:  List[Any]     ={
    """sentencepiece_model_file""": """sentencepiece.bpe.model""",
    """vocab_file""": """vocab.txt""",
}

_UpperCAmelCase			:  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			:  int     ={
    """ernie-m-base""": 514,
    """ernie-m-large""": 514,
}

_UpperCAmelCase			:  int     ={
    """ernie-m-base""": {"""do_lower_case""": False},
    """ernie-m-large""": {"""do_lower_case""": False},
}







class 				snake_case__(							UpperCAmelCase__							):







						'''simple docstring'''




						SCREAMING_SNAKE_CASE__      :  List[str]					=							["input_ids"]

						SCREAMING_SNAKE_CASE__      :  List[Any]					=							VOCAB_FILES_NAMES
						SCREAMING_SNAKE_CASE__      :  int					=							PRETRAINED_INIT_CONFIGURATION
						SCREAMING_SNAKE_CASE__      :  Dict					=							PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
						SCREAMING_SNAKE_CASE__      :  List[str]					=							PRETRAINED_VOCAB_FILES_MAP
						SCREAMING_SNAKE_CASE__      :  Any					=							RESOURCE_FILES_NAMES




						def __init__(				self   ,						__lowercase   ,						__lowercase=None   ,						__lowercase=False   ,						__lowercase="utf8"   ,						__lowercase="[UNK]"   ,						__lowercase="[SEP]"   ,						__lowercase="[PAD]"   ,						__lowercase="[CLS]"   ,						__lowercase="[MASK]"   ,						__lowercase = None   ,						**__lowercase   ,						)					->    None:
										# 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.

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

										# to mimic paddlenlp.transformers.ernie_m.tokenizer.ErnieMTokenizer functioning
										if vocab_file is not None:
														lowerCAmelCase_ :      Union[str, Any]    				=				self.load_vocab(filepath=__lowercase							)
										else:
														lowerCAmelCase_ :      Any    				=				{self.sp_model.id_to_piece(__lowercase							): id for id in range(self.sp_model.get_piece_size()							)}
										lowerCAmelCase_ :      str    				=				{v: k for k, v in self.vocab.items()}




						def 						lowercase_ (				self   ,						__lowercase							)					->    Union[str, Any]:
										if text is None:
														return None

										lowerCAmelCase_ :      Any    				=				self.tokenize(__lowercase							)
										lowerCAmelCase_				,  lowerCAmelCase_ :      Dict    				=				'''''', []

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

										lowerCAmelCase_				,  lowerCAmelCase_				,  lowerCAmelCase_ :      int    				=				normalized_text, [], 0

										if self.do_lower_case:
														lowerCAmelCase_ :      Dict    				=				text.lower()

										for token in split_tokens:
														if token[:1] == "▁":
																		lowerCAmelCase_ :      Dict    				=				token[1:]
														lowerCAmelCase_ :      Union[str, Any]    				=				text[offset:].index(__lowercase							) + offset
														lowerCAmelCase_ :      Any    				=				start + len(__lowercase							)

														token_mapping.append((char_mapping[start], char_mapping[end - 1] + 1)							)
														lowerCAmelCase_ :      Optional[int]    				=				end
										return token_mapping




						@property
						def 						lowercase_ (				self							)					->    Dict:
										return len(self.vocab							)




						def 						lowercase_ (				self							)					->    Dict:
										return dict(self.vocab   ,						**self.added_tokens_encoder							)




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




						def __setstate__(				self   ,						__lowercase							)					->    int:
										lowerCAmelCase_ :      Optional[int]    				=				d

										# for backward compatibility
										if not hasattr(self   ,						'''sp_model_kwargs'''							):
														lowerCAmelCase_ :      Optional[int]    				=				{}

										lowerCAmelCase_ :      Optional[int]    				=				spm.SentencePieceProcessor(**self.sp_model_kwargs							)
										self.sp_model.Load(self.sentencepiece_model_ckpt							)




						def 						lowercase_ (				self   ,						__lowercase							)					->    List[str]:
										return "".join((self.SP_CHAR_MAPPING.get(__lowercase   ,						__lowercase							) for c in text)							)




						def 						lowercase_ (				self   ,						__lowercase   ,						__lowercase=False   ,						__lowercase=6_4   ,						__lowercase=0.1							)					->    Optional[Any]:

										if self.sp_model_kwargs.get('''enable_sampling'''							) is True:
														lowerCAmelCase_ :      int    				=				True
										if self.sp_model_kwargs.get('''alpha'''							) is not None:
														lowerCAmelCase_ :      Optional[Any]    				=				self.sp_model_kwargs.get('''alpha'''							)
										if self.sp_model_kwargs.get('''nbest_size'''							) is not None:
														lowerCAmelCase_ :      List[str]    				=				self.sp_model_kwargs.get('''nbest_size'''							)

										if not enable_sampling:
														lowerCAmelCase_ :      Union[str, Any]    				=				self.sp_model.EncodeAsPieces(__lowercase							)
										else:
														lowerCAmelCase_ :      Optional[int]    				=				self.sp_model.SampleEncodeAsPieces(__lowercase   ,						__lowercase   ,						__lowercase							)
										lowerCAmelCase_ :      str    				=				[]
										for pi, piece in enumerate(__lowercase							):
														if piece == SPIECE_UNDERLINE:
																		if not pieces[pi + 1].startswith(__lowercase							) and pi != 0:
																						new_pieces.append(__lowercase							)
																						continue
																		else:
																						continue
														lowerCAmelCase_ :      Optional[Any]    				=				0
														for i, chunk in enumerate(__lowercase							):
																		if chunk == SPIECE_UNDERLINE:
																						continue
																		if self.is_ch_char(__lowercase							) or self.is_punct(__lowercase							):
																						if i > lst_i and piece[lst_i:i] != SPIECE_UNDERLINE:
																										new_pieces.append(piece[lst_i:i]							)
																						new_pieces.append(__lowercase							)
																						lowerCAmelCase_ :      str    				=				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]							)
																						lowerCAmelCase_ :      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]							)
																						lowerCAmelCase_ :      Tuple    				=				i
														if len(__lowercase							) > lst_i:
																		new_pieces.append(piece[lst_i:]							)
										return new_pieces




						def 						lowercase_ (				self   ,						__lowercase							)					->    Optional[int]:
										lowerCAmelCase_ :      List[Any]    				=				''''''.join(__lowercase							).replace(__lowercase   ,						''' '''							).strip()
										return out_string




						def 						lowercase_ (				self   ,						__lowercase							)					->    List[str]:
										lowerCAmelCase_ :      Dict    				=				self.convert_ids_to_tokens(__lowercase							)
										lowerCAmelCase_ :      Any    				=				''''''.join(__lowercase							).replace(__lowercase   ,						''' '''							).strip()
										return out_string




						def 						lowercase_ (				self   ,						__lowercase							)					->    Optional[Any]:
										return self.vocab.get(__lowercase   ,						self.vocab.get(self.unk_token							)							)




						def 						lowercase_ (				self   ,						__lowercase							)					->    Union[str, Any]:
										return self.reverse_vocab.get(__lowercase   ,						self.unk_token							)




						def 						lowercase_ (				self   ,						__lowercase   ,						__lowercase=None							)					->    Tuple:
										if token_ids_a is None:
														return [self.cls_token_id] + token_ids_a + [self.sep_token_id]
										lowerCAmelCase_ :      Tuple    				=				[self.cls_token_id]
										lowerCAmelCase_ :      List[str]    				=				[self.sep_token_id]
										return _cls + token_ids_a + _sep + _sep + token_ids_a + _sep




						def 						lowercase_ (				self   ,						__lowercase   ,						__lowercase=None							)					->    str:
										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 						lowercase_ (				self   ,						__lowercase   ,						__lowercase=None   ,						__lowercase=False							)					->    Optional[int]:

										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(__lowercase							)) + [1, 1] + ([0] * len(__lowercase							)) + [1]
										return [1] + ([0] * len(__lowercase							)) + [1]




						def 						lowercase_ (				self   ,						__lowercase   ,						__lowercase = None							)					->    List[int]:
										# 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(__lowercase							) + 2) * [0]

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




						def 						lowercase_ (				self   ,						__lowercase							)					->    Any:
										if "\u4e00" <= char <= "\u9fff":
														return True
										return False




						def 						lowercase_ (				self   ,						__lowercase							)					->    Dict:
										if ("a" <= char <= "z") or ("A" <= char <= "Z"):
														return True
										return False




						def 						lowercase_ (				self   ,						__lowercase							)					->    Optional[int]:
										if char in ",;:.?!~，；：。？！《》【】":
														return True
										return False




						def 						lowercase_ (				self   ,						__lowercase							)					->    List[str]:
										if char == " " or char == "\t" or char == "\n" or char == "\r":
														return True
										if len(__lowercase							) == 1:
														lowerCAmelCase_ :      Tuple    				=				unicodedata.category(__lowercase							)
														if cat == "Zs":
																		return True
										return False




						def 						lowercase_ (				self   ,						__lowercase							)					->    List[str]:
										lowerCAmelCase_ :      int    				=				{}
										with io.open(__lowercase   ,						'''r'''   ,						encoding='''utf-8'''							) as f:
														for index, line in enumerate(__lowercase							):
																		lowerCAmelCase_ :      Optional[Any]    				=				line.rstrip('''\n'''							)
																		lowerCAmelCase_ :      List[str]    				=				int(__lowercase							)

										return token_to_idx




						def 						lowercase_ (				self   ,						__lowercase   ,						__lowercase = None							)					->    Tuple[str]:
										lowerCAmelCase_ :      Optional[int]    				=				0
										if os.path.isdir(__lowercase							):
														lowerCAmelCase_ :      Union[str, Any]    				=				os.path.join(
														    __lowercase   ,						(filename_prefix + '''-''' if filename_prefix else '''''') + VOCAB_FILES_NAMES['''vocab_file''']							)
										else:
														lowerCAmelCase_ :      int    				=				(filename_prefix + '''-''' if filename_prefix else '''''') + save_directory
										with open(__lowercase   ,						'''w'''   ,						encoding='''utf-8'''							) as writer:
														for token, token_index in sorted(self.vocab.items()   ,						key=lambda __lowercase							: 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!'''							)
																						lowerCAmelCase_ :      Optional[int]    				=				token_index
																		writer.write(token + '''\n'''							)
																		index += 1

										lowerCAmelCase_ :      Optional[int]    				=				os.path.join(__lowercase   ,						'''sentencepiece.bpe.model'''							)
										with open(__lowercase   ,						'''wb'''							) as fi:
														lowerCAmelCase_ :      Any    				=				self.sp_model.serialized_model_proto()
														fi.write(__lowercase							)

										return (vocab_file,)



import math

import qiskit



def 			lowerCAmelCase (		lowerCAmelCase_ = 1 ,   lowerCAmelCase_ = 1 ,   lowerCAmelCase_ = 1 )-> qiskit.result.counts.Counts:
				if (
				    isinstance(lowerCAmelCase_ ,   lowerCAmelCase_ )
				    or isinstance(lowerCAmelCase_ ,   lowerCAmelCase_ )
				    or isinstance(lowerCAmelCase_ ,   lowerCAmelCase_ )
				):
								raise TypeError('''inputs must be integers.''' )

				if (input_a < 0) or (input_a < 0) or (carry_in < 0):
								raise ValueError('''inputs must be positive.''' )

				if (
				    (math.floor(lowerCAmelCase_ ) != input_a)
				    or (math.floor(lowerCAmelCase_ ) != input_a)
				    or (math.floor(lowerCAmelCase_ ) != carry_in)
				):
								raise ValueError('''inputs must be exact integers.''' )

				if (input_a > 2) or (input_a > 2) or (carry_in > 2):
								raise ValueError('''inputs must be less or equal to 2.''' )

				# build registers
				lowerCAmelCase_ :      str    				=				qiskit.QuantumRegister(4 ,   '''qr''' )
				lowerCAmelCase_ :      str    				=				qiskit.ClassicalRegister(2 ,   '''cr''' )
				# list the entries
				lowerCAmelCase_ :      Any    				=				[input_a, input_a, carry_in]

				lowerCAmelCase_ :      int    				=				qiskit.QuantumCircuit(lowerCAmelCase_ ,   lowerCAmelCase_ )

				for i in range(0 ,   3 ):
								if entry[i] == 2:
												quantum_circuit.h(lowerCAmelCase_ )  # for hadamard entries
								elif entry[i] == 1:
												quantum_circuit.x(lowerCAmelCase_ )  # for 1 entries
								elif entry[i] == 0:
												quantum_circuit.i(lowerCAmelCase_ )  # for 0 entries

    # build the circuit
				quantum_circuit.ccx(0 ,   1 ,   3 )  # ccx = toffoli gate
				quantum_circuit.cx(0 ,   1 )
				quantum_circuit.ccx(1 ,   2 ,   3 )
				quantum_circuit.cx(1 ,   2 )
				quantum_circuit.cx(0 ,   1 )

				quantum_circuit.measure([2, 3] ,   lowerCAmelCase_ )  # measure the last two qbits

				lowerCAmelCase_ :      Tuple    				=				qiskit.Aer.get_backend('''aer_simulator''' )
				lowerCAmelCase_ :      Union[str, Any]    				=				qiskit.execute(lowerCAmelCase_ ,   lowerCAmelCase_ ,   shots=1_000 )

				return job.result().get_counts(lowerCAmelCase_ )


if __name__ == "__main__":
						print(f"""Total sum count for state is: {quantum_full_adder(1, 1, 1)}""")