


import os

import pytest
import yaml

from datasets.features.features import Features, Value
from datasets.info import DatasetInfo, DatasetInfosDict



@pytest.mark.parametrize(
    '''files''' ,   [
        ['''full:README.md''', '''dataset_infos.json'''],
        ['''empty:README.md''', '''dataset_infos.json'''],
        ['''dataset_infos.json'''],
        ['''full:README.md'''],
    ] ,   )
def 			lowerCAmelCase (		lowerCAmelCase_ ,   lowerCAmelCase_ )-> Dict:
				lowerCAmelCase_ :      List[str]    				=				tmp_path_factory.mktemp('''dset_infos_dir''' )
				if "full:README.md" in files:
								with open(dataset_infos_dir / '''README.md''' ,   '''w''' ) as f:
												f.write('''---\ndataset_info:\n  dataset_size: 42\n---''' )
				if "empty:README.md" in files:
								with open(dataset_infos_dir / '''README.md''' ,   '''w''' ) as f:
												f.write('''''' )
    # we want to support dataset_infos.json for backward compatibility
				if "dataset_infos.json" in files:
								with open(dataset_infos_dir / '''dataset_infos.json''' ,   '''w''' ) as f:
												f.write('''{"default": {"dataset_size": 42}}''' )
				lowerCAmelCase_ :      Tuple    				=				DatasetInfosDict.from_directory(lowerCAmelCase_ )
				assert dataset_infos
				assert dataset_infos["default"].dataset_size == 42



@pytest.mark.parametrize(
    '''dataset_info''' ,   [
        DatasetInfo(),
        DatasetInfo(
            description='''foo''' ,   features=Features({'''a''': Value('''int32''' )} ) ,   builder_name='''builder''' ,   config_name='''config''' ,   version='''1.0.0''' ,   splits=[{'''name''': '''train'''}] ,   download_size=42 ,   ),
    ] ,   )
def 			lowerCAmelCase (		lowerCAmelCase_ ,   lowerCAmelCase_ )-> List[Any]:
				lowerCAmelCase_ :      Tuple    				=				str(lowerCAmelCase_ )
				dataset_info.write_to_directory(lowerCAmelCase_ )
				lowerCAmelCase_ :      List[str]    				=				DatasetInfo.from_directory(lowerCAmelCase_ )
				assert dataset_info == reloaded
				assert os.path.exists(os.path.join(lowerCAmelCase_ ,   '''dataset_info.json''' ) )



def 			lowerCAmelCase (		)-> Any:
				lowerCAmelCase_ :      Tuple    				=				DatasetInfo(
				    description='''foo''' ,   citation='''bar''' ,   homepage='''https://foo.bar''' ,   license='''CC0''' ,   features=Features({'''a''': Value('''int32''' )} ) ,   post_processed={} ,   supervised_keys=() ,   task_templates=[] ,   builder_name='''builder''' ,   config_name='''config''' ,   version='''1.0.0''' ,   splits=[{'''name''': '''train''', '''num_examples''': 42}] ,   download_checksums={} ,   download_size=1_337 ,   post_processing_size=442 ,   dataset_size=1_234 ,   size_in_bytes=1_337 + 442 + 1_234 ,   )
				lowerCAmelCase_ :      Any    				=				dataset_info._to_yaml_dict()
				assert sorted(lowerCAmelCase_ ) == sorted(DatasetInfo._INCLUDED_INFO_IN_YAML )
				for key in DatasetInfo._INCLUDED_INFO_IN_YAML:
								assert key in dataset_info_yaml_dict
								assert isinstance(dataset_info_yaml_dict[key] ,   (list, dict, int, str) )
				lowerCAmelCase_ :      Tuple    				=				yaml.safe_dump(lowerCAmelCase_ )
				lowerCAmelCase_ :      int    				=				yaml.safe_load(lowerCAmelCase_ )
				assert dataset_info_yaml_dict == reloaded



