



'''simple docstring'''






from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_tf_available,
    is_tokenizers_available,
    is_torch_available,
)


A_				:					Union[str, Any]							=      {
    """configuration_dpr""": ["""DPR_PRETRAINED_CONFIG_ARCHIVE_MAP""", """DPRConfig"""],
    """tokenization_dpr""": [
        """DPRContextEncoderTokenizer""",
        """DPRQuestionEncoderTokenizer""",
        """DPRReaderOutput""",
        """DPRReaderTokenizer""",
    ],
}


try:
   if not is_tokenizers_available():
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   pass
else:
   A_				:					List[Any]							=      [
       """DPRContextEncoderTokenizerFast""",
       """DPRQuestionEncoderTokenizerFast""",
       """DPRReaderTokenizerFast""",
   ]

try:
   if not is_torch_available():
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   pass
else:
   A_				:					List[Any]							=      [
       """DPR_CONTEXT_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST""",
       """DPR_QUESTION_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST""",
       """DPR_READER_PRETRAINED_MODEL_ARCHIVE_LIST""",
       """DPRContextEncoder""",
       """DPRPretrainedContextEncoder""",
       """DPRPreTrainedModel""",
       """DPRPretrainedQuestionEncoder""",
       """DPRPretrainedReader""",
       """DPRQuestionEncoder""",
       """DPRReader""",
   ]

try:
   if not is_tf_available():
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   pass
else:
   A_				:					Union[str, Any]							=      [
       """TF_DPR_CONTEXT_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST""",
       """TF_DPR_QUESTION_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST""",
       """TF_DPR_READER_PRETRAINED_MODEL_ARCHIVE_LIST""",
       """TFDPRContextEncoder""",
       """TFDPRPretrainedContextEncoder""",
       """TFDPRPretrainedQuestionEncoder""",
       """TFDPRPretrainedReader""",
       """TFDPRQuestionEncoder""",
       """TFDPRReader""",
   ]


if TYPE_CHECKING:
   from .configuration_dpr import DPR_PRETRAINED_CONFIG_ARCHIVE_MAP, DPRConfig
   from .tokenization_dpr import (
       DPRContextEncoderTokenizer,
       DPRQuestionEncoderTokenizer,
       DPRReaderOutput,
       DPRReaderTokenizer,
   )

   try:
      if not is_tokenizers_available():
         raise OptionalDependencyNotAvailable()
   except OptionalDependencyNotAvailable:
      pass
   else:
      from .tokenization_dpr_fast import (
          DPRContextEncoderTokenizerFast,
          DPRQuestionEncoderTokenizerFast,
          DPRReaderTokenizerFast,
      )

   try:
      if not is_torch_available():
         raise OptionalDependencyNotAvailable()
   except OptionalDependencyNotAvailable:
      pass
   else:
      from .modeling_dpr import (
          DPR_CONTEXT_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST,
          DPR_QUESTION_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST,
          DPR_READER_PRETRAINED_MODEL_ARCHIVE_LIST,
          DPRContextEncoder,
          DPRPretrainedContextEncoder,
          DPRPreTrainedModel,
          DPRPretrainedQuestionEncoder,
          DPRPretrainedReader,
          DPRQuestionEncoder,
          DPRReader,
      )

   try:
      if not is_tf_available():
         raise OptionalDependencyNotAvailable()
   except OptionalDependencyNotAvailable:
      pass
   else:
      from .modeling_tf_dpr import (
          TF_DPR_CONTEXT_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST,
          TF_DPR_QUESTION_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST,
          TF_DPR_READER_PRETRAINED_MODEL_ARCHIVE_LIST,
          TFDPRContextEncoder,
          TFDPRPretrainedContextEncoder,
          TFDPRPretrainedQuestionEncoder,
          TFDPRPretrainedReader,
          TFDPRQuestionEncoder,
          TFDPRReader,
      )

