


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

import sentencepiece as spm

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


if is_torch_available():
						import torch


if TYPE_CHECKING:
						from transformers.pipelines.conversational import Conversation


_UpperCAmelCase			:  Optional[Any]     =logging.get_logger(__name__)
_UpperCAmelCase			:  List[Any]     ={"""vocab_file""": """spiece.model"""}

_UpperCAmelCase			:  Union[str, Any]     ={
    """vocab_file""": {
        """AI-Sweden/gpt-sw3-126m""": """https://huggingface.co/AI-Sweden/gpt-sw3-126m/resolve/main/spiece.model""",
        """AI-Sweden/gpt-sw3-350m""": """https://huggingface.co/AI-Sweden/gpt-sw3-350m/resolve/main/spiece.model""",
        """AI-Sweden/gpt-sw3-1.6b""": """https://huggingface.co/AI-Sweden/gpt-sw3-1.6b/resolve/main/spiece.model""",
        """AI-Sweden/gpt-sw3-6.7b""": """https://huggingface.co/AI-Sweden/gpt-sw3-6.7b/resolve/main/spiece.model""",
        """AI-Sweden/gpt-sw3-20b""": """https://huggingface.co/AI-Sweden/gpt-sw3-20b/resolve/main/spiece.model""",
    }
}

_UpperCAmelCase			:  Optional[int]     ={
    """AI-Sweden/gpt-sw3-126m""": 2048,
    """AI-Sweden/gpt-sw3-350m""": 2048,
    """AI-Sweden/gpt-sw3-1.6b""": 2048,
    """AI-Sweden/gpt-sw3-6.7b""": 2048,
    """AI-Sweden/gpt-sw3-20b""": 2048,
}







