




'''simple docstring'''





import argparse
import os
import re


# All paths are set with the intent you should run this script from the root of the repo with the command
# python utils/check_dummies.py
_SCREAMING_SNAKE_CASE							:     Any   	=				"src/transformers"

# Matches is_xxx_available()
_SCREAMING_SNAKE_CASE							:     Any   	=				re.compile(r"is\_([a-z_]*)_available()")
# Matches from xxx import bla
_SCREAMING_SNAKE_CASE							:     Optional[int]   	=				re.compile(r"\s+from\s+\S*\s+import\s+([^\(\s].*)\n")
_SCREAMING_SNAKE_CASE							:     Any   	=				re.compile(r"^\s+if\s+not\s+\(?is\_[a-z_]*\_available\(\)")


_SCREAMING_SNAKE_CASE							:     Tuple   	=				"\n{0} = None\n"

_SCREAMING_SNAKE_CASE							:     Optional[int]   	=				"\nclass {0}(metaclass=DummyObject):\n    _backends = {1}\n\n    def __init__(self, *args, **kwargs):\n        requires_backends(self, {1})\n"


_SCREAMING_SNAKE_CASE							:     Dict   	=				"\ndef {0}(*args, **kwargs):\n    requires_backends({0}, {1})\n"


def   UpperCamelCase_(			snake_case							: Optional[Any]  ):

							'''simple docstring'''






							if _re_test_backend.search(snake_case  ) is None:
														return None
							snake_case_			      =   [b[0] for b in _re_backend.findall(snake_case  )]
							backends.sort()
							return "_and_".join(snake_case  )


def   UpperCamelCase_(			):

							'''simple docstring'''






							with open(os.path.join(snake_case							,       "__init__.py"  )							,       "r"							,       encoding="utf-8"							,       newline="\n"  ) as f:
														snake_case_			      =   f.readlines()

							# Get to the point we do the actual imports for type checking
							snake_case_			      =   0
							while not lines[line_index].startswith("if TYPE_CHECKING"  ):
														line_index += 1

							snake_case_			      =   {}
							# Go through the end of the file
							while line_index < len(snake_case  ):
														# If the line is an if is_backend_available, we grab all objects associated.
														snake_case_			      =   find_backend(lines[line_index]  )
														if backend is not None:
																					while not lines[line_index].startswith("    else:"  ):
																												line_index += 1
																					line_index += 1

																					snake_case_			      =   []
																					# Until we unindent, add backend objects to the list
																					while len(lines[line_index]  ) <= 1 or lines[line_index].startswith(" " * 8  ):
																												snake_case_			      =   lines[line_index]
																												snake_case_			      =   _re_single_line_import.search(snake_case  )
																												if single_line_import_search is not None:
																																			objects.extend(single_line_import_search.groups()[0].split(", "  )  )
																												elif line.startswith(" " * 1_2  ):
																																			objects.append(line[1_2:-2]  )
																												line_index += 1

																					snake_case_			      =   objects
														else:
																					line_index += 1

							return backend_specific_objects


def   UpperCamelCase_(			snake_case							: List[Any]							,       snake_case							: List[str]  ):

							'''simple docstring'''






							if name.isupper():
														return DUMMY_CONSTANT.format(snake_case  )
							elif name.islower():
														return DUMMY_FUNCTION.format(snake_case							,       snake_case  )
							else:
														return DUMMY_CLASS.format(snake_case							,       snake_case  )


def   UpperCamelCase_(			snake_case							: Tuple=None  ):

							'''simple docstring'''






							if backend_specific_objects is None:
														snake_case_			      =   read_init()
							# For special correspondence backend to module name as used in the function requires_modulename
							snake_case_			      =   {}

							for backend, objects in backend_specific_objects.items():
														snake_case_			      =   "[" + ", ".join(f'"{b}"' for b in backend.split("_and_"  )  ) + "]"
														snake_case_			      =   "# This file is autogenerated by the command `make fix-copies`, do not edit.\n"
														dummy_file += "from ..utils import DummyObject, requires_backends\n\n"
														dummy_file += "\n".join([create_dummy_object(snake_case							,       snake_case  ) for o in objects]  )
														snake_case_			      =   dummy_file

							return dummy_files


