


import collections
import gzip
import os
import urllib

import numpy
from tensorflow.python.framework import dtypes, random_seed
from tensorflow.python.platform import gfile
from tensorflow.python.util.deprecation import deprecated

a       	=  collections.namedtuple('_Datasets', ['train', 'validation', 'test'])

# CVDF mirror of http://yann.lecun.com/exdb/mnist/
a       	=  'https://storage.googleapis.com/cvdf-datasets/mnist/'


def       UpperCAmelCase_					(   UpperCAmelCase__	):
					lowercase_					=      numpy.dtype(numpy.uintaa	).newbyteorder(""">"""	)
					return numpy.frombuffer(bytestream.read(4	)    ,				dtype=lowercase_	)[0]


@deprecated(lowercase_    ,				"""Please use tf.data to implement this functionality."""	)
def       UpperCAmelCase_					(   UpperCAmelCase__	):
					print("""Extracting"""    ,				f.name	)
					with gzip.GzipFile(fileobj=lowercase_	) as bytestream:
										lowercase_					=      _readaa(lowercase_	)
										if magic != 2_0_5_1:
															raise ValueError(
															    """Invalid magic number %d in MNIST image file: %s""" % (magic, f.name)	)
										lowercase_					=      _readaa(lowercase_	)
										lowercase_					=      _readaa(lowercase_	)
										lowercase_					=      _readaa(lowercase_	)
										lowercase_					=      bytestream.read(rows * cols * num_images	)
										lowercase_					=      numpy.frombuffer(lowercase_    ,				dtype=numpy.uinta	)
										lowercase_					=      data.reshape(lowercase_    ,				lowercase_    ,				lowercase_    ,				1	)
										return data


@deprecated(lowercase_    ,				"""Please use tf.one_hot on tensors."""	)
def       UpperCAmelCase_					(   UpperCAmelCase__    ,				UpperCAmelCase__	):
					lowercase_					=      labels_dense.shape[0]
					lowercase_					=      numpy.arange(lowercase_	) * num_classes
					lowercase_					=      numpy.zeros((num_labels, num_classes)	)
					lowercase_					=      1
					return labels_one_hot


@deprecated(lowercase_    ,				"""Please use tf.data to implement this functionality."""	)
def       UpperCAmelCase_					(   UpperCAmelCase__    ,				UpperCAmelCase__=False    ,				UpperCAmelCase__=1_0	):
					print("""Extracting"""    ,				f.name	)
					with gzip.GzipFile(fileobj=lowercase_	) as bytestream:
										lowercase_					=      _readaa(lowercase_	)
										if magic != 2_0_4_9:
															raise ValueError(
															    """Invalid magic number %d in MNIST label file: %s""" % (magic, f.name)	)
										lowercase_					=      _readaa(lowercase_	)
										lowercase_					=      bytestream.read(lowercase_	)
										lowercase_					=      numpy.frombuffer(lowercase_    ,				dtype=numpy.uinta	)
										if one_hot:
															return _dense_to_one_hot(lowercase_    ,				lowercase_	)
										return labels