def 			lowerCAmelCase (		)-> List[Any]:
				lowerCAmelCase_ :      Optional[Any]    				=				DatasetInfo()
				lowerCAmelCase_ :      int    				=				dataset_info._to_yaml_dict()
				assert dataset_info_yaml_dict == {}



@pytest.mark.parametrize(
    '''dataset_infos_dict''' ,   [
        DatasetInfosDict(),
        DatasetInfosDict({'''default''': DatasetInfo()} ),
        DatasetInfosDict({'''my_config_name''': DatasetInfo()} ),
        DatasetInfosDict(
            {
                '''default''': DatasetInfo(
                    description='''foo''' ,   features=Features({'''a''': Value('''int32''' )} ) ,   builder_name='''builder''' ,   config_name='''config''' ,   version='''1.0.0''' ,   splits=[{'''name''': '''train'''}] ,   download_size=42 ,   )
            } ),
        DatasetInfosDict(
            {
                '''v1''': DatasetInfo(dataset_size=42 ),
                '''v2''': DatasetInfo(dataset_size=1_337 ),
            } ),
    ] ,   )
def 			lowerCAmelCase (		lowerCAmelCase_ ,   lowerCAmelCase_ )-> List[str]:
				lowerCAmelCase_ :      List[str]    				=				str(lowerCAmelCase_ )
				dataset_infos_dict.write_to_directory(lowerCAmelCase_ )
				lowerCAmelCase_ :      List[Any]    				=				DatasetInfosDict.from_directory(lowerCAmelCase_ )

				# the config_name of the dataset_infos_dict take over the attribute
				for config_name, dataset_info in dataset_infos_dict.items():
								lowerCAmelCase_ :      List[str]    				=				config_name
								# the yaml representation doesn't include fields like description or citation
								# so we just test that we can recover what we can from the yaml
								lowerCAmelCase_ :      str    				=				DatasetInfo._from_yaml_dict(dataset_info._to_yaml_dict() )
				assert dataset_infos_dict == reloaded

				if dataset_infos_dict:
								assert os.path.exists(os.path.join(lowerCAmelCase_ ,   '''README.md''' ) )



import math

import qiskit



def 			lowerCAmelCase (		lowerCAmelCase_ = 1 ,   lowerCAmelCase_ = 1 ,   lowerCAmelCase_ = 1 )-> qiskit.result.counts.Counts:
				if (
				    isinstance(lowerCAmelCase_ ,   lowerCAmelCase_ )
				    or isinstance(lowerCAmelCase_ ,   lowerCAmelCase_ )
				    or isinstance(lowerCAmelCase_ ,   lowerCAmelCase_ )
				):
								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(lowerCAmelCase_ ) != input_a)
				    or (math.floor(lowerCAmelCase_ ) != input_a)
				    or (math.floor(lowerCAmelCase_ ) != 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
				lowerCAmelCase_ :      str    				=				qiskit.QuantumRegister(4 ,   '''qr''' )
				lowerCAmelCase_ :      str    				=				qiskit.ClassicalRegister(2 ,   '''cr''' )
				# list the entries
				lowerCAmelCase_ :      Any    				=				[input_a, input_a, carry_in]

				lowerCAmelCase_ :      int    				=				qiskit.QuantumCircuit(lowerCAmelCase_ ,   lowerCAmelCase_ )

				for i in range(0 ,   3 ):
								if entry[i] == 2:
												quantum_circuit.h(lowerCAmelCase_ )  # for hadamard entries
								elif entry[i] == 1:
												quantum_circuit.x(lowerCAmelCase_ )  # for 1 entries
								elif entry[i] == 0:
												quantum_circuit.i(lowerCAmelCase_ )  # 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] ,   lowerCAmelCase_ )  # measure the last two qbits

				lowerCAmelCase_ :      Tuple    				=				qiskit.Aer.get_backend('''aer_simulator''' )
				lowerCAmelCase_ :      Union[str, Any]    				=				qiskit.execute(lowerCAmelCase_ ,   lowerCAmelCase_ ,   shots=1_000 )

				return job.result().get_counts(lowerCAmelCase_ )


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