
import os
import unicodedata
from shutil import copyfile
from typing import Any, Dict, List, Optional, Tuple

import sentencepiece as spm

from ...tokenization_utils import AddedToken, PreTrainedTokenizer
from ...utils import logging


__lowercase							:   str					=     logging.get_logger(__name__)
__lowercase							:   List[str]					=     {'''vocab_file''': '''spiece.model'''}

__lowercase							:   List[str]					=     {
    '''vocab_file''': {
        '''albert-base-v1''': '''https://huggingface.co/albert-base-v1/resolve/main/spiece.model''',
        '''albert-large-v1''': '''https://huggingface.co/albert-large-v1/resolve/main/spiece.model''',
        '''albert-xlarge-v1''': '''https://huggingface.co/albert-xlarge-v1/resolve/main/spiece.model''',
        '''albert-xxlarge-v1''': '''https://huggingface.co/albert-xxlarge-v1/resolve/main/spiece.model''',
        '''albert-base-v2''': '''https://huggingface.co/albert-base-v2/resolve/main/spiece.model''',
        '''albert-large-v2''': '''https://huggingface.co/albert-large-v2/resolve/main/spiece.model''',
        '''albert-xlarge-v2''': '''https://huggingface.co/albert-xlarge-v2/resolve/main/spiece.model''',
        '''albert-xxlarge-v2''': '''https://huggingface.co/albert-xxlarge-v2/resolve/main/spiece.model''',
    }
}

__lowercase							:   List[str]					=     {
    '''albert-base-v1''': 512,
    '''albert-large-v1''': 512,
    '''albert-xlarge-v1''': 512,
    '''albert-xxlarge-v1''': 512,
    '''albert-base-v2''': 512,
    '''albert-large-v2''': 512,
    '''albert-xlarge-v2''': 512,
    '''albert-xxlarge-v2''': 512,
}

__lowercase							:   Optional[Any]					=     '''▁'''