def   UpperCamelCase_(			snake_case							: Optional[Any]=False  ):

							'''simple docstring'''






							snake_case_			      =   create_dummy_files()
							# For special correspondence backend to shortcut as used in utils/dummy_xxx_objects.py
							snake_case_			      =   {"torch": "pt"}

							# Locate actual dummy modules and read their content.
							snake_case_			      =   os.path.join(snake_case							,       "utils"  )
							snake_case_			      =   {
							    backend: os.path.join(snake_case							,       f'dummy_{short_names.get(snake_case							,       snake_case  )}_objects.py'  )
							    for backend in dummy_files.keys()
							}

							snake_case_			      =   {}
							for backend, file_path in dummy_file_paths.items():
														if os.path.isfile(snake_case  ):
																					with open(snake_case							,       "r"							,       encoding="utf-8"							,       newline="\n"  ) as f:
																												snake_case_			      =   f.read()
														else:
																					snake_case_			      =   ""

							for backend in dummy_files.keys():
														if dummy_files[backend] != actual_dummies[backend]:
																					if overwrite:
																												print(
																												    f'Updating transformers.utils.dummy_{short_names.get(snake_case							,       snake_case  )}_objects.py as the main '
																												    "__init__ has new objects."  )
																												with open(dummy_file_paths[backend]							,       "w"							,       encoding="utf-8"							,       newline="\n"  ) as f:
																																			f.write(dummy_files[backend]  )
																					else:
																												raise ValueError(
																												    "The main __init__ has objects that are not present in "
																												    f'transformers.utils.dummy_{short_names.get(snake_case							,       snake_case  )}_objects.py. Run `make fix-copies` '
																												    "to fix this."  )


if __name__ == "__main__":
		_SCREAMING_SNAKE_CASE							:     Optional[Any]   	=				argparse.ArgumentParser()
		parser.add_argument("--fix_and_overwrite", action="store_true", help="Whether to fix inconsistencies.")
		_SCREAMING_SNAKE_CASE							:     Tuple   	=				parser.parse_args()

		check_dummies(args.fix_and_overwrite)










'''simple docstring'''





import qiskit
from qiskit.providers import Backend


def   UpperCamelCase_(			snake_case							: int							,       snake_case							: int  ):

							'''simple docstring'''






							snake_case_      ,   snake_case_			      =   bin(snake_case  )[2:], bin(snake_case  )[2:]  # Remove leading '0b'

							# Ensure that both strings are of the same length
							if len(snake_case  ) > len(snake_case  ):
														snake_case_			      =   y.zfill(len(snake_case  )  )
							else:
														snake_case_			      =   x.zfill(len(snake_case  )  )

							# 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
							snake_case_			      =   qiskit.QuantumCircuit((len(snake_case  ) * 3) + 1							,       len(snake_case  ) + 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(snake_case  )  ):
														if x[::-1][i] == "1":
																					circuit.x(snake_case  )
							for j in range(len(snake_case  )  ):
														if y[::-1][j] == "1":
																					circuit.x(len(snake_case  ) + j  )

							return circuit, x, y


def   UpperCamelCase_(			snake_case							: qiskit.QuantumCircuit							,       snake_case							: int							,       snake_case							: int							,       snake_case							: int							,       snake_case							: int							,       ):

							'''simple docstring'''






							circuit.ccx(snake_case							,       snake_case							,       snake_case  )
							circuit.cx(snake_case							,       snake_case  )
							circuit.ccx(snake_case							,       snake_case							,       snake_case  )
							circuit.cx(snake_case							,       snake_case  )
							circuit.cx(snake_case							,       snake_case  )


def   UpperCamelCase_(			snake_case							: int							,       snake_case							: int							,       snake_case							: Backend = qiskit.Aer.get_backend("aer_simulator"  )							,       ):

							'''simple docstring'''






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

							# Store the Integers
							snake_case_      ,   snake_case_      ,   snake_case_			      =   store_two_classics(snake_case							,       snake_case  )
							for i in range(len(snake_case  )  ):
														full_adder(snake_case							,       snake_case							,       len(snake_case  ) + i							,       len(snake_case  ) + len(snake_case  ) + i							,       len(snake_case  ) + len(snake_case  ) + i + 1  )
														circuit.barrier()  # Optional, just for aesthetics

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

							snake_case_			      =   qiskit.execute(snake_case							,       snake_case							,       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()