class 							UpperCamelCase__ :

					@deprecated(
					    UpperCamelCase__				,       """Please use alternatives such as official/mnist/_DataSet.py"""
					    """ from tensorflow/models."""				,       )
					def __init__(  self							: List[str]				,       UpperCamelCase__							: Optional[Any]				,       UpperCamelCase__							: Tuple				,       UpperCamelCase__							: Dict=False				,       UpperCamelCase__							: Optional[Any]=False				,       UpperCamelCase__							: List[Any]=dtypes.floataa				,       UpperCamelCase__							: Optional[Any]=True				,       UpperCamelCase__							: Tuple=None				,       ):






										'''simple docstring'''






										lowercase_				,       lowercase_					=      random_seed.get_seed(UpperCamelCase__							)
										# If op level seed is not set, use whatever graph level seed is returned
										numpy.random.seed(seeda if seed is None else seeda							)
										lowercase_					=      dtypes.as_dtype(UpperCamelCase__							).base_dtype
										if dtype not in (dtypes.uinta, dtypes.floataa):
															raise TypeError("""Invalid image dtype %r, expected uint8 or float32""" % dtype							)
										if fake_data:
															lowercase_					=      10_000
															lowercase_					=      one_hot
										else:
															assert (
															    images.shape[0] == labels.shape[0]
															), F'''images.shape: {images.shape} labels.shape: {labels.shape}'''
															lowercase_					=      images.shape[0]

															# Convert shape from [num examples, rows, columns, depth]
															# to [num examples, rows*columns] (assuming depth == 1)
															if reshape:
																				assert images.shape[3] == 1
																				lowercase_					=      images.reshape(
																				    images.shape[0]				,       images.shape[1] * images.shape[2]							)
															if dtype == dtypes.floataa:
																				# Convert from [0, 255] -> [0.0, 1.0].
																				lowercase_					=      images.astype(numpy.floataa							)
																				lowercase_					=      numpy.multiply(UpperCamelCase__				,       1.0 / 255.0							)
										lowercase_					=      images
										lowercase_					=      labels
										lowercase_					=      0
										lowercase_					=      0

					@property
					def 	UpperCAmelCase__							(  self							: Any							):






										'''simple docstring'''






										return self._images

					@property
					def 	UpperCAmelCase__							(  self							: str							):






										'''simple docstring'''






										return self._labels

					@property
					def 	UpperCAmelCase__							(  self							: Optional[int]							):






										'''simple docstring'''






										return self._num_examples

					@property
					def 	UpperCAmelCase__							(  self							: int							):






										'''simple docstring'''






										return self._epochs_completed







					def 	UpperCAmelCase__							(  self							: Optional[int]				,       UpperCamelCase__							: List[str]				,       UpperCamelCase__							: List[Any]=False				,       UpperCamelCase__							: Union[str, Any]=True							):






										'''simple docstring'''






										if fake_data:
															lowercase_					=      [1] * 784
															lowercase_					=      [1] + [0] * 9 if self.one_hot else 0
															return (
															    [fake_image for _ in range(UpperCamelCase__							)],
															    [fake_label for _ in range(UpperCamelCase__							)],
															)
										lowercase_					=      self._index_in_epoch
										# Shuffle for the first epoch
										if self._epochs_completed == 0 and start == 0 and shuffle:
															lowercase_					=      numpy.arange(self._num_examples							)
															numpy.random.shuffle(UpperCamelCase__							)
															lowercase_					=      self.images[perma]
															lowercase_					=      self.labels[perma]
										# Go to the next epoch
										if start + batch_size > self._num_examples:
															# Finished epoch
															self._epochs_completed += 1
															# Get the rest examples in this epoch
															lowercase_					=      self._num_examples - start
															lowercase_					=      self._images[start : self._num_examples]
															lowercase_					=      self._labels[start : self._num_examples]
															# Shuffle the data
															if shuffle:
																				lowercase_					=      numpy.arange(self._num_examples							)
																				numpy.random.shuffle(UpperCamelCase__							)
																				lowercase_					=      self.images[perm]
																				lowercase_					=      self.labels[perm]
															# Start next epoch
															lowercase_					=      0
															lowercase_					=      batch_size - rest_num_examples
															lowercase_					=      self._index_in_epoch
															lowercase_					=      self._images[start:end]
															lowercase_					=      self._labels[start:end]
															return (
															    numpy.concatenate((images_rest_part, images_new_part)				,       axis=0							),
															    numpy.concatenate((labels_rest_part, labels_new_part)				,       axis=0							),
															)
										else:
															self._index_in_epoch += batch_size
															lowercase_					=      self._index_in_epoch
															return self._images[start:end], self._labels[start:end]



@deprecated(lowercase_    ,				"""Please write your own downloading logic."""	)
def       UpperCAmelCase_					(   UpperCAmelCase__    ,				UpperCAmelCase__    ,				UpperCAmelCase__	):




					if not gfile.Exists(lowercase_	):
										gfile.MakeDirs(lowercase_	)
					lowercase_					=      os.path.join(lowercase_    ,				lowercase_	)
					if not gfile.Exists(lowercase_	):
										urllib.request.urlretrieve(lowercase_    ,				lowercase_	)  # noqa: S310
										with gfile.GFile(lowercase_	) as f:
															lowercase_					=      f.size()
										print("""Successfully downloaded"""    ,				lowercase_    ,				lowercase_    ,				"""bytes."""	)
					return filepath



@deprecated(
    lowercase_    ,				"""Please use alternatives such as:""" """ tensorflow_datasets.load(\'mnist\')"""	)