class 	__lowercase				(  _lowercase    ):
			lowerCamelCase			:		Tuple	      =			VOCAB_FILES_NAMES
			lowerCamelCase			:		Union[str, Any]	      =			PRETRAINED_VOCAB_FILES_MAP
			lowerCamelCase			:		List[str]	      =			PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES

			def __init__(self			,   A			,   A=True			,   A=True			,   A=False			,   A="[CLS]"			,   A="[SEP]"			,   A="<unk>"			,   A="[SEP]"			,   A="<pad>"			,   A="[CLS]"			,   A="[MASK]"			,   A = None			,   **A			,   ):
								# 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     =		(
								    AddedToken(A			,   lstrip=A			,   rstrip=A			,   normalized=A      )
								    if isinstance(A			,   A      )
								    else mask_token
								)

								lowerCamelCase_					:      Any     =		{} if sp_model_kwargs is None else sp_model_kwargs

								super().__init__(
								    do_lower_case=A			,   remove_space=A			,   keep_accents=A			,   bos_token=A			,   eos_token=A			,   unk_token=A			,   sep_token=A			,   pad_token=A			,   cls_token=A			,   mask_token=A			,   sp_model_kwargs=self.sp_model_kwargs			,   **A			,   )

								lowerCamelCase_					:      str     =		do_lower_case
								lowerCamelCase_					:      Dict     =		remove_space
								lowerCamelCase_					:      Union[str, Any]     =		keep_accents
								lowerCamelCase_					:      List[str]     =		vocab_file

								lowerCamelCase_					:      int     =		spm.SentencePieceProcessor(**self.sp_model_kwargs      )
								self.sp_model.Load(A      )

			@property
			def        UpperCAmelCase__ (self      ):
								return len(self.sp_model      )

			def        UpperCAmelCase__ (self      ):
								lowerCamelCase_					:      List[str]     =		{self.convert_ids_to_tokens(A      ): i for i in range(self.vocab_size      )}
								vocab.update(self.added_tokens_encoder      )
								return vocab

			def __getstate__(self      ):
								lowerCamelCase_					:      Any     =		self.__dict__.copy()
								lowerCamelCase_					:      int     =		None
								return state

			def __setstate__(self			,   A      ):
								lowerCamelCase_					:      Optional[int]     =		d

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

								lowerCamelCase_					:      str     =		spm.SentencePieceProcessor(**self.sp_model_kwargs      )
								self.sp_model.Load(self.vocab_file      )

			def        UpperCAmelCase__ (self			,   A      ):
								if self.remove_space:
													lowerCamelCase_					:      Union[str, Any]     =		''' '''.join(inputs.strip().split()      )
								else:
													lowerCamelCase_					:      Tuple     =		inputs
								lowerCamelCase_					:      str     =		outputs.replace('''``'''			,   '''"'''      ).replace('''\'\''''			,   '''"'''      )

								if not self.keep_accents:
													lowerCamelCase_					:      int     =		unicodedata.normalize('''NFKD'''			,   A      )
													lowerCamelCase_					:      Optional[Any]     =		''''''.join([c for c in outputs if not unicodedata.combining(A      )]      )
								if self.do_lower_case:
													lowerCamelCase_					:      Union[str, Any]     =		outputs.lower()

								return outputs

			def        UpperCAmelCase__ (self			,   A      ):
								lowerCamelCase_					:      Optional[Any]     =		self.preprocess_text(A      )
								lowerCamelCase_					:      Dict     =		self.sp_model.encode(A			,   out_type=A      )
								lowerCamelCase_					:      Union[str, Any]     =		[]
								for piece in pieces:
													if len(A      ) > 1 and piece[-1] == str(''','''      ) and piece[-2].isdigit():
																		lowerCamelCase_					:      Tuple     =		self.sp_model.EncodeAsPieces(piece[:-1].replace(A			,   ''''''      )      )
																		if piece[0] != SPIECE_UNDERLINE and cur_pieces[0][0] == SPIECE_UNDERLINE:
																							if len(cur_pieces[0]      ) == 1:
																												lowerCamelCase_					:      Optional[int]     =		cur_pieces[1:]
																							else:
																												lowerCamelCase_					:      List[str]     =		cur_pieces[0][1:]
																		cur_pieces.append(piece[-1]      )
																		new_pieces.extend(A      )
													else:
																		new_pieces.append(A      )

								return new_pieces

			def        UpperCAmelCase__ (self			,   A      ):
								return self.sp_model.PieceToId(A      )

			def        UpperCAmelCase__ (self			,   A      ):
								return self.sp_model.IdToPiece(A      )

			def        UpperCAmelCase__ (self			,   A      ):
								lowerCamelCase_					:      Optional[int]     =		[]
								lowerCamelCase_					:      List[Any]     =		''''''
								lowerCamelCase_					:      str     =		False
								for token in tokens:
													# make sure that special tokens are not decoded using sentencepiece model
													if token in self.all_special_tokens:
																		if not prev_is_special:
																							out_string += " "
																		out_string += self.sp_model.decode(A      ) + token
																		lowerCamelCase_					:      Dict     =		True
																		lowerCamelCase_					:      List[str]     =		[]
													else:
																		current_sub_tokens.append(A      )
																		lowerCamelCase_					:      str     =		False
								out_string += self.sp_model.decode(A      )
								return out_string.strip()

			def        UpperCAmelCase__ (self			,   A			,   A = None      ):
								lowerCamelCase_					:      Optional[Any]     =		[self.sep_token_id]
								lowerCamelCase_					:      Optional[Any]     =		[self.cls_token_id]
								if token_ids_a is None:
													return cls + token_ids_a + sep
								return cls + token_ids_a + sep + token_ids_a + sep

			def        UpperCAmelCase__ (self			,   A			,   A = None			,   A = False      ):

								if already_has_special_tokens:
													return super().get_special_tokens_mask(
													    token_ids_a=A			,   token_ids_a=A			,   already_has_special_tokens=A      )

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

			def        UpperCAmelCase__ (self			,   A			,   A = None      ):
								lowerCamelCase_					:      Tuple     =		[self.sep_token_id]
								lowerCamelCase_					:      Tuple     =		[self.cls_token_id]

								if token_ids_a is None:
													return len(cls + token_ids_a + sep      ) * [0]
								return len(cls + token_ids_a + sep      ) * [0] + len(token_ids_a + sep      ) * [1]






			def        UpperCAmelCase__ (self			,   A			,   A = None      ):
								if not os.path.isdir(A      ):
													logger.error(F"""Vocabulary path ({save_directory}) should be a directory"""      )
													return
								lowerCamelCase_					:      Any     =		os.path.join(
								    A			,   (filename_prefix + '''-''' if filename_prefix else '''''') + VOCAB_FILES_NAMES['''vocab_file''']      )

								if os.path.abspath(self.vocab_file      ) != os.path.abspath(A      ) and os.path.isfile(self.vocab_file      ):
													copyfile(self.vocab_file			,   A      )
								elif not os.path.isfile(self.vocab_file      ):
													with open(A			,   '''wb'''      ) as fi:
																		lowerCamelCase_					:      Any     =		self.sp_model.serialized_model_proto()
																		fi.write(A      )

								return (out_vocab_file,)




'''simple docstring'''


import qiskit




def lowercase_	(   _lowercase			,       _lowercase				)     ->							qiskit.result.counts.Counts:
					'''simple docstring'''

					lowerCamelCase_					:      Optional[Any]     =		qiskit.Aer.get_backend('''aer_simulator'''				)

					# Create a Quantum Circuit acting on the q register
					lowerCamelCase_					:      Optional[int]     =		qiskit.QuantumCircuit(_lowercase			,       _lowercase				)

					# Apply X (NOT) Gate to Qubits 0 & 1
					circuit.x(0				)
					circuit.x(1				)

					# Map the quantum measurement to the classical bits
					circuit.measure([0, 1]			,       [0, 1]				)

					# Execute the circuit on the qasm simulator
					lowerCamelCase_					:      Optional[int]     =		qiskit.execute(_lowercase			,       _lowercase			,       shots=1_000				)

					# Return the histogram data of the results of the experiment.
					return job.result().get_counts(_lowercase				)


if __name__ == "__main__":
					__lowercase							:   List[Any]					=     single_qubit_measure(2, 2)
					print(f'Total count for various states are: {counts}')


