
import warnings

from transformers import AutoTokenizer
from transformers.utils import is_torch_available
from transformers.utils.generic import ExplicitEnum

from ...processing_utils import ProcessorMixin


if is_torch_available():
   import torch





class     __UpperCamelCase (							lowerCAmelCase__       ):






     """simple docstring"""







     lowerCAmelCase_							   =			'''char'''
     lowerCAmelCase_							   =			'''bpe'''
     lowerCAmelCase_							   =			'''wp'''






lowercase_ 				=			(DecodeType.CHARACTER, DecodeType.BPE, DecodeType.WORDPIECE)





class     __UpperCamelCase (							lowerCAmelCase__       ):






     """simple docstring"""







     lowerCAmelCase_							   =			['''image_processor''', '''char_tokenizer''']
     lowerCAmelCase_							   =			'''ViTImageProcessor'''
     lowerCAmelCase_							   =			'''MgpstrTokenizer'''



     def __init__(				self							:							int     ,						_A							:							str=None     ,						_A							:							List[str]=None     ,						**_A							:							Optional[Any] ):







       """simple docstring"""




       __SCREAMING_SNAKE_CASE      :	Optional[int]					=		None
       if "feature_extractor" in kwargs:
         warnings.warn(
             '''The `feature_extractor` argument is deprecated and will be removed in v5, use `image_processor`'''
             ''' instead.'''     ,						_A     ,						)
         __SCREAMING_SNAKE_CASE      :	List[Any]					=		kwargs.pop('''feature_extractor''' )

       __SCREAMING_SNAKE_CASE      :	Dict					=		image_processor if image_processor is not None else feature_extractor
       if image_processor is None:
         raise ValueError('''You need to specify an `image_processor`.''' )
       if tokenizer is None:
         raise ValueError('''You need to specify a `tokenizer`.''' )

       __SCREAMING_SNAKE_CASE      :	Union[str, Any]					=		tokenizer
       __SCREAMING_SNAKE_CASE      :	Any					=		AutoTokenizer.from_pretrained('''gpt2''' )
       __SCREAMING_SNAKE_CASE      :	Any					=		AutoTokenizer.from_pretrained('''bert-base-uncased''' )

       super().__init__(_A     ,						_A )



     def __call__(				self							:							int     ,						_A							:							str=None     ,						_A							:							List[Any]=None     ,						_A							:							List[Any]=None     ,						**_A							:							str ):







       """simple docstring"""




       if images is None and text is None:
         raise ValueError('''You need to specify either an `images` or `text` input to process.''' )

       if images is not None:
         __SCREAMING_SNAKE_CASE      :	Optional[int]					=		self.image_processor(_A     ,						return_tensors=_A     ,						**_A )
       if text is not None:
         __SCREAMING_SNAKE_CASE      :	Any					=		self.char_tokenizer(_A     ,						return_tensors=_A     ,						**_A )

       if text is None:
         return inputs
       elif images is None:
         return encodings
       else:
         __SCREAMING_SNAKE_CASE      :	str					=		encodings['''input_ids''']
         return inputs



     def  UpperCAmelCase__							(				self							:							List[Any]     ,						_A							:							int ):







       """simple docstring"""




       __SCREAMING_SNAKE_CASE,		__SCREAMING_SNAKE_CASE,		__SCREAMING_SNAKE_CASE      :	Optional[int]					=		sequences
       __SCREAMING_SNAKE_CASE      :	Tuple					=		char_preds.size(0 )

       __SCREAMING_SNAKE_CASE,		__SCREAMING_SNAKE_CASE      :	Union[str, Any]					=		self._decode_helper(_A     ,						'''char''' )
       __SCREAMING_SNAKE_CASE,		__SCREAMING_SNAKE_CASE      :	Any					=		self._decode_helper(_A     ,						'''bpe''' )
       __SCREAMING_SNAKE_CASE,		__SCREAMING_SNAKE_CASE      :	Any					=		self._decode_helper(_A     ,						'''wp''' )

       __SCREAMING_SNAKE_CASE      :	Tuple					=		[]
       __SCREAMING_SNAKE_CASE      :	Optional[int]					=		[]
       for i in range(_A ):
         __SCREAMING_SNAKE_CASE      :	Any					=		[char_scores[i], bpe_scores[i], wp_scores[i]]
         __SCREAMING_SNAKE_CASE      :	str					=		[char_strs[i], bpe_strs[i], wp_strs[i]]
         __SCREAMING_SNAKE_CASE      :	Any					=		scores.index(max(_A ) )
         final_strs.append(strs[max_score_index] )
         final_scores.append(scores[max_score_index] )

       __SCREAMING_SNAKE_CASE      :	str					=		{}
       __SCREAMING_SNAKE_CASE      :	Optional[Any]					=		final_strs
       __SCREAMING_SNAKE_CASE      :	Union[str, Any]					=		final_scores
       __SCREAMING_SNAKE_CASE      :	int					=		char_strs
       __SCREAMING_SNAKE_CASE      :	List[Any]					=		bpe_strs
       __SCREAMING_SNAKE_CASE      :	List[str]					=		wp_strs
       return out



     def  UpperCAmelCase__							(				self							:							Any     ,						_A							:							Optional[int]     ,						_A							:							List[Any] ):







       """simple docstring"""




       if format == DecodeType.CHARACTER:
         __SCREAMING_SNAKE_CASE      :	Any					=		self.char_decode
         __SCREAMING_SNAKE_CASE      :	Any					=		1
         __SCREAMING_SNAKE_CASE      :	Dict					=		'''[s]'''
       elif format == DecodeType.BPE:
         __SCREAMING_SNAKE_CASE      :	Dict					=		self.bpe_decode
         __SCREAMING_SNAKE_CASE      :	Dict					=		2
         __SCREAMING_SNAKE_CASE      :	Optional[int]					=		'''#'''
       elif format == DecodeType.WORDPIECE:
         __SCREAMING_SNAKE_CASE      :	str					=		self.wp_decode
         __SCREAMING_SNAKE_CASE      :	Any					=		102
         __SCREAMING_SNAKE_CASE      :	Optional[int]					=		'''[SEP]'''
       else:
         raise ValueError(F'''Format {format} is not supported.''' )

       __SCREAMING_SNAKE_CASE,		__SCREAMING_SNAKE_CASE      :	List[str]					=		[], []
       __SCREAMING_SNAKE_CASE      :	Union[str, Any]					=		pred_logits.size(0 )
       __SCREAMING_SNAKE_CASE      :	Tuple					=		pred_logits.size(1 )
       __SCREAMING_SNAKE_CASE,		__SCREAMING_SNAKE_CASE      :	Union[str, Any]					=		pred_logits.topk(1     ,						dim=-1     ,						largest=_A     ,						sorted=_A )
       __SCREAMING_SNAKE_CASE      :	Union[str, Any]					=		preds_index.view(-1     ,						_A )[:, 1:]
       __SCREAMING_SNAKE_CASE      :	Dict					=		decoder(_A )
       __SCREAMING_SNAKE_CASE,		__SCREAMING_SNAKE_CASE      :	Tuple					=		torch.nn.functional.softmax(_A     ,						dim=2 ).max(dim=2 )
       __SCREAMING_SNAKE_CASE      :	List[str]					=		preds_max_prob[:, 1:]

       for index in range(_A ):
         __SCREAMING_SNAKE_CASE      :	Any					=		preds_str[index].find(_A )
         __SCREAMING_SNAKE_CASE      :	int					=		preds_str[index][:pred_eos]
         __SCREAMING_SNAKE_CASE      :	Optional[int]					=		preds_index[index].cpu().tolist()
         __SCREAMING_SNAKE_CASE      :	Union[str, Any]					=		pred_index.index(_A ) if eos_token in pred_index else -1
         __SCREAMING_SNAKE_CASE      :	Optional[int]					=		preds_max_prob[index][: pred_eos_index + 1]
         __SCREAMING_SNAKE_CASE      :	Tuple					=		pred_max_prob.cumprod(dim=0 )[-1] if pred_max_prob.nelement() != 0 else 0.0
         dec_strs.append(_A )
         conf_scores.append(_A )

       return dec_strs, conf_scores



     def  UpperCAmelCase__							(				self							:							List[str]     ,						_A							:							Tuple ):







       """simple docstring"""




       __SCREAMING_SNAKE_CASE      :	Any					=		[seq.replace(''' '''     ,						'''''' ) for seq in self.char_tokenizer.batch_decode(_A )]
       return decode_strs



     def  UpperCAmelCase__							(				self							:							Any     ,						_A							:							Optional[Any] ):







       """simple docstring"""




       return self.bpe_tokenizer.batch_decode(_A )




     def  UpperCAmelCase__							(				self							:							Optional[int]     ,						_A							:							Optional[int] ):







       """simple docstring"""




       __SCREAMING_SNAKE_CASE      :	Tuple					=		[seq.replace(''' '''     ,						'''''' ) for seq in self.wp_tokenizer.batch_decode(_A )]
       return decode_strs






'''simple docstring'''


import qiskit
def 						snake_case_       (UpperCamelCase			:    int					,		UpperCamelCase			:    int ):





							'''simple docstring'''


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

							_a      	=							qiskit.QuantumCircuit(4					,		2 )
							# encode inputs in qubits 0 and 1
							if bita == 1:
														qc_ha.x(0 )
							if bita == 1:
														qc_ha.x(1 )
							qc_ha.barrier()

							# use cnots to write XOR of the inputs on qubit2
							qc_ha.cx(0					,		2 )
							qc_ha.cx(1					,		2 )

							# use ccx / toffoli gate to write AND of the inputs on qubit3
							qc_ha.ccx(0					,		1					,		3 )
							qc_ha.barrier()

							# extract outputs
							qc_ha.measure(2					,		0 )  # extract XOR value
							qc_ha.measure(3					,		1 )  # extract AND value

							# Execute the circuit on the qasm simulator
							_a      	=							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__":
				_snake_case : Tuple  				=						half_adder(1, 1)
				print(F'''Half Adder Output Qubit Counts: {counts}''')

