




'''simple docstring'''





# Lint as: python3
import sys
from collections.abc import Mapping
from typing import TYPE_CHECKING

import numpy as np
import pyarrow as pa

from .. import config
from ..utils.py_utils import map_nested
from .formatting import TensorFormatter


if TYPE_CHECKING:
  import tensorflow as tf




class 				_snake_case	(			TensorFormatter[Mapping, "tf.Tensor", Mapping]							):




   def __init__(      self       ,							a__=None       ,							**a__							)       ->       List[Any]:

          '''simple docstring'''




          super().__init__(features=a__							)
          snake_case_			      =   tf_tensor_kwargs
          import tensorflow as tf  # noqa: import tf at initialization




   def      lowerCAmelCase__       (      self       ,							a__							)       ->       Any:

          '''simple docstring'''




          import tensorflow as tf

          if isinstance(a__       ,							a__							) and column:
                 if all(
                     isinstance(a__       ,							tf.Tensor							) and x.shape == column[0].shape and x.dtype == column[0].dtype for x in column							):
                        return tf.stack(a__							)
                 elif all(
                     isinstance(a__       ,							(tf.Tensor, tf.RaggedTensor)							) and x.ndim == 1 and x.dtype == column[0].dtype
                     for x in column							):
                        # only rag 1-D tensors, otherwise some dimensions become ragged even though they were consolidated
                        return tf.ragged.stack(a__							)

          return column




   def      lowerCAmelCase__       (      self       ,							a__							)       ->       List[str]:

          '''simple docstring'''




          import tensorflow as tf

          if value is None:
                 return value

          snake_case_			      =   {}

          if isinstance(a__       ,							(np.number, np.ndarray)							) and np.issubdtype(value.dtype       ,							np.integer							):
                 snake_case_			      =   {'dtype': tf.intaa}
          elif isinstance(a__       ,							(np.number, np.ndarray)							) and np.issubdtype(value.dtype       ,							np.floating							):
                 snake_case_			      =   {'dtype': tf.floataa}
          elif config.PIL_AVAILABLE and "PIL" in sys.modules:
                 import PIL.Image

                 if isinstance(a__       ,							PIL.Image.Image							):
                        snake_case_			      =   np.asarray(a__							)

          return tf.convert_to_tensor(a__       ,							**{**default_dtype, **self.tf_tensor_kwargs}							)




   def      lowerCAmelCase__       (      self       ,							a__							)       ->       str:

          '''simple docstring'''




          import tensorflow as tf

          # support for torch, tf, jax etc.
          if config.TORCH_AVAILABLE and "torch" in sys.modules:
                 import torch

                 if isinstance(a__       ,							torch.Tensor							):
                        return self._tensorize(data_struct.detach().cpu().numpy()[()]							)
          if hasattr(a__       ,							"__array__"							) and not isinstance(a__       ,							tf.Tensor							):
                 snake_case_			      =   data_struct.__array__()
          # support for nested types like struct of list of struct
          if isinstance(a__       ,							np.ndarray							):
                 if data_struct.dtype == object:  # tf tensors cannot be instantied from an array of objects
                        return self._consolidate([self.recursive_tensorize(a__							) for substruct in data_struct]							)
          elif isinstance(a__       ,							(list, tuple)							):
                 return self._consolidate([self.recursive_tensorize(a__							) for substruct in data_struct]							)
          return self._tensorize(a__							)




   def      lowerCAmelCase__       (      self       ,							a__							)       ->       Optional[Any]:

          '''simple docstring'''




          return map_nested(self._recursive_tensorize       ,							a__       ,							map_list=a__							)




   def      lowerCAmelCase__       (      self       ,							a__							)       ->       Mapping:

          '''simple docstring'''




          snake_case_			      =   self.numpy_arrow_extractor().extract_row(a__							)
          snake_case_			      =   self.python_features_decoder.decode_row(a__							)
          return self.recursive_tensorize(a__							)




   def      lowerCAmelCase__       (      self       ,							a__							)       ->       "tf.Tensor":

          '''simple docstring'''




          snake_case_			      =   self.numpy_arrow_extractor().extract_column(a__							)
          snake_case_			      =   self.python_features_decoder.decode_column(a__       ,							pa_table.column_names[0]							)
          snake_case_			      =   self.recursive_tensorize(a__							)
          snake_case_			      =   self._consolidate(a__							)
          return column




   def      lowerCAmelCase__       (      self       ,							a__							)       ->       Mapping:

          '''simple docstring'''




          snake_case_			      =   self.numpy_arrow_extractor().extract_batch(a__							)
          snake_case_			      =   self.python_features_decoder.decode_batch(a__							)
          snake_case_			      =   self.recursive_tensorize(a__							)
          for column_name in batch:
                 snake_case_			      =   self._consolidate(batch[column_name]							)
          return batch










'''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()