else:
   import sys

   A_				:					str							=      _LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)








'''simple docstring'''






import qiskit
from qiskit.providers import Backend




def        snake_case_   (	lowerCAmelCase_			,  lowerCAmelCase_						)->						tuple[qiskit.QuantumCircuit, str, str]:





       '''simple docstring'''


       _UpperCAmelCase	,_UpperCAmelCase    :		Optional[Any]     	=					bin(lowerCAmelCase_						)[2:], bin(lowerCAmelCase_						)[2:]  # Remove leading '0b'

       # Ensure that both strings are of the same length
       if len(lowerCAmelCase_						) > len(lowerCAmelCase_						):
              _UpperCAmelCase    :		str     	=					y.zfill(len(lowerCAmelCase_						)						)
       else:
              _UpperCAmelCase    :		int     	=					x.zfill(len(lowerCAmelCase_						)						)

       # We need (3 * number of bits in the larger number)+1 qBits
       # The second parameter is the number of classical registers, to measure the result
       _UpperCAmelCase    :		Any     	=					qiskit.QuantumCircuit((len(lowerCAmelCase_						) * 3) + 1			,  len(lowerCAmelCase_						) + 1						)

       # We are essentially "not-ing" the bits that are 1
       # Reversed because it's easier to perform ops on more significant bits
       for i in range(len(lowerCAmelCase_						)						):
              if x[::-1][i] == "1":
                     circuit.x(lowerCAmelCase_						)
       for j in range(len(lowerCAmelCase_						)						):
              if y[::-1][j] == "1":
                     circuit.x(len(lowerCAmelCase_						) + j						)

       return circuit, x, y




def        snake_case_   (	lowerCAmelCase_			,  lowerCAmelCase_			,  lowerCAmelCase_			,  lowerCAmelCase_			,  lowerCAmelCase_			,  )->						Dict:





       '''simple docstring'''


       circuit.ccx(lowerCAmelCase_			,  lowerCAmelCase_			,  lowerCAmelCase_						)
       circuit.cx(lowerCAmelCase_			,  lowerCAmelCase_						)
       circuit.ccx(lowerCAmelCase_			,  lowerCAmelCase_			,  lowerCAmelCase_						)
       circuit.cx(lowerCAmelCase_			,  lowerCAmelCase_						)
       circuit.cx(lowerCAmelCase_			,  lowerCAmelCase_						)




def        snake_case_   (	lowerCAmelCase_			,  lowerCAmelCase_			,  lowerCAmelCase_ = qiskit.Aer.get_backend("""aer_simulator"""						)			,  )->						int:





       '''simple docstring'''


       if vala < 0 or vala < 0:
              raise ValueError("""Both Integers must be positive!"""						)

       # Store the Integers
       _UpperCAmelCase	,_UpperCAmelCase	,_UpperCAmelCase    :		Union[str, Any]     	=					store_two_classics(lowerCAmelCase_			,  lowerCAmelCase_						)
       for i in range(len(lowerCAmelCase_						)						):
              full_adder(lowerCAmelCase_			,  lowerCAmelCase_			,  len(lowerCAmelCase_						) + i			,  len(lowerCAmelCase_						) + len(lowerCAmelCase_						) + i			,  len(lowerCAmelCase_						) + len(lowerCAmelCase_						) + i + 1						)
              circuit.barrier()  # Optional, just for aesthetics

       # Measure the resultant qBits
       for i in range(len(lowerCAmelCase_						) + 1						):
              circuit.measure([(len(lowerCAmelCase_						) * 2) + i]			,  [i]						)

       _UpperCAmelCase    :		Optional[int]     	=					qiskit.execute(lowerCAmelCase_			,  lowerCAmelCase_			,  shots=1						).result()

       # The result is in binary. Convert it back to int
       return int(list(res.get_counts()						)[0]			,  2						)


if __name__ == "__main__":
   import doctest

   doctest.testmod()