def       UpperCAmelCase_					(   UpperCAmelCase__    ,				UpperCAmelCase__=False    ,				UpperCAmelCase__=False    ,				UpperCAmelCase__=dtypes.floataa    ,				UpperCAmelCase__=True    ,				UpperCAmelCase__=5_0_0_0    ,				UpperCAmelCase__=None    ,				UpperCAmelCase__=DEFAULT_SOURCE_URL    ,				):




					if fake_data:

										def fake():
															return _DataSet(
															    []    ,				[]    ,				fake_data=lowercase_    ,				one_hot=lowercase_    ,				dtype=lowercase_    ,				seed=lowercase_	)

										lowercase_					=      fake()
										lowercase_					=      fake()
										lowercase_					=      fake()
										return _Datasets(train=lowercase_    ,				validation=lowercase_    ,				test=lowercase_	)

					if not source_url:  # empty string check
										lowercase_					=      DEFAULT_SOURCE_URL

					lowercase_					=      """train-images-idx3-ubyte.gz"""
					lowercase_					=      """train-labels-idx1-ubyte.gz"""
					lowercase_					=      """t10k-images-idx3-ubyte.gz"""
					lowercase_					=      """t10k-labels-idx1-ubyte.gz"""

					lowercase_					=      _maybe_download(
					    lowercase_    ,				lowercase_    ,				source_url + train_images_file	)
					with gfile.Open(lowercase_    ,				"""rb"""	) as f:
										lowercase_					=      _extract_images(lowercase_	)

					lowercase_					=      _maybe_download(
					    lowercase_    ,				lowercase_    ,				source_url + train_labels_file	)
					with gfile.Open(lowercase_    ,				"""rb"""	) as f:
										lowercase_					=      _extract_labels(lowercase_    ,				one_hot=lowercase_	)

					lowercase_					=      _maybe_download(
					    lowercase_    ,				lowercase_    ,				source_url + test_images_file	)
					with gfile.Open(lowercase_    ,				"""rb"""	) as f:
										lowercase_					=      _extract_images(lowercase_	)

					lowercase_					=      _maybe_download(
					    lowercase_    ,				lowercase_    ,				source_url + test_labels_file	)
					with gfile.Open(lowercase_    ,				"""rb"""	) as f:
										lowercase_					=      _extract_labels(lowercase_    ,				one_hot=lowercase_	)

					if not 0 <= validation_size <= len(lowercase_	):
										lowercase_					=      (
										    """Validation size should be between 0 and """
										    F'''{len(lowercase_	)}. Received: {validation_size}.'''
										)
										raise ValueError(lowercase_	)

					lowercase_					=      train_images[:validation_size]
					lowercase_					=      train_labels[:validation_size]
					lowercase_					=      train_images[validation_size:]
					lowercase_					=      train_labels[validation_size:]

					lowercase_					=      {"""dtype""": dtype, """reshape""": reshape, """seed""": seed}

					lowercase_					=      _DataSet(lowercase_    ,				lowercase_    ,				**lowercase_	)
					lowercase_					=      _DataSet(lowercase_    ,				lowercase_    ,				**lowercase_	)
					lowercase_					=      _DataSet(lowercase_    ,				lowercase_    ,				**lowercase_	)

					return _Datasets(train=lowercase_    ,				validation=lowercase_    ,				test=lowercase_	)










'''simple docstring'''







import math

import qiskit


def       __UpperCamelCase					(      lowercase_       :  int = 1   ,       lowercase_       :  int = 1   ,       lowercase_       :  int = 1   ):
       """simple docstring"""




       if (
           isinstance(lowercase_   ,       lowercase_   )
           or isinstance(lowercase_   ,       lowercase_   )
           or isinstance(lowercase_   ,       lowercase_   )
       ):
              raise TypeError('inputs must be integers.'   )

       if (input_a < 0) or (input_a < 0) or (carry_in < 0):
              raise ValueError('inputs must be positive.'   )

       if (
           (math.floor(lowercase_   ) != input_a)
           or (math.floor(lowercase_   ) != input_a)
           or (math.floor(lowercase_   ) != carry_in)
       ):
              raise ValueError('inputs must be exact integers.'   )

       if (input_a > 2) or (input_a > 2) or (carry_in > 2):
              raise ValueError('inputs must be less or equal to 2.'   )

       # build registers
       a_						     =			qiskit.QuantumRegister(4   ,       'qr'   )
       a_						     =			qiskit.ClassicalRegister(2   ,       'cr'   )
       # list the entries
       a_						     =			[input_a, input_a, carry_in]

       a_						     =			qiskit.QuantumCircuit(lowercase_   ,       lowercase_   )

       for i in range(0   ,       3   ):
              if entry[i] == 2:
                     quantum_circuit.h(lowercase_   )  # for hadamard entries
              elif entry[i] == 1:
                     quantum_circuit.x(lowercase_   )  # for 1 entries
              elif entry[i] == 0:
                     quantum_circuit.i(lowercase_   )  # for 0 entries

    # build the circuit
       quantum_circuit.ccx(0   ,       1   ,       3   )  # ccx = toffoli gate
       quantum_circuit.cx(0   ,       1   )
       quantum_circuit.ccx(1   ,       2   ,       3   )
       quantum_circuit.cx(1   ,       2   )
       quantum_circuit.cx(0   ,       1   )

       quantum_circuit.measure([2, 3]   ,       lowercase_   )  # measure the last two qbits

       a_						     =			qiskit.Aer.get_backend('aer_simulator'   )
       a_						     =			qiskit.execute(lowercase_   ,       lowercase_   ,       shots=1_000   )

       return job.result().get_counts(lowercase_   )


if __name__ == "__main__":
  print(f"""Total sum count for state is: {quantum_full_adder(1, 1, 1)}""")




