

import json
import os
from pathlib import Path
from shutil import copyfile
from typing import Any, Dict, List, Optional, Tuple, Union

import sentencepiece

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


__snake_case      :      List[str]             =       logging.get_logger(__name__)

__snake_case      :      List[str]             =       """▁"""

__snake_case      :      List[str]             =       {
    """vocab_file""": """vocab.json""",
    """spm_file""": """sentencepiece.bpe.model""",
}

__snake_case      :      List[str]             =       {
    """vocab_file""": {
        """facebook/s2t-small-librispeech-asr""": (
            """https://huggingface.co/facebook/s2t-small-librispeech-asr/resolve/main/vocab.json"""
        ),
    },
    """spm_file""": {
        """facebook/s2t-small-librispeech-asr""": (
            """https://huggingface.co/facebook/s2t-small-librispeech-asr/resolve/main/sentencepiece.bpe.model"""
        )
    },
}

__snake_case      :      int             =       {
    """facebook/s2t-small-librispeech-asr""": 10_24,
}

__snake_case      :      List[Any]             =       ["""pt""", """fr""", """ru""", """nl""", """ro""", """it""", """es""", """de"""]

__snake_case      :      int             =       {"""mustc""": MUSTC_LANGS}


class       __SCREAMING_SNAKE_CASE   (				__lowercase):
						_SCREAMING_SNAKE_CASE		:    str						=   VOCAB_FILES_NAMES
						_SCREAMING_SNAKE_CASE		:    Union[str, Any]						=   PRETRAINED_VOCAB_FILES_MAP
						_SCREAMING_SNAKE_CASE		:    Union[str, Any]						=   MAX_MODEL_INPUT_SIZES
						_SCREAMING_SNAKE_CASE		:    Dict						=   ["input_ids", "attention_mask"]

						_SCREAMING_SNAKE_CASE		:    List[int]						=   []






						def __init__(		self       ,  _UpperCamelCase       ,  _UpperCamelCase       ,  _UpperCamelCase="<s>"       ,  _UpperCamelCase="</s>"       ,  _UpperCamelCase="<pad>"       ,  _UpperCamelCase="<unk>"       ,  _UpperCamelCase=False       ,  _UpperCamelCase=False       ,  _UpperCamelCase=None       ,  _UpperCamelCase=None       ,  _UpperCamelCase = None       ,  **_UpperCamelCase       ,  ):






												"""simple docstring"""
												lowerCAmelCase__        =  {} if sp_model_kwargs is None else sp_model_kwargs

												super().__init__(
												    bos_token=snake_case_       ,  eos_token=snake_case_       ,  unk_token=snake_case_       ,  pad_token=snake_case_       ,  do_upper_case=snake_case_       ,  do_lower_case=snake_case_       ,  tgt_lang=snake_case_       ,  lang_codes=snake_case_       ,  sp_model_kwargs=self.sp_model_kwargs       ,  **snake_case_       ,  )
												lowerCAmelCase__        =  do_upper_case
												lowerCAmelCase__        =  do_lower_case

												lowerCAmelCase__        =  load_json(snake_case_				)
												lowerCAmelCase__        =  {v: k for k, v in self.encoder.items()}
												lowerCAmelCase__        =  spm_file
												lowerCAmelCase__        =  load_spm(snake_case_       ,  self.sp_model_kwargs				)

												if lang_codes is not None:
																		lowerCAmelCase__        =  lang_codes
																		lowerCAmelCase__        =  LANGUAGES[lang_codes]
																		lowerCAmelCase__        =  [F"<lang:{lang}>" for lang in self.langs]
																		lowerCAmelCase__        =  {lang: self.sp_model.PieceToId(F"<lang:{lang}>"				) for lang in self.langs}

																		lowerCAmelCase__        =  self.lang_tokens
																		lowerCAmelCase__        =  tgt_lang if tgt_lang is not None else self.langs[0]

																		self.set_tgt_lang_special_tokens(self._tgt_lang				)
												else:
																		lowerCAmelCase__        =  {}






						@property
						def  UpperCamelCase__ (		self				):






												"""simple docstring"""
												return len(self.encoder				)






						@property
						def  UpperCamelCase__ (		self				):






												"""simple docstring"""
												return self._tgt_lang






						@tgt_lang.setter
						def  UpperCamelCase__ (		self       ,  _UpperCamelCase				):






												"""simple docstring"""
												lowerCAmelCase__        =  new_tgt_lang
												self.set_tgt_lang_special_tokens(snake_case_				)






						def  UpperCamelCase__ (		self       ,  _UpperCamelCase				):






												"""simple docstring"""
												lowerCAmelCase__        =  self.lang_code_to_id[tgt_lang]
												lowerCAmelCase__        =  [lang_code_id]






						def  UpperCamelCase__ (		self       ,  _UpperCamelCase				):






												"""simple docstring"""
												return self.sp_model.encode(snake_case_       ,  out_type=snake_case_				)






						def  UpperCamelCase__ (		self       ,  _UpperCamelCase				):






												"""simple docstring"""
												return self.encoder.get(snake_case_       ,  self.encoder[self.unk_token]				)






						def  UpperCamelCase__ (		self       ,  _UpperCamelCase				):






												"""simple docstring"""
												return self.decoder.get(snake_case_       ,  self.unk_token				)






						def  UpperCamelCase__ (		self       ,  _UpperCamelCase				):






												"""simple docstring"""
												lowerCAmelCase__        =  []
												lowerCAmelCase__        =  ''''''
												for token in tokens:
																		# make sure that special tokens are not decoded using sentencepiece model
																		if token in self.all_special_tokens:
																								lowerCAmelCase__        =  self.sp_model.decode(snake_case_				)
																								out_string += (decoded.upper() if self.do_upper_case else decoded) + token + " "
																								lowerCAmelCase__        =  []
																		else:
																								current_sub_tokens.append(snake_case_				)
												lowerCAmelCase__        =  self.sp_model.decode(snake_case_				)
												out_string += decoded.upper() if self.do_upper_case else decoded
												return out_string.strip()






						def  UpperCamelCase__ (		self       ,  _UpperCamelCase       ,  _UpperCamelCase=None				):






												"""simple docstring"""
												if token_ids_a is None:
																		return self.prefix_tokens + token_ids_a + [self.eos_token_id]
												# We don't expect to process pairs, but leave the pair logic for API consistency
												return self.prefix_tokens + token_ids_a + token_ids_a + [self.eos_token_id]






						def  UpperCamelCase__ (		self       ,  _UpperCamelCase       ,  _UpperCamelCase = None       ,  _UpperCamelCase = False				):






												"""simple docstring"""

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

												lowerCAmelCase__        =  [1] * len(self.prefix_tokens				)
												lowerCAmelCase__        =  [1]
												if token_ids_a is None:
																		return prefix_ones + ([0] * len(snake_case_				)) + suffix_ones
												return prefix_ones + ([0] * len(snake_case_				)) + ([0] * len(snake_case_				)) + suffix_ones






						def  UpperCamelCase__ (		self				):






												"""simple docstring"""
												lowerCAmelCase__        =  self.encoder.copy()
												vocab.update(self.added_tokens_encoder				)
												return vocab






						def __getstate__(		self				):






												"""simple docstring"""
												lowerCAmelCase__        =  self.__dict__.copy()
												lowerCAmelCase__        =  None
												return state






						def __setstate__(		self       ,  _UpperCamelCase				):






												"""simple docstring"""
												lowerCAmelCase__        =  d

												# for backward compatibility
												if not hasattr(self       ,  'sp_model_kwargs'				):
																		lowerCAmelCase__        =  {}

												lowerCAmelCase__        =  load_spm(self.spm_file       ,  self.sp_model_kwargs				)







						def  UpperCamelCase__ (		self       ,  _UpperCamelCase       ,  _UpperCamelCase = None				):






												"""simple docstring"""
												lowerCAmelCase__        =  Path(snake_case_				)
												assert save_dir.is_dir(), F"{save_directory} should be a directory"
												lowerCAmelCase__        =  save_dir / (
												    (filename_prefix + '''-''' if filename_prefix else '''''') + self.vocab_files_names['''vocab_file''']
												)
												lowerCAmelCase__        =  save_dir / (
												    (filename_prefix + '''-''' if filename_prefix else '''''') + self.vocab_files_names['''spm_file''']
												)

												save_json(self.encoder       ,  snake_case_				)

												if os.path.abspath(self.spm_file				) != os.path.abspath(snake_case_				) and os.path.isfile(self.spm_file				):
																		copyfile(self.spm_file       ,  snake_case_				)
												elif not os.path.isfile(self.spm_file				):
																		with open(snake_case_       ,  'wb'				) as fi:
																								lowerCAmelCase__        =  self.sp_model.serialized_model_proto()
																								fi.write(snake_case_				)

												return (str(snake_case_				), str(snake_case_				))