class 				snake_case__(							UpperCAmelCase__							):







						'''simple docstring'''




						SCREAMING_SNAKE_CASE__      :  Dict					=							VOCAB_FILES_NAMES
						SCREAMING_SNAKE_CASE__      :  Optional[Any]					=							PRETRAINED_VOCAB_FILES_MAP
						SCREAMING_SNAKE_CASE__      :  List[str]					=							PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
						SCREAMING_SNAKE_CASE__      :  str					=							["""input_ids""", """attention_mask"""]




						def __init__(				self   ,						__lowercase   ,						__lowercase=False   ,						__lowercase=False   ,						__lowercase=False   ,						__lowercase=None   ,						__lowercase=None   ,						__lowercase=None   ,						__lowercase=None   ,						__lowercase = None   ,						**__lowercase   ,						)					->    None:
										lowerCAmelCase_ :      Optional[Any]    				=				{} if sp_model_kwargs is None else sp_model_kwargs

										lowerCAmelCase_ :      Union[str, Any]    				=				kwargs.get('''name_or_path'''							)
										if name_or_path is None:
														logger.warning(
														    '''name_or_path not provided, will work for all GPTSw3 models except gpt-sw3-7b,'''
														    ''' you are testing the model, this can safely be ignored'''							)
														lowerCAmelCase_ :      Optional[int]    				=				'''None'''

										# Default definitions for our 2 tokenizer versions, with None-checks to enable proper testing
										lowerCAmelCase_ :      Union[str, Any]    				=				'''<|endoftext|>''' if eos_token is None else eos_token
										lowerCAmelCase_ :      str    				=				'''<unk>''' if unk_token is None else unk_token
										if "gpt-sw3-7b" in name_or_path:
														lowerCAmelCase_ :      Tuple    				=				unk_token if pad_token is None else pad_token
														lowerCAmelCase_ :      str    				=				eos_token if bos_token is None else bos_token
										else:
														lowerCAmelCase_ :      List[str]    				=				'''<pad>''' if pad_token is None else pad_token
														lowerCAmelCase_ :      List[str]    				=				'''<s>''' if bos_token is None else bos_token

										super().__init__(
										    do_lower_case=__lowercase   ,						remove_space=__lowercase   ,						keep_accents=__lowercase   ,						bos_token=__lowercase   ,						eos_token=__lowercase   ,						unk_token=__lowercase   ,						pad_token=__lowercase   ,						sp_model_kwargs=self.sp_model_kwargs   ,						**__lowercase   ,						)

										lowerCAmelCase_ :      Tuple    				=				do_lower_case
										lowerCAmelCase_ :      Optional[Any]    				=				remove_space
										lowerCAmelCase_ :      Tuple    				=				keep_accents
										lowerCAmelCase_ :      Optional[int]    				=				vocab_file

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

										# Used for whitespace normalization in input texts
										# fmt : off
										lowerCAmelCase_ :      Dict    				=				{''' ''', ''' ''', ''' ''', ''' ''', ''' ''', '''　''', ''' ''', ''' ''', ''' ''', ''' ''', '''￼''', ''''''}
										# fmt : on

										# Regular expression to remove non-printing characters (e.g. some unicode control chars) in preprocessing
										lowerCAmelCase_ :      Any    				=				re.compile(
										    f"""[{"".join(map(__lowercase   ,						list(range(0   ,						9							)							) + list(range(1_1   ,						3_2							)							) + list(range(1_2_7   ,						1_6_0							)							) + [1_6_0, 1_7_3, 8_2_0_3]							)							)}]"""							)




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




						def __setstate__(				self   ,						__lowercase							)					->    List[Any]:
										lowerCAmelCase_ :      Union[str, Any]    				=				d

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

										lowerCAmelCase_ :      List[Any]    				=				spm.SentencePieceProcessor(**self.sp_model_kwargs							)
										self.sp_model.Load(self.vocab_file							)




						@property
						# Copied from transformers.models.albert.tokenization_albert.AlbertTokenizer.vocab_size
						def 						lowercase_ (				self							)					->    int:
										return len(self.sp_model							)




						def 						lowercase_ (				self   ,						__lowercase							)					->    str:
										lowerCAmelCase_ :      List[Any]    				=				self.non_printing_characters_re.sub(''''''   ,						__lowercase							)

										# Normalize whitespaces
										lowerCAmelCase_ :      str    				=				''''''.join([char if char not in self.whitespaces else ''' ''' for char in text]							)

										# NFC Unicode normalization
										lowerCAmelCase_ :      Any    				=				unicodedata.normalize('''NFC'''   ,						__lowercase							)
										return text




						def 						lowercase_ (				self   ,						__lowercase   ,						**__lowercase							)					->    List[str]:
										lowerCAmelCase_ :      Optional[int]    				=				self.preprocess_text(__lowercase							)
										return self.sp_model.encode(__lowercase   ,						out_type=__lowercase							)




						def 						lowercase_ (				self   ,						__lowercase							)					->    int:
										return self.sp_model.PieceToId(__lowercase							)




						def 						lowercase_ (				self   ,						__lowercase							)					->    str:
										return self.sp_model.IdToPiece(__lowercase							)




						@staticmethod
						def 						lowercase_ (				__lowercase							)					->    str:
										return out_string




						def 						lowercase_ (				self   ,						__lowercase							)					->    str:
										lowerCAmelCase_ :      str    				=				[]
										lowerCAmelCase_ :      Union[str, 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:
																		# TODO: Check if this is needed, as it ensures that decode(encode(doc)) != doc by adding extra whitespace in the decoded document
																		if not prev_is_special:
																						out_string += " "

																		out_string += self.sp_model.decode(__lowercase							) + token
																		lowerCAmelCase_ :      Optional[Any]    				=				True
																		lowerCAmelCase_ :      Dict    				=				[]
														else:
																		current_sub_tokens.append(__lowercase							)
																		lowerCAmelCase_ :      str    				=				False
										out_string += self.sp_model.decode(__lowercase							)

										return out_string




						def 						lowercase_ (				self							)					->    Dict[str, int]:
										lowerCAmelCase_ :      List[Any]    				=				{self.convert_ids_to_tokens(__lowercase							): i for i in range(self.vocab_size							)}
										vocab.update(self.added_tokens_encoder							)
										return vocab




						def 						lowercase_ (				self   ,						__lowercase   ,						__lowercase = None							)					->    Tuple[str]:
										if not os.path.isdir(__lowercase							):
														logger.error(f"""Vocabulary path ({save_directory}) should be a directory"""							)
														return
										lowerCAmelCase_ :      int    				=				os.path.join(
										    __lowercase   ,						(filename_prefix + '''-''' if filename_prefix else '''''') + VOCAB_FILES_NAMES['''vocab_file''']							)

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

										return (out_vocab_file,)




						def 						lowercase_ (				self   ,						__lowercase   ,						__lowercase = False							)					->    Union[List[int], List[List[int]], "torch.Tensor"]:

										if isinstance(__lowercase   ,						__lowercase							):
														lowerCAmelCase_ :      Optional[Any]    				=				self.preprocess_text(__lowercase							)
														lowerCAmelCase_ :      Optional[Any]    				=				self.sp_model.encode(__lowercase							)
										else:
														lowerCAmelCase_ :      Any    				=				[self.preprocess_text(__lowercase							) for t in text]
														lowerCAmelCase_ :      List[str]    				=				self.sp_model.encode(__lowercase							)

										if return_tensors is True or return_tensors == "pt":
														lowerCAmelCase_ :      int    				=				torch.tensor(__lowercase							)

										return token_ids




						def 						lowercase_ (				self   ,						__lowercase							)					->    str:
										return self.sp_model.decode(__lowercase							)




						def 						lowercase_ (				self   ,						__lowercase							)					->    List[int]:
										lowerCAmelCase_ :      Optional[int]    				=				[f"""User: {text}""" if is_user else f"""Bot: {text}""" for is_user, text in conversation.iter_texts()]
										lowerCAmelCase_ :      List[str]    				=				(
										    f"""{self.eos_token}{self.bos_token}""" + f"""{self.bos_token}""".join(__lowercase							) + f"""{self.bos_token}Bot:"""
										)
										return self.encode(text=__lowercase							)



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)}""")