def 		_UpperCamelCase				(      UpperCamelCase_    :   str      ,    UpperCamelCase_    :   Dict[str, Any]						)					->				List[str]:

						"""simple docstring"""



						lowerCAmelCase__        =  sentencepiece.SentencePieceProcessor(**lowerCAmelCase__						)
						spm.Load(str(lowerCAmelCase__						)						)
						return spm







def 		_UpperCamelCase				(      UpperCamelCase_    :   str						)					->				int:

						"""simple docstring"""



						with open(lowerCAmelCase__      ,    'r'						) as f:
												return json.load(lowerCAmelCase__						)







def 		_UpperCamelCase				(      UpperCamelCase_    :   Dict      ,    UpperCamelCase_    :   str						)					->				Any:

						"""simple docstring"""



						with open(lowerCAmelCase__      ,    'w'						) as f:
												json.dump(lowerCAmelCase__      ,    lowerCAmelCase__      ,    indent=2						)













import qiskit







def 		_UpperCamelCase				(      UpperCamelCase_    :   int      ,    UpperCamelCase_    :   int						)					->				qiskit.result.counts.Counts:

						"""simple docstring"""



						lowerCAmelCase__        =  qiskit.Aer.get_backend('aer_simulator'						)

						# Create a Quantum Circuit acting on the q register
						lowerCAmelCase__        =  qiskit.QuantumCircuit(UpperCamelCase_      ,    UpperCamelCase_						)

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

						# Execute the circuit on the simulator
						lowerCAmelCase__        =  qiskit.execute(UpperCamelCase_      ,    UpperCamelCase_      ,    shots=1000						)

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


if __name__ == "__main__":
					print(f'Total count for various states are: {single_qubit_measure(1, 1)}')





