From 03999bd82d66d2cfb62cdcccd15d6dd3b9ad074d Mon Sep 17 00:00:00 2001 From: Hiroshi Horii Date: Tue, 4 Jan 2022 23:12:41 +0900 Subject: [PATCH] renewed benchmarks Previous benchmarks tracked only C++ implementation. However, in recent releases, functions in Python were increased to transpile, assemble, and support control-flow. With this change, benchmarks additionally track python implementation. --- test/asv.linux.conf.json | 16 +- test/asv.linux.cuda.conf.json | 17 +- test/asv.mac.conf.json | 183 ++++++++++++++ test/benchmark/__init__.py | 5 - test/benchmark/basic.py | 44 ---- test/benchmark/basic_05q.py | 126 --------- test/benchmark/basic_15q.py | 126 --------- test/benchmark/basic_25q.py | 126 --------- test/benchmark/circuit_library_circuits.py | 107 -------- test/benchmark/default_simulator.py | 281 +++++++++++++++++++++ test/benchmark/densitymatrix_cpu.py | 46 ++++ test/benchmark/densitymatrix_gpu.py | 47 ++++ test/benchmark/mps_cpu.py | 47 ++++ test/benchmark/noise.py | 47 ---- test/benchmark/noise_12q.py | 85 ------- test/benchmark/noise_16q.py | 85 ------- test/benchmark/noise_20q.py | 85 ------- test/benchmark/output.py | 41 --- test/benchmark/output_05q.py | 80 ------ test/benchmark/output_15q.py | 80 ------ test/benchmark/output_25q.py | 80 ------ test/benchmark/simulator_benchmark.py | 218 ---------------- test/benchmark/statevector_cpu.py | 46 ++++ test/benchmark/statevector_gpu.py | 46 ++++ test/benchmark/unitary_cpu.py | 39 +++ test/benchmark/vqe_application.py | 109 -------- 26 files changed, 743 insertions(+), 1469 deletions(-) create mode 100644 test/asv.mac.conf.json delete mode 100644 test/benchmark/basic.py delete mode 100644 test/benchmark/basic_05q.py delete mode 100644 test/benchmark/basic_15q.py delete mode 100644 test/benchmark/basic_25q.py delete mode 100644 test/benchmark/circuit_library_circuits.py create mode 100644 test/benchmark/default_simulator.py create mode 100644 test/benchmark/densitymatrix_cpu.py create mode 100644 test/benchmark/densitymatrix_gpu.py create mode 100644 test/benchmark/mps_cpu.py delete mode 100644 test/benchmark/noise.py delete mode 100644 test/benchmark/noise_12q.py delete mode 100644 test/benchmark/noise_16q.py delete mode 100644 test/benchmark/noise_20q.py delete mode 100644 test/benchmark/output.py delete mode 100644 test/benchmark/output_05q.py delete mode 100644 test/benchmark/output_15q.py delete mode 100644 test/benchmark/output_25q.py delete mode 100644 test/benchmark/simulator_benchmark.py create mode 100644 test/benchmark/statevector_cpu.py create mode 100644 test/benchmark/statevector_gpu.py create mode 100644 test/benchmark/unitary_cpu.py delete mode 100644 test/benchmark/vqe_application.py diff --git a/test/asv.linux.conf.json b/test/asv.linux.conf.json index 9db91e1339..ce49fc0a9b 100644 --- a/test/asv.linux.conf.json +++ b/test/asv.linux.conf.json @@ -33,27 +33,19 @@ "install_command": [ "python -c \"import shutil; shutil.rmtree('{build_dir}/qiskit', True)\"", "python -c \"import shutil; shutil.rmtree('{build_dir}/qiskit_aer.egg-info', True)\"", - "pip install git+https://github.com/Qiskit/qiskit-terra", - "pip install qiskit_nature", + "pip install -U qiskit-terra", "python -mpip install {wheel_file}" ], "uninstall_command": [ - "return-code=any python -mpip uninstall -y qiskit-terra", - "return-code=any python -mpip uninstall -y qiskit_nature", "return-code=any python -mpip uninstall -y {project}" ], "build_command": [ - "python -mpip install -U scikit-build", - "pip install git+https://github.com/Qiskit/qiskit-terra", - "pip install pyscf", - "pip install matplotlib", - "pip install qiskit_nature", "python setup.py bdist_wheel --dist-dir={build_cache_dir} -- -DCMAKE_CXX_COMPILER=g++ -- -j" ], // List of branches to benchmark. If not provided, defaults to "main" // (for git) or "default" (for mercurial). - // "branches": ["main"], // for git + "branches": ["main"], // for git // "branches": ["default"], // for mercurial // The DVCS being used. If not set, it will be automatically @@ -155,7 +147,7 @@ // The directory (relative to the current directory) that the html tree // should be written to. If not provided, defaults to "html". // "html_dir": "html", - "html_dir": ".asv/html" + "html_dir": ".asv/html", // The number of characters to retain in the commit hashes. // "hash_length": 8, @@ -163,7 +155,7 @@ // `asv` will cache results of the recent builds in each // environment, making them faster to install next time. This is // the number of builds to keep, per environment. - // "build_cache_size": 2, + "build_cache_size": 100000 // The commits after which the regression search in `asv publish` // should start looking for regressions. Dictionary whose keys are diff --git a/test/asv.linux.cuda.conf.json b/test/asv.linux.cuda.conf.json index 52186fc90e..b709cb5d9e 100644 --- a/test/asv.linux.cuda.conf.json +++ b/test/asv.linux.cuda.conf.json @@ -33,28 +33,19 @@ "install_command": [ "python -c \"import shutil; shutil.rmtree('{build_dir}/qiskit', True)\"", "python -c \"import shutil; shutil.rmtree('{build_dir}/qiskit_aer.egg-info', True)\"", - "pip install git+https://github.com/Qiskit/qiskit-terra", - "pip install qiskit_nature", + "pip install -U qiskit-terra", "python -mpip install {wheel_file}" ], "uninstall_command": [ - "return-code=any python -mpip uninstall -y qiskit-terra", - "return-code=any python -mpip uninstall -y qiskit_nature", "return-code=any python -mpip uninstall -y {project}" ], "build_command": [ - "python -mpip install -U scikit-build", - "pip install git+https://github.com/Qiskit/qiskit-terra", - "pip install qiskit_nature", - "pip install pyscf", - "pip install matplotlib", - "pip install qiskit_nature", "python setup.py bdist_wheel --dist-dir={build_cache_dir} -- -DCMAKE_CXX_COMPILER=g++ -DAER_THRUST_BACKEND=CUDA -- -j" ], // List of branches to benchmark. If not provided, defaults to "main" // (for git) or "default" (for mercurial). - // "branches": ["main"], // for git + "branches": ["main"], // for git // "branches": ["default"], // for mercurial // The DVCS being used. If not set, it will be automatically @@ -156,7 +147,7 @@ // The directory (relative to the current directory) that the html tree // should be written to. If not provided, defaults to "html". // "html_dir": "html", - "html_dir": ".asv/html" + "html_dir": ".asv/html", // The number of characters to retain in the commit hashes. // "hash_length": 8, @@ -164,7 +155,7 @@ // `asv` will cache results of the recent builds in each // environment, making them faster to install next time. This is // the number of builds to keep, per environment. - // "build_cache_size": 2, + "build_cache_size": 100000 // The commits after which the regression search in `asv publish` // should start looking for regressions. Dictionary whose keys are diff --git a/test/asv.mac.conf.json b/test/asv.mac.conf.json new file mode 100644 index 0000000000..9d3c54ce00 --- /dev/null +++ b/test/asv.mac.conf.json @@ -0,0 +1,183 @@ +// To use this configuration for running the benchmarks, we have to run asv like this: +// $ asv --connfig asv.linux.conf.json +{ + // The version of the config file format. Do not change, unless + // you know what you are doing. + "version": 1, + + // The name of the project being benchmarked + "project": "qiskit-aer", + + // The project's homepage + "project_url": "http://qiskit.org/aer", + + // The URL or local path of the source code repository for the + // project being benchmarked + "repo": "../", + + // The Python project's subdirectory in your repo. If missing or + // the empty string, the project is assumed to be located at the root + // of the repository. + // "repo_subdir": "", + + // Customizable commands for building, installing, and + // uninstalling the project. See asv.conf.json documentation. + // + // "install_command": ["python -mpip install {wheel_file}"], + // "uninstall_command": ["return-code=any python -mpip uninstall -y {project}"], + // "build_command": [ + // "python setup.py build", + // "PIP_NO_BUILD_ISOLATION=false python -mpip wheel --no-deps --no-index -w {build_cache_dir} {build_dir}" + // ], + + "install_command": [ + "python -c \"import shutil; shutil.rmtree('{build_dir}/qiskit', True)\"", + "python -c \"import shutil; shutil.rmtree('{build_dir}/qiskit_aer.egg-info', True)\"", + "pip install -U qiskit-terra", + "python -mpip install {wheel_file}" + ], + "uninstall_command": [ + "return-code=any python -mpip uninstall -y {project}" + ], + "build_command": [ + "python setup.py bdist_wheel --dist-dir={build_cache_dir} -- -DCMAKE_CXX_COMPILER=clang++ -- -j8" + ], + + // List of branches to benchmark. If not provided, defaults to "main" + // (for git) or "default" (for mercurial). + "branches": ["main"], // for git + // "branches": ["default"], // for mercurial + + // The DVCS being used. If not set, it will be automatically + // determined from "repo" by looking at the protocol in the URL + // (if remote), or by looking for special directories, such as + // ".git" (if local). + // "dvcs": "git", + + // The tool to use to create environments. May be "conda", + // "virtualenv" or other value depending on the plugins in use. + // If missing or the empty string, the tool will be automatically + // determined by looking for tools on the PATH environment + // variable. + "environment_type": "conda", + + // timeout in seconds for installing any dependencies in environment + // defaults to 10 min + //"install_timeout": 600, + + // the base URL to show a commit for the project. + // "show_commit_url": "http://github.com/owner/project/commit/", + + // The Pythons you'd like to test against. If not provided, defaults + // to the current version of Python used to run `asv`. + // "pythons": ["3.7", "3.8", "3.9"], + + // The list of conda channel names to be searched for benchmark + // dependency packages in the specified order + // "conda_channels": ["conda-forge", "defaults"] + + // The matrix of dependencies to test. Each key is the name of a + // package (in PyPI) and the values are version numbers. An empty + // list or empty string indicates to just test against the default + // (latest) version. null indicates that the package is to not be + // installed. If the package to be tested is only available from + // PyPi, and the 'environment_type' is conda, then you can preface + // the package name by 'pip+', and the package will be installed via + // pip (with all the conda available packages installed first, + // followed by the pip installed packages). + // + // "matrix": { + // "numpy": ["1.6", "1.7"], + // "six": ["", null], // test with and without six installed + // "pip+emcee": [""], // emcee is only available for install with pip. + // }, + + //"matrix": { + // "pip+qiskit-terra": [""], + //}, + + // Combinations of libraries/python versions can be excluded/included + // from the set to test. Each entry is a dictionary containing additional + // key-value pairs to include/exclude. + // + // An exclude entry excludes entries where all values match. The + // values are regexps that should match the whole string. + // + // An include entry adds an environment. Only the packages listed + // are installed. The 'python' key is required. The exclude rules + // do not apply to includes. + // + // In addition to package names, the following keys are available: + // + // - python + // Python version, as in the *pythons* variable above. + // - environment_type + // Environment type, as above. + // - sys_platform + // Platform, as in sys.platform. Possible values for the common + // cases: 'linux2', 'win32', 'cygwin', 'darwin'. + // + // "exclude": [ + // {"python": "3.2", "sys_platform": "win32"}, // skip py3.2 on windows + // {"environment_type": "conda", "six": null}, // don't run without six on conda + // ], + // + // "include": [ + // // additional env for python2.7 + // {"python": "2.7", "numpy": "1.8"}, + // // additional env if run on windows+conda + // {"platform": "win32", "environment_type": "conda", "python": "2.7", "libpython": ""}, + // ], + + // The directory (relative to the current directory) that benchmarks are + // stored in. If not provided, defaults to "benchmarks" + "benchmark_dir": "benchmark", + + + // The directory (relative to the current directory) to cache the Python + // environments in. If not provided, defaults to "env" + // "env_dir": "env", + "env_dir": ".asv/envs", + + // The directory (relative to the current directory) that raw benchmark + // results are stored in. If not provided, defaults to "results". + // "results_dir": "results", + "results_dir": ".asv/results", + + // The directory (relative to the current directory) that the html tree + // should be written to. If not provided, defaults to "html". + // "html_dir": "html", + "html_dir": ".asv/html", + + // The number of characters to retain in the commit hashes. + // "hash_length": 8, + + // `asv` will cache results of the recent builds in each + // environment, making them faster to install next time. This is + // the number of builds to keep, per environment. + "build_cache_size": 100000 + + // The commits after which the regression search in `asv publish` + // should start looking for regressions. Dictionary whose keys are + // regexps matching to benchmark names, and values corresponding to + // the commit (exclusive) after which to start looking for + // regressions. The default is to start from the first commit + // with results. If the commit is `null`, regression detection is + // skipped for the matching benchmark. + // + // "regressions_first_commits": { + // "some_benchmark": "352cdf", // Consider regressions only after this commit + // "another_benchmark": null, // Skip regression detection altogether + // }, + + // The thresholds for relative change in results, after which `asv + // publish` starts reporting regressions. Dictionary of the same + // form as in ``regressions_first_commits``, with values + // indicating the thresholds. If multiple entries match, the + // maximum is taken. If no entry matches, the default is 5%. + // + // "regressions_thresholds": { + // "some_benchmark": 0.01, // Threshold of 1% + // "another_benchmark": 0.5, // Threshold of 50% + // }, +} diff --git a/test/benchmark/__init__.py b/test/benchmark/__init__.py index d5929de93b..e69de29bb2 100644 --- a/test/benchmark/__init__.py +++ b/test/benchmark/__init__.py @@ -1,5 +0,0 @@ -from .simulator_benchmark import SimulatorBenchmarkSuite -from .basic import BasicSimulatorBenchmarkSuite -from .noise import NoiseSimulatorBenchmarkSuite -from .output import OutputSimulatorBenchmarkSuite -from .circuit_library_circuits import CircuitLibraryCircuits \ No newline at end of file diff --git a/test/benchmark/basic.py b/test/benchmark/basic.py deleted file mode 100644 index 80194dccf8..0000000000 --- a/test/benchmark/basic.py +++ /dev/null @@ -1,44 +0,0 @@ -# This code is part of Qiskit. -# -# (C) Copyright IBM 2018, 2019, 2020. -# -# This code is licensed under the Apache License, Version 2.0. You may -# obtain a copy of this license in the LICENSE.txt file in the root directory -# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. -# -# Any modifications or derivative works of this code must retain this -# copyright notice, and modified files need to carry a notice indicating -# that they have been altered from the originals. -""" -Base Class of Basic Circuit Benchmarking -""" -from qiskit.circuit.library import IntegerComparator, WeightedAdder, QuadraticForm - -from benchmark.simulator_benchmark import SimulatorBenchmarkSuite - -class BasicSimulatorBenchmarkSuite(SimulatorBenchmarkSuite): - - def __init__(self, - name = 'basic', - apps = [], - qubits = [], - runtime_names = [], - measures = [], - measure_counts = [], - noise_model_names = []): - super().__init__(name, - apps, - qubits=qubits, - runtime_names=runtime_names, - measures=measures, - measure_counts=measure_counts, - noise_model_names=noise_model_names) - - def track_statevector(self, app, measure, measure_count, noise_name, qubit): - return self._run(self.RUNTIME_STATEVECTOR_CPU, app, measure, measure_count, noise_name, qubit) - - def track_statevector_gpu(self, app, measure, measure_count, noise_name, qubit): - return self._run(self.RUNTIME_STATEVECTOR_GPU, app, measure, measure_count, noise_name, qubit) - - def track_matrix_product_state(self, app, measure, measure_count, noise_name, qubit): - return self._run(self.RUNTIME_MPS_CPU, app, measure, measure_count, noise_name, qubit) diff --git a/test/benchmark/basic_05q.py b/test/benchmark/basic_05q.py deleted file mode 100644 index 6c4a47fbcb..0000000000 --- a/test/benchmark/basic_05q.py +++ /dev/null @@ -1,126 +0,0 @@ -# This code is part of Qiskit. -# -# (C) Copyright IBM 2018, 2019, 2020. -# -# This code is licensed under the Apache License, Version 2.0. You may -# obtain a copy of this license in the LICENSE.txt file in the root directory -# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. -# -# Any modifications or derivative works of this code must retain this -# copyright notice, and modified files need to carry a notice indicating -# that they have been altered from the originals. -""" -Basic Circuit Benchmarking with 5 qubits -""" -from qiskit.circuit.library import IntegerComparator, WeightedAdder, QuadraticForm - -from benchmark.simulator_benchmark import SimulatorBenchmarkSuite -from benchmark.basic import BasicSimulatorBenchmarkSuite - -DEFAULT_QUBITS = [ 5 ] - -DEFAULT_RUNTIME = [ - SimulatorBenchmarkSuite.RUNTIME_STATEVECTOR_CPU, - SimulatorBenchmarkSuite.RUNTIME_MPS_CPU, - SimulatorBenchmarkSuite.RUNTIME_STATEVECTOR_GPU - ] - -DEFAULT_MEASUREMENT_METHODS = [ - SimulatorBenchmarkSuite.MEASUREMENT_SAMPLING - ] - -DEFAULT_MEASUREMENT_COUNTS = SimulatorBenchmarkSuite.DEFAULT_MEASUREMENT_COUNTS - -DEFAULT_NOISE_MODELS = [ - SimulatorBenchmarkSuite.NOISE_IDEAL -] - -class ArithmeticCircuits(BasicSimulatorBenchmarkSuite): - - def __init__(self, - apps = { - 'integer_comparator': 10, - 'weighted_adder': 1, - 'quadratic_form': 10 - }, - qubits = DEFAULT_QUBITS, - runtime_names = DEFAULT_RUNTIME, - measures = DEFAULT_MEASUREMENT_METHODS, - measure_counts = DEFAULT_MEASUREMENT_COUNTS, - noise_model_names = DEFAULT_NOISE_MODELS): - super().__init__('arithmetic_circuits', - apps, - qubits=qubits, - runtime_names=runtime_names, - measures=measures, - measure_counts=measure_counts, - noise_model_names=noise_model_names) - -class BasicChangeCircuits(BasicSimulatorBenchmarkSuite): - - def __init__(self, - apps = {'qft':1 }, - qubits = DEFAULT_QUBITS, - runtime_names = DEFAULT_RUNTIME, - measures = DEFAULT_MEASUREMENT_METHODS, - measure_counts = DEFAULT_MEASUREMENT_COUNTS, - noise_model_names = DEFAULT_NOISE_MODELS): - - super().__init__('basic_change_circuits', - apps, - qubits=qubits, - runtime_names=runtime_names, - measures=measures, - measure_counts=measure_counts, - noise_model_names=noise_model_names) - -class NLocalCircuits(BasicSimulatorBenchmarkSuite): - - def __init__(self, - apps = { - 'real_amplitudes': 10, - 'real_amplitudes_linear': 10, - 'efficient_su2': 10, - 'efficient_su2_linear': 10, - #'excitation_preserving': 10, - #'excitation_preserving_linear': 10 - }, - qubits = DEFAULT_QUBITS, - runtime_names = DEFAULT_RUNTIME, - measures = DEFAULT_MEASUREMENT_METHODS, - measure_counts = DEFAULT_MEASUREMENT_COUNTS, - noise_model_names = DEFAULT_NOISE_MODELS): - super().__init__('n_local_circuits', - apps, - qubits=qubits, - runtime_names=runtime_names, - measures=measures, - measure_counts=measure_counts, - noise_model_names=noise_model_names) - -class ParticularQuantumCircuits(BasicSimulatorBenchmarkSuite): - - def __init__(self, - apps = { - 'fourier_checking': 10, - 'graph_state': 10, - 'hidden_linear_function': 10, - 'iqp': 10, - 'quantum_volume': 1, - 'phase_estimation': 1 }, - qubits = DEFAULT_QUBITS, - runtime_names = DEFAULT_RUNTIME, - measures = DEFAULT_MEASUREMENT_METHODS, - measure_counts = DEFAULT_MEASUREMENT_COUNTS, - noise_model_names=DEFAULT_NOISE_MODELS): - super().__init__('particular_quantum_circuits', - apps, qubits=qubits, - runtime_names=runtime_names, - measures=measures, - measure_counts=measure_counts, - noise_model_names=noise_model_names) - -if __name__ == "__main__": - benchmarks = [ ArithmeticCircuits(), BasicChangeCircuits(), NLocalCircuits(), ParticularQuantumCircuits() ] - for benchmark in benchmarks: - benchmark.run_manual() diff --git a/test/benchmark/basic_15q.py b/test/benchmark/basic_15q.py deleted file mode 100644 index fc3b940e0d..0000000000 --- a/test/benchmark/basic_15q.py +++ /dev/null @@ -1,126 +0,0 @@ -# This code is part of Qiskit. -# -# (C) Copyright IBM 2018, 2019, 2020. -# -# This code is licensed under the Apache License, Version 2.0. You may -# obtain a copy of this license in the LICENSE.txt file in the root directory -# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. -# -# Any modifications or derivative works of this code must retain this -# copyright notice, and modified files need to carry a notice indicating -# that they have been altered from the originals. -""" -Basic Circuit Benchmarking with 15 qubits -""" -from qiskit.circuit.library import IntegerComparator, WeightedAdder, QuadraticForm - -from benchmark.simulator_benchmark import SimulatorBenchmarkSuite -from benchmark.basic import BasicSimulatorBenchmarkSuite - -DEFAULT_QUBITS = [ 15 ] - -DEFAULT_RUNTIME = [ - SimulatorBenchmarkSuite.RUNTIME_STATEVECTOR_CPU, - SimulatorBenchmarkSuite.RUNTIME_MPS_CPU, - SimulatorBenchmarkSuite.RUNTIME_STATEVECTOR_GPU - ] - -DEFAULT_MEASUREMENT_METHODS = [ - SimulatorBenchmarkSuite.MEASUREMENT_SAMPLING - ] - -DEFAULT_MEASUREMENT_COUNTS = SimulatorBenchmarkSuite.DEFAULT_MEASUREMENT_COUNTS - -DEFAULT_NOISE_MODELS = [ - SimulatorBenchmarkSuite.NOISE_IDEAL -] - -class ArithmeticCircuits(BasicSimulatorBenchmarkSuite): - - def __init__(self, - apps = { - 'integer_comparator': 10, - 'weighted_adder': 1, - 'quadratic_form': 10 - }, - qubits = DEFAULT_QUBITS, - runtime_names = DEFAULT_RUNTIME, - measures = DEFAULT_MEASUREMENT_METHODS, - measure_counts = DEFAULT_MEASUREMENT_COUNTS, - noise_model_names = DEFAULT_NOISE_MODELS): - super().__init__('arithmetic_circuits', - apps, - qubits=qubits, - runtime_names=runtime_names, - measures=measures, - measure_counts=measure_counts, - noise_model_names=noise_model_names) - -class BasicChangeCircuits(BasicSimulatorBenchmarkSuite): - - def __init__(self, - apps = {'qft':1 }, - qubits = DEFAULT_QUBITS, - runtime_names = DEFAULT_RUNTIME, - measures = DEFAULT_MEASUREMENT_METHODS, - measure_counts = DEFAULT_MEASUREMENT_COUNTS, - noise_model_names = DEFAULT_NOISE_MODELS): - - super().__init__('basic_change_circuits', - apps, - qubits=qubits, - runtime_names=runtime_names, - measures=measures, - measure_counts=measure_counts, - noise_model_names=noise_model_names) - -class NLocalCircuits(BasicSimulatorBenchmarkSuite): - - def __init__(self, - apps = { - 'real_amplitudes': 10, - 'real_amplitudes_linear': 10, - 'efficient_su2': 10, - 'efficient_su2_linear': 10, - #'excitation_preserving': 10, - #'excitation_preserving_linear': 10 - }, - qubits = DEFAULT_QUBITS, - runtime_names = DEFAULT_RUNTIME, - measures = DEFAULT_MEASUREMENT_METHODS, - measure_counts = DEFAULT_MEASUREMENT_COUNTS, - noise_model_names = DEFAULT_NOISE_MODELS): - super().__init__('n_local_circuits', - apps, - qubits=qubits, - runtime_names=runtime_names, - measures=measures, - measure_counts=measure_counts, - noise_model_names=noise_model_names) - -class ParticularQuantumCircuits(BasicSimulatorBenchmarkSuite): - - def __init__(self, - apps = { - 'fourier_checking': 10, - 'graph_state': 10, - 'hidden_linear_function': 10, - 'iqp': 10, - 'quantum_volume': 1, - 'phase_estimation': 1 }, - qubits = DEFAULT_QUBITS, - runtime_names = DEFAULT_RUNTIME, - measures = DEFAULT_MEASUREMENT_METHODS, - measure_counts = DEFAULT_MEASUREMENT_COUNTS, - noise_model_names=DEFAULT_NOISE_MODELS): - super().__init__('particular_quantum_circuits', - apps, qubits=qubits, - runtime_names=runtime_names, - measures=measures, - measure_counts=measure_counts, - noise_model_names=noise_model_names) - -if __name__ == "__main__": - benchmarks = [ ArithmeticCircuits(), BasicChangeCircuits(), NLocalCircuits(), ParticularQuantumCircuits() ] - for benchmark in benchmarks: - benchmark.run_manual() diff --git a/test/benchmark/basic_25q.py b/test/benchmark/basic_25q.py deleted file mode 100644 index 9bb05338ca..0000000000 --- a/test/benchmark/basic_25q.py +++ /dev/null @@ -1,126 +0,0 @@ -# This code is part of Qiskit. -# -# (C) Copyright IBM 2018, 2019, 2020. -# -# This code is licensed under the Apache License, Version 2.0. You may -# obtain a copy of this license in the LICENSE.txt file in the root directory -# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. -# -# Any modifications or derivative works of this code must retain this -# copyright notice, and modified files need to carry a notice indicating -# that they have been altered from the originals. -""" -Basic Circuit Benchmarking with 25 qubits -""" -from qiskit.circuit.library import IntegerComparator, WeightedAdder, QuadraticForm - -from benchmark.simulator_benchmark import SimulatorBenchmarkSuite -from benchmark.basic import BasicSimulatorBenchmarkSuite - -DEFAULT_QUBITS = [ 25 ] - -DEFAULT_RUNTIME = [ - SimulatorBenchmarkSuite.RUNTIME_STATEVECTOR_CPU, - #SimulatorBenchmarkSuite.RUNTIME_MPS_CPU, - SimulatorBenchmarkSuite.RUNTIME_STATEVECTOR_GPU - ] - -DEFAULT_MEASUREMENT_METHODS = [ - SimulatorBenchmarkSuite.MEASUREMENT_SAMPLING - ] - -DEFAULT_MEASUREMENT_COUNTS = SimulatorBenchmarkSuite.DEFAULT_MEASUREMENT_COUNTS - -DEFAULT_NOISE_MODELS = [ - SimulatorBenchmarkSuite.NOISE_IDEAL -] - -class ArithmeticCircuits(BasicSimulatorBenchmarkSuite): - - def __init__(self, - apps = { - 'integer_comparator': 10, - 'weighted_adder': 1, - 'quadratic_form': 10 - }, - qubits = DEFAULT_QUBITS, - runtime_names = DEFAULT_RUNTIME, - measures = DEFAULT_MEASUREMENT_METHODS, - measure_counts = DEFAULT_MEASUREMENT_COUNTS, - noise_model_names = DEFAULT_NOISE_MODELS): - super().__init__('arithmetic_circuits', - apps, - qubits=qubits, - runtime_names=runtime_names, - measures=measures, - measure_counts=measure_counts, - noise_model_names=noise_model_names) - -class BasicChangeCircuits(BasicSimulatorBenchmarkSuite): - - def __init__(self, - apps = {'qft':1 }, - qubits = DEFAULT_QUBITS, - runtime_names = DEFAULT_RUNTIME, - measures = DEFAULT_MEASUREMENT_METHODS, - measure_counts = DEFAULT_MEASUREMENT_COUNTS, - noise_model_names = DEFAULT_NOISE_MODELS): - - super().__init__('basic_change_circuits', - apps, - qubits=qubits, - runtime_names=runtime_names, - measures=measures, - measure_counts=measure_counts, - noise_model_names=noise_model_names) - -class NLocalCircuits(BasicSimulatorBenchmarkSuite): - - def __init__(self, - apps = { - 'real_amplitudes': 10, - 'real_amplitudes_linear': 10, - 'efficient_su2': 10, - 'efficient_su2_linear': 10, - #'excitation_preserving': 10, - #'excitation_preserving_linear': 10 - }, - qubits = DEFAULT_QUBITS, - runtime_names = DEFAULT_RUNTIME, - measures = DEFAULT_MEASUREMENT_METHODS, - measure_counts = DEFAULT_MEASUREMENT_COUNTS, - noise_model_names = DEFAULT_NOISE_MODELS): - super().__init__('n_local_circuits', - apps, - qubits=qubits, - runtime_names=runtime_names, - measures=measures, - measure_counts=measure_counts, - noise_model_names=noise_model_names) - -class ParticularQuantumCircuits(BasicSimulatorBenchmarkSuite): - - def __init__(self, - apps = { - 'fourier_checking': 10, - 'graph_state': 10, - 'hidden_linear_function': 10, - 'iqp': 10, - 'quantum_volume': 1, - 'phase_estimation': 1 }, - qubits = DEFAULT_QUBITS, - runtime_names = DEFAULT_RUNTIME, - measures = DEFAULT_MEASUREMENT_METHODS, - measure_counts = DEFAULT_MEASUREMENT_COUNTS, - noise_model_names=DEFAULT_NOISE_MODELS): - super().__init__('particular_quantum_circuits', - apps, qubits=qubits, - runtime_names=runtime_names, - measures=measures, - measure_counts=measure_counts, - noise_model_names=noise_model_names) - -if __name__ == "__main__": - benchmarks = [ ArithmeticCircuits(), BasicChangeCircuits(), NLocalCircuits(), ParticularQuantumCircuits() ] - for benchmark in benchmarks: - benchmark.run_manual() diff --git a/test/benchmark/circuit_library_circuits.py b/test/benchmark/circuit_library_circuits.py deleted file mode 100644 index d50e3e7b05..0000000000 --- a/test/benchmark/circuit_library_circuits.py +++ /dev/null @@ -1,107 +0,0 @@ -# This code is part of Qiskit. -# -# (C) Copyright IBM 2018, 2019, 2020. -# -# This code is licensed under the Apache License, Version 2.0. You may -# obtain a copy of this license in the LICENSE.txt file in the root directory -# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. -# -# Any modifications or derivative works of this code must retain this -# copyright notice, and modified files need to carry a notice indicating -# that they have been altered from the originals. -""" -Circuit Generator -""" -import numpy as np - -from qiskit.circuit.library import * - -class CircuitLibraryCircuits(): - - def _repeat(self, circ, repeats): - if repeats is not None and repeats > 1: - circ = circ.repeat(repeats) - return circ - - def integer_comparator(self, qubit, repeats): - if qubit < 2: - raise ValueError('qubit is too small: {0}'.format(qubit)) - half = int(qubit / 2) - return self._repeat(IntegerComparator(num_state_qubits=half, value=1), repeats) - - def weighted_adder(self, qubit, repeats): - if qubit > 20: - raise ValueError('qubit is too big: {0}'.format(qubit)) - return self._repeat(WeightedAdder(num_state_qubits=qubit), repeats) - - def quadratic_form(self, qubit, repeats): - if qubit < 4: - raise ValueError('qubit is too small: {0}'.format(qubit)) - return self._repeat(QuadraticForm(num_result_qubits=(qubit - 3), linear=[1, 1, 1], little_endian=True), repeats) - - def qft(self, qubit, repeats): - return self._repeat(QFT(qubit), repeats) - - def real_amplitudes(self, qubit, repeats): - return RealAmplitudes(qubit, reps=repeats) - - def real_amplitudes_linear(self, qubit, repeats): - return RealAmplitudes(qubit, reps=repeats, entanglement='linear') - - def efficient_su2(self, qubit, repeats): - return EfficientSU2(qubit) - - def efficient_su2_linear(self, qubit, repeats): - return EfficientSU2(qubit, reps=repeats, entanglement='linear') - - def excitation_preserving(self, qubit, repeats): - return ExcitationPreserving(qubit, reps=repeats) - - def excitation_preserving_linear(self, qubit, repeats): - return ExcitationPreserving(qubit, reps=repeats, entanglement='linear') - - def fourier_checking(self, qubit, repeats): - if qubit > 20: - raise ValueError('qubit is too big: {0}'.format(qubit)) - f = [-1, 1] * (2 ** (qubit - 1)) - g = [1, -1] * (2 ** (qubit - 1)) - return self._repeat(FourierChecking(f, g), repeats) - - def graph_state(self, qubit, repeats): - a = np.reshape([0] * (qubit ** 2), [qubit] * 2) - for _ in range(qubit): - while True: - i = np.random.randint(0, qubit) - j = np.random.randint(0, qubit) - if a[i][j] == 0: - a[i][j] = 1 - a[j][i] = 1 - break - return self._repeat(GraphState(a), repeats) - - def hidden_linear_function(self, qubit, repeats): - a = np.reshape([0] * (qubit ** 2), [qubit] * 2) - for _ in range(qubit): - while True: - i = np.random.randint(0, qubit) - j = np.random.randint(0, qubit) - if a[i][j] == 0: - a[i][j] = 1 - a[j][i] = 1 - break - return self._repeat(HiddenLinearFunction(a), repeats) - - def iqp(self, qubit, repeats): - interactions = np.random.randint(-1024, 1024, (qubit, qubit)) - for i in range(qubit): - for j in range(i + 1, qubit): - interactions[j][i] = interactions[i][j] - return self._repeat(IQP(interactions), repeats) - - def quantum_volume(self, qubit, repeats): - return self._repeat(QuantumVolume(qubit), repeats) - - def phase_estimation(self, qubit, repeats): - if qubit < 5: - raise ValueError('qubit is too small: {0}'.format(qubit)) - return self._repeat(PhaseEstimation(2, QuantumVolume(qubit - 2)), repeats) diff --git a/test/benchmark/default_simulator.py b/test/benchmark/default_simulator.py new file mode 100644 index 0000000000..443dd4b148 --- /dev/null +++ b/test/benchmark/default_simulator.py @@ -0,0 +1,281 @@ +# This code is part of Qiskit. +# +# (C) Copyright IBM 2018, 2019, 2020, 2021, 2022. +# +# This code is licensed under the Apache License, Version 2.0. You may +# obtain a copy of this license in the LICENSE.txt file in the root directory +# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. +# +# Any modifications or derivative works of this code must retain this +# copyright notice, and modified files need to carry a notice indicating +# that they have been altered from the originals. +import numpy as np +from time import time +from abc import ABC + +from qiskit import QuantumCircuit, transpile +import qiskit.quantum_info as qi +from qiskit.circuit.library import QuantumVolume, QFT, RealAmplitudes +from qiskit.providers.aer.noise import NoiseModel, ReadoutError, amplitude_damping_error, depolarizing_error, phase_amplitude_damping_error + +class _Base(ABC): + + def __init__(self, + qubits=[5, 15, 25]): + + self._simulator = None + self.params = (qubits) + self.param_names = ["qubits"] + + def simulator(self): + if self._simulator: + return self._simulator + try: + from qiskit.providers.aer import AerSimulator + self._simulator = AerSimulator() + except: + from qiskit.providers.aer import QasmSimulator + self._simulator = QasmSimulator() + return self._simulator + + def _run(self, circuit, *args, **kwargs): + if self.simulator().__class__.__name__ == 'AerSimulator': + return self.simulator().run(circuit, *args, **kwargs).result() + elif self.simulator().__class__.__name__ in ('QasmSimulator', 'UnitarySimulator'): + from qiskit import assemble + circuit = assemble(circuit, self.simulator()) + return self.simulator().run(circuit, *args, **kwargs).result() + else: + raise ValueError(f'unknown simulator class: {self._simulator.__class__.__name__}') + + +class Benchmark(_Base): + + def __init__(self, + qubits=[5, 15, 25]): + + super().__init__(qubits) + + def _track(self, circuit): + """track only simulation time of given circuit""" + + self.add_measure(circuit) + + circuit = transpile(circuit, self.simulator()) + + if circuit.num_parameters > 0: + params = [ np.random.random() for _ in range(circuit.num_parameters) ] + circuit = circuit.bind_parameters(params) + + # benchmark start + start_ts = time() + result = self._run(circuit) + end_ts = time() + # benchmark end + + if result.success: + return end_ts - start_ts + else: + raise ValueError(result.status) + + def add_measure(self, circuit): + """append measurement""" + circuit.measure_all() + + def track_qv(self, qubit): + """simulation time of QuantumVolume""" + return self._track(QuantumVolume(qubit)) + + track_qv.unit = "ms" + + def track_qft(self, qubit): + """simulation time of QFT""" + return self._track(QFT(qubit)) + + track_qft.unit = 'ms' + + def track_real_amplitudes(self, qubit): + """simulation time of RealAmplitudes""" + return self._track(RealAmplitudes(qubit)) + + track_real_amplitudes.unit = 'ms' + + def track_real_amplitudes_full(self, qubit): + """simulation time of RealAmplitudes""" + return self._track(RealAmplitudes(qubit, entanglement='full')) + + track_real_amplitudes_full.unit = 'ms' + + +class ExpVal(_Base): + + def __init__(self, + qubits=[10, 15, 25]): + + super().__init__(qubits) + + def track_expval(self, qubit): + """track only time to calculate expectation values of RealAmplitudes with 1K pauli-strings""" + terms = 1000 + circuit = QuantumCircuit(qubit) + for i in range(qubit): + circuit.h(i) + + rng = np.random.default_rng(1) + pauli_strings = [''.join(s) for s in rng.choice(['I', 'X', 'Y', 'Z'], size=(terms, qubit))] + try: + op = None + for pauli_string in pauli_strings: + if op is None: + op = 1 / terms * qi.SparsePauliOp(pauli_string) + else: + op += 1 / terms * qi.SparsePauliOp(pauli_string) + circuit.save_expectation_value(op, range(qubit)) + except: + from qiskit.providers.aer.extensions import snapshot_expectation_value + circuit.snapshot_expectation_value('expval', [(1/terms, pauli) for pauli in pauli_strings], range(qubit)) + + start_ts = time() + result = self._run(circuit) + end_ts = time() + if not result.success: + raise ValueError(result.status) + + return end_ts - start_ts + + track_expval.unit = "ms" + + def track_expval_var(self, qubit): + """track only time to calculate expectation value variances of RealAmplitudes with 100 pauli-strings""" + + terms = 100 + circuit = QuantumCircuit(qubit) + for i in range(qubit): + circuit.h(i) + + rng = np.random.default_rng(1) + pauli_strings = [''.join(s) for s in rng.choice(['I', 'X', 'Y', 'Z'], size=(terms, qubit))] + try: + op = None + for pauli_string in pauli_strings: + if op is None: + op = rng.random() * qi.SparsePauliOp(pauli_string) + else: + op += rng.random() * qi.SparsePauliOp(pauli_string) + circuit.save_expectation_value_variance(op, range(qubit)) + except: + raise ValueError('no save_expectation_value_variance') + + start_ts = time() + result = self._run(circuit) + end_ts = time() + if not result.success: + raise ValueError(result.status) + return end_ts - start_ts + + track_expval_var.unit = "ms" + + +class Noise(_Base): + + def __init__(self, + qubits=[10, 15]): + + super().__init__(qubits) + + def track_depolarizing_error(self, qubit): + """track only time to simulate quantum volume transpiled with basis gates U and CX with depolarizing error""" + circuit = QuantumVolume(qubit) + circuit.measure_all() + + circuit = transpile(circuit, self.simulator(), basis_gates=['u', 'cx']) + + noise_model = NoiseModel() + noise_model.add_all_qubit_quantum_error(depolarizing_error(1e-3, 1), ['u']) + noise_model.add_all_qubit_quantum_error(depolarizing_error(1e-2, 2), ['cx']) + + start_ts = time() + result = self._run(circuit, noise_model=noise_model) + end_ts = time() + if not result.success: + raise ValueError(result.status) + + return end_ts - start_ts + + track_depolarizing_error.unit = "ms" + + def track_amplitude_damping_error(self, qubit): + """track only time to simulate quantum volume transpiled with basis gates U and CX with amplitude damping error""" + circuit = QuantumVolume(qubit) + circuit.measure_all() + + circuit = transpile(circuit, self.simulator(), basis_gates=['u', 'cx']) + + noise_model = NoiseModel() + noise_model.add_all_qubit_quantum_error(amplitude_damping_error(1e-3), 'u') + cx_error = amplitude_damping_error(1e-2) + cx_error = cx_error.tensor(cx_error) + noise_model.add_all_qubit_quantum_error(cx_error, 'cx') + + start_ts = time() + result = self._run(circuit, noise_model=noise_model) + end_ts = time() + if not result.success: + raise ValueError(result.status) + + return end_ts - start_ts + + track_amplitude_damping_error.unit = "ms" + + def track_readout_error(self, qubit): + """track only time to simulate quantum volume transpiled with basis gates U and CX with amplitude damping error""" + circuit = QuantumVolume(qubit) + circuit.measure_all() + + circuit = transpile(circuit, self.simulator()) + + readout_error = [0.01, 0.1] + noise_model = NoiseModel() + readout = [[1.0 - readout_error[0], readout_error[0]], + [readout_error[1], 1.0 - readout_error[1]]] + noise_model.add_all_qubit_readout_error(ReadoutError(readout)) + + start_ts = time() + result = self._run(circuit, noise_model=noise_model) + end_ts = time() + if not result.success: + raise ValueError(result.status) + + return end_ts - start_ts + + track_readout_error.unit = "ms" + + +class ParameterizedCircuit(_Base): + + def __init__(self): + + super().__init__([15]) + + def track_parameterized_circuits(self, qubit): + """track parameterized circuits: 100 sets x 1000 parameters""" + circuit = RealAmplitudes(qubit, reps=100) + circuit.measure_all() + + circuit = transpile(circuit, self.simulator()) + + num_of_params = 10 + param_map = {} + for param in circuit.parameters: + param_values = [ np.random.random() for _ in range(num_of_params) ] + param_map[param] = param_values + + start_ts = time() + result = self._run(circuit, parameter_binds=[param_map]) + end_ts = time() + if not result.success: + raise ValueError(result.status) + + return end_ts - start_ts + + track_parameterized_circuits.unit = "ms" \ No newline at end of file diff --git a/test/benchmark/densitymatrix_cpu.py b/test/benchmark/densitymatrix_cpu.py new file mode 100644 index 0000000000..88477b0f06 --- /dev/null +++ b/test/benchmark/densitymatrix_cpu.py @@ -0,0 +1,46 @@ +# This code is part of Qiskit. +# +# (C) Copyright IBM 2018, 2019, 2020, 2021, 2022. +# +# This code is licensed under the Apache License, Version 2.0. You may +# obtain a copy of this license in the LICENSE.txt file in the root directory +# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. +# +# Any modifications or derivative works of this code must retain this +# copyright notice, and modified files need to carry a notice indicating +# that they have been altered from the originals. +from .default_simulator import Benchmark as BaseBanchmark +from .default_simulator import ExpVal as BaseExpVal +from .default_simulator import Noise as BaseNoise + + +class DensitymatrixCPU: + + def simulator(self): + if self._simulator: + return self._simulator + try: + from qiskit.providers.aer import AerSimulator + self._simulator = AerSimulator(method='density_matrix', device='CPU') + except: + from qiskit.providers.aer import QasmSimulator + self._simulator = QasmSimulator(method='density_matrix') + return self._simulator + + +class Benchmark(DensitymatrixCPU, BaseBanchmark): + + def __init__(self): + super().__init__([5, 13]) + + +class ExpVal(DensitymatrixCPU, BaseExpVal): + + def __init__(self): + super().__init__([5, 13]) + + +class Noise(DensitymatrixCPU, BaseNoise): + + def __init__(self): + super().__init__([5, 13]) diff --git a/test/benchmark/densitymatrix_gpu.py b/test/benchmark/densitymatrix_gpu.py new file mode 100644 index 0000000000..fb7faa1703 --- /dev/null +++ b/test/benchmark/densitymatrix_gpu.py @@ -0,0 +1,47 @@ +# This code is part of Qiskit. +# +# (C) Copyright IBM 2018, 2019, 2020, 2021, 2022. +# +# This code is licensed under the Apache License, Version 2.0. You may +# obtain a copy of this license in the LICENSE.txt file in the root directory +# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. +# +# Any modifications or derivative works of this code must retain this +# copyright notice, and modified files need to carry a notice indicating +# that they have been altered from the originals. +from .default_simulator import Benchmark as BaseBanchmark +from .default_simulator import ExpVal as BaseExpVal +from .default_simulator import Noise as BaseNoise + + +class DensitymatrixGPU: + + def simulator(self): + if self._simulator: + return self._simulator + try: + from qiskit.providers.aer import AerSimulator + self._simulator = AerSimulator(method='density_matrix', device='GPU') + except: + from qiskit.providers.aer import QasmSimulator + self._simulator = QasmSimulator(method='density_matrix_gpu') + return self._simulator + + +class Benchmark(DensitymatrixGPU, BaseBanchmark): + + def __init__(self): + super().__init__([5, 13]) + + +class ExpVal(DensitymatrixGPU, BaseExpVal): + + def __init__(self): + super().__init__([5, 13]) + + +class Noise(DensitymatrixGPU, BaseNoise): + + def __init__(self): + super().__init__([5, 13]) + diff --git a/test/benchmark/mps_cpu.py b/test/benchmark/mps_cpu.py new file mode 100644 index 0000000000..6f04c7f4e6 --- /dev/null +++ b/test/benchmark/mps_cpu.py @@ -0,0 +1,47 @@ +# This code is part of Qiskit. +# +# (C) Copyright IBM 2018, 2019, 2020, 2021, 2022. +# +# This code is licensed under the Apache License, Version 2.0. You may +# obtain a copy of this license in the LICENSE.txt file in the root directory +# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. +# +# Any modifications or derivative works of this code must retain this +# copyright notice, and modified files need to carry a notice indicating +# that they have been altered from the originals. +from .default_simulator import Benchmark as BaseBanchmark +from .default_simulator import ExpVal as BaseExpVal +from .default_simulator import Noise as BaseNoise + + +class MatrixProductStateCPU: + + def simulator(self): + if self._simulator: + return self._simulator + try: + from qiskit.providers.aer import AerSimulator + self._simulator = AerSimulator(method='matrix_product_state', device='CPU') + except: + from qiskit.providers.aer import QasmSimulator + self._simulator = QasmSimulator(method='matrix_product_state') + return self._simulator + + +class Benchmark(MatrixProductStateCPU, BaseBanchmark): + + def __init__(self): + super().__init__([5, 15, 20]) + + +class ExpVal(MatrixProductStateCPU, BaseExpVal): + + def __init__(self): + super().__init__([5, 15, 20]) + + +class Noise(MatrixProductStateCPU, BaseNoise): + + def __init__(self): + super().__init__([5, 15]) + diff --git a/test/benchmark/noise.py b/test/benchmark/noise.py deleted file mode 100644 index 9bed10f321..0000000000 --- a/test/benchmark/noise.py +++ /dev/null @@ -1,47 +0,0 @@ -# This code is part of Qiskit. -# -# (C) Copyright IBM 2018, 2019, 2020. -# -# This code is licensed under the Apache License, Version 2.0. You may -# obtain a copy of this license in the LICENSE.txt file in the root directory -# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. -# -# Any modifications or derivative works of this code must retain this -# copyright notice, and modified files need to carry a notice indicating -# that they have been altered from the originals. -""" -Base Class of Noise Benchmarking -""" -from qiskit.circuit.library import IntegerComparator, WeightedAdder, QuadraticForm - -from benchmark.simulator_benchmark import SimulatorBenchmarkSuite - -class NoiseSimulatorBenchmarkSuite(SimulatorBenchmarkSuite): - - def __init__(self, - name = 'noise', - apps = [], - qubits = [], - runtime_names = [], - measures = [], - measure_counts = [], - noise_model_names = []): - super().__init__(name, - apps, - qubits=qubits, - runtime_names=runtime_names, - measures=measures, - measure_counts=measure_counts, - noise_model_names=noise_model_names) - - def track_statevector(self, app, measure, measure_count, noise_name, qubit): - return self._run(self.RUNTIME_STATEVECTOR_CPU, app, measure, measure_count, noise_name, qubit) - - def track_statevector_gpu(self, app, measure, measure_count, noise_name, qubit): - return self._run(self.RUNTIME_STATEVECTOR_GPU, app, measure, measure_count, noise_name, qubit) - - def track_density_matrix(self, app, measure, measure_count, noise_name, qubit): - return self._run(self.RUNTIME_DENSITY_MATRIX_CPU, app, measure, measure_count, noise_name, qubit) - - def track_density_matrix_gpu(self, app, measure, measure_count, noise_name, qubit): - return self._run(self.RUNTIME_DENSITY_MATRIX_GPU, app, measure, measure_count, noise_name, qubit) \ No newline at end of file diff --git a/test/benchmark/noise_12q.py b/test/benchmark/noise_12q.py deleted file mode 100644 index 752d364e5f..0000000000 --- a/test/benchmark/noise_12q.py +++ /dev/null @@ -1,85 +0,0 @@ -# This code is part of Qiskit. -# -# (C) Copyright IBM 2018, 2019, 2020. -# -# This code is licensed under the Apache License, Version 2.0. You may -# obtain a copy of this license in the LICENSE.txt file in the root directory -# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. -# -# Any modifications or derivative works of this code must retain this -# copyright notice, and modified files need to carry a notice indicating -# that they have been altered from the originals. -""" -Noise Benchmarking with 12 qubits -""" -from benchmark.simulator_benchmark import SimulatorBenchmarkSuite -from benchmark.noise import NoiseSimulatorBenchmarkSuite - -DEFAULT_APPS = { -# 'fourier_checking', -# 'graph_state', -# 'hidden_linear_function', -# 'iqp', - 'quantum_volume': 1 -# 'phase_estimation' - } - -DEFAULT_QUBITS = [12] - -DEFAULT_RUNTIME = [ - SimulatorBenchmarkSuite.RUNTIME_STATEVECTOR_CPU, - SimulatorBenchmarkSuite.RUNTIME_STATEVECTOR_GPU, - SimulatorBenchmarkSuite.RUNTIME_DENSITY_MATRIX_CPU, - SimulatorBenchmarkSuite.RUNTIME_DENSITY_MATRIX_GPU - ] - -DEFAULT_MEASUREMENT_METHODS = [ - SimulatorBenchmarkSuite.MEASUREMENT_SAMPLING - ] - -DEFAULT_MEASUREMENT_COUNTS = [ 1000 ] - -DEFAULT_NOISE_MODELS = [ - SimulatorBenchmarkSuite.NOISE_DAMPING, - SimulatorBenchmarkSuite.NOISE_DEPOLARIZING - ] - -class DampingError(NoiseSimulatorBenchmarkSuite): - - def __init__(self, - apps = DEFAULT_APPS, - qubits = DEFAULT_QUBITS, - runtime_names = DEFAULT_RUNTIME, - measures = DEFAULT_MEASUREMENT_METHODS, - measure_counts = DEFAULT_MEASUREMENT_COUNTS, - noise_model_names = [SimulatorBenchmarkSuite.NOISE_DAMPING] ): - super().__init__('damping_error', - apps, - qubits=qubits, - runtime_names=runtime_names, - measures=measures, - measure_counts=measure_counts, - noise_model_names=noise_model_names) - self.__name__ = 'damping_error' - -class DepolarizingError(NoiseSimulatorBenchmarkSuite): - - def __init__(self, - apps = DEFAULT_APPS, - qubits = DEFAULT_QUBITS, - runtime_names = DEFAULT_RUNTIME, - measures = DEFAULT_MEASUREMENT_METHODS, - measure_counts = DEFAULT_MEASUREMENT_COUNTS, - noise_model_names = [SimulatorBenchmarkSuite.NOISE_DEPOLARIZING] ): - super().__init__('depolarizing_error', - apps, - qubits=qubits, - runtime_names=runtime_names, - measures=measures, - measure_counts=measure_counts, - noise_model_names=noise_model_names) - self.__name__ = 'depolarizing_error' - -if __name__ == "__main__": - DampingError().run_manual() - DepolarizingError().run_manual() \ No newline at end of file diff --git a/test/benchmark/noise_16q.py b/test/benchmark/noise_16q.py deleted file mode 100644 index 90317340c2..0000000000 --- a/test/benchmark/noise_16q.py +++ /dev/null @@ -1,85 +0,0 @@ -# This code is part of Qiskit. -# -# (C) Copyright IBM 2018, 2019, 2020. -# -# This code is licensed under the Apache License, Version 2.0. You may -# obtain a copy of this license in the LICENSE.txt file in the root directory -# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. -# -# Any modifications or derivative works of this code must retain this -# copyright notice, and modified files need to carry a notice indicating -# that they have been altered from the originals. -""" -Noise Benchmarking with 16 qubits -""" -from benchmark.simulator_benchmark import SimulatorBenchmarkSuite -from benchmark.noise import NoiseSimulatorBenchmarkSuite - -DEFAULT_APPS = { -# 'fourier_checking', -# 'graph_state', -# 'hidden_linear_function', -# 'iqp', - 'quantum_volume': 1 -# 'phase_estimation' - } - -DEFAULT_QUBITS = [16] - -DEFAULT_RUNTIME = [ - SimulatorBenchmarkSuite.RUNTIME_STATEVECTOR_CPU, - SimulatorBenchmarkSuite.RUNTIME_STATEVECTOR_GPU, - #SimulatorBenchmarkSuite.RUNTIME_DENSITY_MATRIX_CPU, - #SimulatorBenchmarkSuite.RUNTIME_DENSITY_MATRIX_GPU - ] - -DEFAULT_MEASUREMENT_METHODS = [ - SimulatorBenchmarkSuite.MEASUREMENT_SAMPLING - ] - -DEFAULT_MEASUREMENT_COUNTS = [ 1000 ] - -DEFAULT_NOISE_MODELS = [ - SimulatorBenchmarkSuite.NOISE_DAMPING, - SimulatorBenchmarkSuite.NOISE_DEPOLARIZING - ] - -class DampingError(NoiseSimulatorBenchmarkSuite): - - def __init__(self, - apps = DEFAULT_APPS, - qubits = DEFAULT_QUBITS, - runtime_names = DEFAULT_RUNTIME, - measures = DEFAULT_MEASUREMENT_METHODS, - measure_counts = DEFAULT_MEASUREMENT_COUNTS, - noise_model_names = [SimulatorBenchmarkSuite.NOISE_DAMPING] ): - super().__init__('damping_error', - apps, - qubits=qubits, - runtime_names=runtime_names, - measures=measures, - measure_counts=measure_counts, - noise_model_names=noise_model_names) - self.__name__ = 'damping_error' - -class DepolarizingError(NoiseSimulatorBenchmarkSuite): - - def __init__(self, - apps = DEFAULT_APPS, - qubits = DEFAULT_QUBITS, - runtime_names = DEFAULT_RUNTIME, - measures = DEFAULT_MEASUREMENT_METHODS, - measure_counts = DEFAULT_MEASUREMENT_COUNTS, - noise_model_names = [SimulatorBenchmarkSuite.NOISE_DEPOLARIZING] ): - super().__init__('depolarizing_error', - apps, - qubits=qubits, - runtime_names=runtime_names, - measures=measures, - measure_counts=measure_counts, - noise_model_names=noise_model_names) - self.__name__ = 'depolarizing_error' - -if __name__ == "__main__": - DampingError().run_manual() - DepolarizingError().run_manual() \ No newline at end of file diff --git a/test/benchmark/noise_20q.py b/test/benchmark/noise_20q.py deleted file mode 100644 index 153bae564f..0000000000 --- a/test/benchmark/noise_20q.py +++ /dev/null @@ -1,85 +0,0 @@ -# This code is part of Qiskit. -# -# (C) Copyright IBM 2018, 2019, 2020. -# -# This code is licensed under the Apache License, Version 2.0. You may -# obtain a copy of this license in the LICENSE.txt file in the root directory -# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. -# -# Any modifications or derivative works of this code must retain this -# copyright notice, and modified files need to carry a notice indicating -# that they have been altered from the originals. -""" -Noise Benchmarking with 20 qubits -""" -from benchmark.simulator_benchmark import SimulatorBenchmarkSuite -from benchmark.noise import NoiseSimulatorBenchmarkSuite - -DEFAULT_APPS = { -# 'fourier_checking', -# 'graph_state', -# 'hidden_linear_function', -# 'iqp', - 'quantum_volume': 1 -# 'phase_estimation' - } - -DEFAULT_QUBITS = [20] - -DEFAULT_RUNTIME = [ - SimulatorBenchmarkSuite.RUNTIME_STATEVECTOR_CPU, - SimulatorBenchmarkSuite.RUNTIME_STATEVECTOR_GPU, - #SimulatorBenchmarkSuite.RUNTIME_DENSITY_MATRIX_CPU, - #SimulatorBenchmarkSuite.RUNTIME_DENSITY_MATRIX_GPU - ] - -DEFAULT_MEASUREMENT_METHODS = [ - SimulatorBenchmarkSuite.MEASUREMENT_SAMPLING - ] - -DEFAULT_MEASUREMENT_COUNTS = [ 1000 ] - -DEFAULT_NOISE_MODELS = [ - SimulatorBenchmarkSuite.NOISE_DAMPING, - SimulatorBenchmarkSuite.NOISE_DEPOLARIZING - ] - -class DampingError(NoiseSimulatorBenchmarkSuite): - - def __init__(self, - apps = DEFAULT_APPS, - qubits = DEFAULT_QUBITS, - runtime_names = DEFAULT_RUNTIME, - measures = DEFAULT_MEASUREMENT_METHODS, - measure_counts = DEFAULT_MEASUREMENT_COUNTS, - noise_model_names = [SimulatorBenchmarkSuite.NOISE_DAMPING] ): - super().__init__('damping_error', - apps, - qubits=qubits, - runtime_names=runtime_names, - measures=measures, - measure_counts=measure_counts, - noise_model_names=noise_model_names) - self.__name__ = 'damping_error' - -class DepolarizingError(NoiseSimulatorBenchmarkSuite): - - def __init__(self, - apps = DEFAULT_APPS, - qubits = DEFAULT_QUBITS, - runtime_names = DEFAULT_RUNTIME, - measures = DEFAULT_MEASUREMENT_METHODS, - measure_counts = DEFAULT_MEASUREMENT_COUNTS, - noise_model_names = [SimulatorBenchmarkSuite.NOISE_DEPOLARIZING] ): - super().__init__('depolarizing_error', - apps, - qubits=qubits, - runtime_names=runtime_names, - measures=measures, - measure_counts=measure_counts, - noise_model_names=noise_model_names) - self.__name__ = 'depolarizing_error' - -if __name__ == "__main__": - DampingError().run_manual() - DepolarizingError().run_manual() \ No newline at end of file diff --git a/test/benchmark/output.py b/test/benchmark/output.py deleted file mode 100644 index 36018fd946..0000000000 --- a/test/benchmark/output.py +++ /dev/null @@ -1,41 +0,0 @@ -# This code is part of Qiskit. -# -# (C) Copyright IBM 2018, 2019, 2020. -# -# This code is licensed under the Apache License, Version 2.0. You may -# obtain a copy of this license in the LICENSE.txt file in the root directory -# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. -# -# Any modifications or derivative works of this code must retain this -# copyright notice, and modified files need to carry a notice indicating -# that they have been altered from the originals. -""" -Base Class of Output Benchmarking -""" -from qiskit.circuit.library import IntegerComparator, WeightedAdder, QuadraticForm - -from benchmark.simulator_benchmark import SimulatorBenchmarkSuite - -class OutputSimulatorBenchmarkSuite(SimulatorBenchmarkSuite): - - def __init__(self, - name = 'output', - apps = [], - qubits = [], - runtime_names = [], - measures = [], - measure_counts = [], - noise_model_names = []): - super().__init__(name, - apps, - qubits=qubits, - runtime_names=runtime_names, - measures=measures, - measure_counts=measure_counts, - noise_model_names=noise_model_names) - - def track_statevector(self, app, measure, measure_count, noise_name, qubit): - return self._run(self.RUNTIME_STATEVECTOR_CPU, app, measure, measure_count, noise_name, qubit) - - def track_statevector_gpu(self, app, measure, measure_count, noise_name, qubit): - return self._run(self.RUNTIME_STATEVECTOR_GPU, app, measure, measure_count, noise_name, qubit) \ No newline at end of file diff --git a/test/benchmark/output_05q.py b/test/benchmark/output_05q.py deleted file mode 100644 index 7de05c33d2..0000000000 --- a/test/benchmark/output_05q.py +++ /dev/null @@ -1,80 +0,0 @@ -# This code is part of Qiskit. -# -# (C) Copyright IBM 2018, 2019, 2020. -# -# This code is licensed under the Apache License, Version 2.0. You may -# obtain a copy of this license in the LICENSE.txt file in the root directory -# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. -# -# Any modifications or derivative works of this code must retain this -# copyright notice, and modified files need to carry a notice indicating -# that they have been altered from the originals. -""" -Output Benchmarking with 5 qubits -""" -from benchmark.simulator_benchmark import SimulatorBenchmarkSuite -from benchmark.output import OutputSimulatorBenchmarkSuite - -DEFAULT_APPS = { -# 'fourier_checking', -# 'graph_state', -# 'hidden_linear_function', -# 'iqp', - 'quantum_volume': 1, -# 'phase_estimation' - } - -DEFAULT_QUBITS = [ 5 ] - -DEFAULT_RUNTIME = [ - SimulatorBenchmarkSuite.RUNTIME_STATEVECTOR_CPU, - SimulatorBenchmarkSuite.RUNTIME_STATEVECTOR_GPU, - #SimulatorBenchmarkSuite.RUNTIME_MPS_CPU, - ] - -DEFAULT_MEASUREMENT_COUNTS = [ 1, 10, 100, 1000, 10000 ] - -DEFAULT_NOISE_MODELS = [ - SimulatorBenchmarkSuite.NOISE_IDEAL - ] - -class Sampling(OutputSimulatorBenchmarkSuite): - - def __init__(self, - apps = DEFAULT_APPS, - qubits = DEFAULT_QUBITS, - runtime_names = DEFAULT_RUNTIME, - measures = [SimulatorBenchmarkSuite.MEASUREMENT_SAMPLING], - measure_counts = DEFAULT_MEASUREMENT_COUNTS, - noise_model_names = DEFAULT_NOISE_MODELS): - super().__init__( 'sampling', - apps, - qubits=qubits, - runtime_names=runtime_names, - measures=measures, - measure_counts=measure_counts, - noise_model_names=noise_model_names) - self.__name__ = 'sampling' - -class ExpVal(OutputSimulatorBenchmarkSuite): - - def __init__(self, - apps = DEFAULT_APPS, - qubits = DEFAULT_QUBITS, - runtime_names = DEFAULT_RUNTIME, - measures = [SimulatorBenchmarkSuite.MEASUREMENT_EXPVAL], - measure_counts = DEFAULT_MEASUREMENT_COUNTS, - noise_model_names = DEFAULT_NOISE_MODELS): - super().__init__( 'expval', - apps, - qubits=qubits, - runtime_names=runtime_names, - measures=measures, - measure_counts=measure_counts, - noise_model_names=noise_model_names) - self.__name__ = 'expval' - - -if __name__ == "__main__": - Sampling().run_manual() - ExpVal().run_manual() \ No newline at end of file diff --git a/test/benchmark/output_15q.py b/test/benchmark/output_15q.py deleted file mode 100644 index f5e13907f6..0000000000 --- a/test/benchmark/output_15q.py +++ /dev/null @@ -1,80 +0,0 @@ -# This code is part of Qiskit. -# -# (C) Copyright IBM 2018, 2019, 2020. -# -# This code is licensed under the Apache License, Version 2.0. You may -# obtain a copy of this license in the LICENSE.txt file in the root directory -# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. -# -# Any modifications or derivative works of this code must retain this -# copyright notice, and modified files need to carry a notice indicating -# that they have been altered from the originals. -""" -Output Benchmarking with 15 qubits -""" -from benchmark.simulator_benchmark import SimulatorBenchmarkSuite -from benchmark.output import OutputSimulatorBenchmarkSuite - -DEFAULT_APPS = { -# 'fourier_checking', -# 'graph_state', -# 'hidden_linear_function', -# 'iqp', - 'quantum_volume': 1, -# 'phase_estimation' - } - -DEFAULT_QUBITS = [ 15 ] - -DEFAULT_RUNTIME = [ - SimulatorBenchmarkSuite.RUNTIME_STATEVECTOR_CPU, - SimulatorBenchmarkSuite.RUNTIME_STATEVECTOR_GPU, - #SimulatorBenchmarkSuite.RUNTIME_MPS_CPU, - ] - -DEFAULT_MEASUREMENT_COUNTS = [ 1, 10, 100, 1000, 10000 ] - -DEFAULT_NOISE_MODELS = [ - SimulatorBenchmarkSuite.NOISE_IDEAL - ] - -class Sampling(OutputSimulatorBenchmarkSuite): - - def __init__(self, - apps = DEFAULT_APPS, - qubits = DEFAULT_QUBITS, - runtime_names = DEFAULT_RUNTIME, - measures = [SimulatorBenchmarkSuite.MEASUREMENT_SAMPLING], - measure_counts = DEFAULT_MEASUREMENT_COUNTS, - noise_model_names = DEFAULT_NOISE_MODELS): - super().__init__( 'sampling', - apps, - qubits=qubits, - runtime_names=runtime_names, - measures=measures, - measure_counts=measure_counts, - noise_model_names=noise_model_names) - self.__name__ = 'sampling' - -class ExpVal(OutputSimulatorBenchmarkSuite): - - def __init__(self, - apps = DEFAULT_APPS, - qubits = DEFAULT_QUBITS, - runtime_names = DEFAULT_RUNTIME, - measures = [SimulatorBenchmarkSuite.MEASUREMENT_EXPVAL], - measure_counts = DEFAULT_MEASUREMENT_COUNTS, - noise_model_names = DEFAULT_NOISE_MODELS): - super().__init__( 'expval', - apps, - qubits=qubits, - runtime_names=runtime_names, - measures=measures, - measure_counts=measure_counts, - noise_model_names=noise_model_names) - self.__name__ = 'expval' - - -if __name__ == "__main__": - Sampling().run_manual() - ExpVal().run_manual() \ No newline at end of file diff --git a/test/benchmark/output_25q.py b/test/benchmark/output_25q.py deleted file mode 100644 index 27683b2dd2..0000000000 --- a/test/benchmark/output_25q.py +++ /dev/null @@ -1,80 +0,0 @@ -# This code is part of Qiskit. -# -# (C) Copyright IBM 2018, 2019, 2020. -# -# This code is licensed under the Apache License, Version 2.0. You may -# obtain a copy of this license in the LICENSE.txt file in the root directory -# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. -# -# Any modifications or derivative works of this code must retain this -# copyright notice, and modified files need to carry a notice indicating -# that they have been altered from the originals. -""" -Output Benchmarking with 25 qubits -""" -from benchmark.simulator_benchmark import SimulatorBenchmarkSuite -from benchmark.output import OutputSimulatorBenchmarkSuite - -DEFAULT_APPS = { -# 'fourier_checking', -# 'graph_state', -# 'hidden_linear_function', -# 'iqp', - 'quantum_volume': 1, -# 'phase_estimation' - } - -DEFAULT_QUBITS = [ 25 ] - -DEFAULT_RUNTIME = [ - SimulatorBenchmarkSuite.RUNTIME_STATEVECTOR_CPU, - SimulatorBenchmarkSuite.RUNTIME_STATEVECTOR_GPU, - #SimulatorBenchmarkSuite.RUNTIME_MPS_CPU, - ] - -DEFAULT_MEASUREMENT_COUNTS = [ 1, 10, 100, 1000, 10000 ] - -DEFAULT_NOISE_MODELS = [ - SimulatorBenchmarkSuite.NOISE_IDEAL - ] - -class Sampling(OutputSimulatorBenchmarkSuite): - - def __init__(self, - apps = DEFAULT_APPS, - qubits = DEFAULT_QUBITS, - runtime_names = DEFAULT_RUNTIME, - measures = [SimulatorBenchmarkSuite.MEASUREMENT_SAMPLING], - measure_counts = DEFAULT_MEASUREMENT_COUNTS, - noise_model_names = DEFAULT_NOISE_MODELS): - super().__init__( 'sampling', - apps, - qubits=qubits, - runtime_names=runtime_names, - measures=measures, - measure_counts=measure_counts, - noise_model_names=noise_model_names) - self.__name__ = 'sampling' - -class ExpVal(OutputSimulatorBenchmarkSuite): - - def __init__(self, - apps = DEFAULT_APPS, - qubits = DEFAULT_QUBITS, - runtime_names = DEFAULT_RUNTIME, - measures = [SimulatorBenchmarkSuite.MEASUREMENT_EXPVAL], - measure_counts = DEFAULT_MEASUREMENT_COUNTS, - noise_model_names = DEFAULT_NOISE_MODELS): - super().__init__( 'expval', - apps, - qubits=qubits, - runtime_names=runtime_names, - measures=measures, - measure_counts=measure_counts, - noise_model_names=noise_model_names) - self.__name__ = 'expval' - - -if __name__ == "__main__": - Sampling().run_manual() - ExpVal().run_manual() \ No newline at end of file diff --git a/test/benchmark/simulator_benchmark.py b/test/benchmark/simulator_benchmark.py deleted file mode 100644 index 9bfd8e84e7..0000000000 --- a/test/benchmark/simulator_benchmark.py +++ /dev/null @@ -1,218 +0,0 @@ -# This code is part of Qiskit. -# -# (C) Copyright IBM 2018, 2019, 2020. -# -# This code is licensed under the Apache License, Version 2.0. You may -# obtain a copy of this license in the LICENSE.txt file in the root directory -# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. -# -# Any modifications or derivative works of this code must retain this -# copyright notice, and modified files need to carry a notice indicating -# that they have been altered from the originals. -""" -Base class of Qiskit Aer Benchmarking -""" -import sys -import numpy as np -from time import time -from qiskit.compiler import transpile, assemble -from qiskit.providers.aer import AerSimulator, UnitarySimulator -from qiskit.providers.aer.noise import NoiseModel, amplitude_damping_error, depolarizing_error - -from benchmark.circuit_library_circuits import CircuitLibraryCircuits - -QOBJS = {} - -class SimulatorBenchmarkSuite(CircuitLibraryCircuits): - - RUNTIME_STATEVECTOR_CPU = 'statevector' - RUNTIME_STATEVECTOR_GPU = 'statevector_gpu' - RUNTIME_MPS_CPU = 'matrix_product_state' - RUNTIME_DENSITY_MATRIX_CPU = 'density_matrix' - RUNTIME_DENSITY_MATRIX_GPU = 'density_matrix_gpu' - RUNTIME_STABILIZER_CPU = 'stabilizer' - RUNTIME_EXTENDED_STABILIZER_CPU = 'extended_stabilizer' - RUNTIME_UNITARY_MATRIX_CPU = 'unitary_matrix' - RUNTIME_UNITARY_MATRIX_GPU = 'unitary_matrix_gpu' - - RUNTIME_CPU = [ - RUNTIME_STATEVECTOR_CPU, - RUNTIME_MPS_CPU, - RUNTIME_DENSITY_MATRIX_CPU, - RUNTIME_STABILIZER_CPU, - RUNTIME_EXTENDED_STABILIZER_CPU, - RUNTIME_UNITARY_MATRIX_CPU - ] - - RUNTIME_GPU = [ - RUNTIME_STATEVECTOR_GPU, - RUNTIME_DENSITY_MATRIX_GPU, - RUNTIME_UNITARY_MATRIX_GPU - ] - - DEFAULT_RUNTIME = [ - RUNTIME_STATEVECTOR_CPU, - RUNTIME_MPS_CPU, - RUNTIME_DENSITY_MATRIX_CPU, - RUNTIME_STATEVECTOR_GPU - ] - - DEFAULT_QUBITS = [10, 15, 20, 25] - - MEASUREMENT_SAMPLING = 'sampling' - MEASUREMENT_EXPVAL = 'expval' - - DEFAULT_MEASUREMENT_METHODS = [ MEASUREMENT_SAMPLING ] - DEFAULT_MEASUREMENT_COUNTS = [ 1000 ] - - NOISE_IDEAL = 'ideal' - NOISE_DAMPING = 'damping' - NOISE_DEPOLARIZING = 'depolarizing' - - DEFAULT_NOISE_MODELS = [ NOISE_IDEAL ] - - def __init__(self, - name = 'simulator_benchmark', - apps = {}, - qubits = DEFAULT_QUBITS, - runtime_names = DEFAULT_RUNTIME, - measures = DEFAULT_MEASUREMENT_METHODS, - measure_counts = DEFAULT_MEASUREMENT_COUNTS, - noise_model_names = DEFAULT_NOISE_MODELS): - self.timeout = 60 * 10 - self.__name__ = name - - self.apps = apps if isinstance(apps, list) else [app for app in apps] - self.app2rep = {} if isinstance(apps, list) else apps - self.qubits = qubits - self.runtime_names = runtime_names - self.measures = measures - self.measure_counts = measure_counts - self.noise_model_names = noise_model_names - - self.params = (self.apps, self.measures, self.measure_counts, self.noise_model_names, self.qubits) - self.param_names = ["application", "measure_method", "measure_counts", "noise", "qubit"] - - self.simulators = {} - self.backend_qubits = {} - - self.noise_models = {} - self.noise_models[self.NOISE_IDEAL] = None - if self.NOISE_DAMPING in self.noise_model_names: - noise_model = NoiseModel() - error = amplitude_damping_error(1e-3) - noise_model.add_all_qubit_quantum_error(error, ['u3']) - self.noise_models[self.NOISE_DAMPING] = noise_model - if self.NOISE_DEPOLARIZING in self.noise_model_names: - noise_model = NoiseModel() - noise_model.add_all_qubit_quantum_error(depolarizing_error(1e-3, 1), ['u3']) - noise_model.add_all_qubit_quantum_error(depolarizing_error(1e-2, 2), ['cx']) - self.noise_models[self.NOISE_DEPOLARIZING] = noise_model - - if self.RUNTIME_STATEVECTOR_CPU in runtime_names: - self.simulators[self.RUNTIME_STATEVECTOR_CPU] = AerSimulator(method='statevector', device='CPU') - self.backend_qubits[self.RUNTIME_STATEVECTOR_CPU] = self.qubits - - if self.RUNTIME_STATEVECTOR_GPU in runtime_names: - self.simulators[self.RUNTIME_STATEVECTOR_GPU] = AerSimulator(method='statevector', device='GPU') - self.backend_qubits[self.RUNTIME_STATEVECTOR_GPU] = self.qubits - - if self.RUNTIME_MPS_CPU in runtime_names: - self.simulators[self.RUNTIME_MPS_CPU] = AerSimulator(method='matrix_product_state', device='GPU') - self.backend_qubits[self.RUNTIME_MPS_CPU] = self.qubits - - if self.RUNTIME_DENSITY_MATRIX_CPU in runtime_names: - self.simulators[self.RUNTIME_DENSITY_MATRIX_CPU] = AerSimulator(method='density_matrix', device='CPU') - self.backend_qubits[self.RUNTIME_DENSITY_MATRIX_CPU] = [qubit for qubit in qubits if qubit <= 15] - - if self.RUNTIME_DENSITY_MATRIX_GPU in runtime_names: - self.simulators[self.RUNTIME_DENSITY_MATRIX_GPU] = AerSimulator(method='density_matrix', device='GPU') - self.backend_qubits[self.RUNTIME_DENSITY_MATRIX_GPU] = [qubit for qubit in qubits if qubit <= 15] - - def gen_qobj(self, runtime, app, measure, measure_count, qubit, noise_name): - - def add_measure_all(base): - circuit = base.copy() - circuit.measure_all() - return circuit - - def add_expval(base, num_terms): - circuit = base.copy() - from qiskit.providers.aer.extensions import snapshot_expectation_value - from numpy.random import default_rng - rng = default_rng(1) - paulis = [''.join(s) for s in - rng.choice(['I', 'X', 'Y', 'Z'], size=(num_terms, qubit))] - pauli_op = [(1 / num_terms, pauli) for pauli in paulis] - circuit.snapshot_expectation_value('expval', pauli_op, range(qubit)) - - circuit = eval('self.{0}'.format(app))(qubit, None if app not in self.app2rep else self.app2rep[app]) - noise_model = self.noise_models[noise_name] - - if len(circuit.parameters) > 0: - param_binds = {} - for param in circuit.parameters: - param_binds[param] = np.random.random() - circuit = circuit.bind_parameters(param_binds) - - simulator = self.simulators[runtime] - shots = measure_count if measure == self.MEASUREMENT_SAMPLING else 1 - - if (simulator, app, measure, measure_count, qubit) not in QOBJS: - QOBJS[(runtime, app, measure, measure_count, qubit, noise_name)] = simulator._assemble(transpile(circuit, simulator), shots=shots, noise_model=noise_model, enable_truncation=False) - return QOBJS[(runtime, app, measure, measure_count, qubit, noise_name)] - - def _run(self, runtime, app, measure, measure_count, noise_name, qubit): - simulator = self.simulators[runtime] - - if qubit not in self.backend_qubits[runtime]: - raise ValueError('out of qubit range: qubit={0}, list={1}'.format(qubit, self.backend_qubits[runtime])) - - qobj = self.gen_qobj(runtime, app, measure, measure_count, qubit, noise_name) - if qobj is None: - raise ValueError('no qobj: measure={0}:{1}, qubit={2}'.format(measure, measure_count, qubit)) - - start = time() - result = simulator._run(qobj) - if result.status != 'COMPLETED': - try: - reason = None - ret_dict = result.to_dict() - if 'results' in ret_dict: - if len (ret_dict['results']) > 0 and 'status' in ret_dict['results'][0]: - reason = ret_dict['results'][0]['status'] - if reason is None and 'status' in ret_dict: - reason = ret_dict['status'] - if reason is None: - reason = 'unknown' - except: - reason = 'unknown' - raise ValueError('simulation error ({0})'.format(reason)) - return time() - start - - def run_manual(self): - import timeout_decorator - @timeout_decorator.timeout(self.timeout) - def run_with_timeout (suite, runtime, app, measure, measure_count, noise_name, qubit): - start = time() - return eval('suite.track_{0}'.format(runtime))(app, measure, measure_count, noise_name, qubit) - - #for runtime in self.runtime_names: - for noise_name in self.noise_model_names: - for runtime in self.runtime_names: - for app in self.apps: - repeats = None if app not in self.app2rep else self.app2rep[app] - app_name = app if repeats is None else '{0}:{1}'.format(app, repeats) - for qubit in self.qubits: - for measure in self.measures: - for measure_count in self.measure_counts: - print ('{0},{1},{2},{3},{4},{5},{6},'.format(self.__name__, app_name, runtime, measure, measure_count, noise_name, qubit), end="") - try: - elapsed = run_with_timeout(self, runtime, app, measure, measure_count, noise_name, qubit) - print ('{0}'.format(elapsed)) - except ValueError as e: - print ('{0}'.format(e)) - except: - import traceback - traceback.print_exc(file=sys.stderr) - print ('unknown error') diff --git a/test/benchmark/statevector_cpu.py b/test/benchmark/statevector_cpu.py new file mode 100644 index 0000000000..4ed7f7ba54 --- /dev/null +++ b/test/benchmark/statevector_cpu.py @@ -0,0 +1,46 @@ +# This code is part of Qiskit. +# +# (C) Copyright IBM 2018, 2019, 2020, 2021, 2022. +# +# This code is licensed under the Apache License, Version 2.0. You may +# obtain a copy of this license in the LICENSE.txt file in the root directory +# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. +# +# Any modifications or derivative works of this code must retain this +# copyright notice, and modified files need to carry a notice indicating +# that they have been altered from the originals. +from .default_simulator import Benchmark as BaseBanchmark +from .default_simulator import ExpVal as BaseExpVal +from .default_simulator import Noise as BaseNoise + + +class StatevectorCPU: + + def simulator(self): + if self._simulator: + return self._simulator + try: + from qiskit.providers.aer import AerSimulator + self._simulator = AerSimulator(method='statevector', device='CPU') + except: + from qiskit.providers.aer import QasmSimulator + self._simulator = QasmSimulator(method='statevector') + return self._simulator + + +class Benchmark(StatevectorCPU, BaseBanchmark): + + def __init__(self): + super().__init__([5, 15, 25]) + + +class ExpVal(StatevectorCPU, BaseExpVal): + + def __init__(self): + super().__init__([5, 15, 25]) + + +class Noise(StatevectorCPU, BaseNoise): + + def __init__(self): + super().__init__([5, 15]) diff --git a/test/benchmark/statevector_gpu.py b/test/benchmark/statevector_gpu.py new file mode 100644 index 0000000000..df358de20d --- /dev/null +++ b/test/benchmark/statevector_gpu.py @@ -0,0 +1,46 @@ +# This code is part of Qiskit. +# +# (C) Copyright IBM 2018, 2019, 2020, 2021, 2022. +# +# This code is licensed under the Apache License, Version 2.0. You may +# obtain a copy of this license in the LICENSE.txt file in the root directory +# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. +# +# Any modifications or derivative works of this code must retain this +# copyright notice, and modified files need to carry a notice indicating +# that they have been altered from the originals. +from .default_simulator import Benchmark as BaseBanchmark +from .default_simulator import ExpVal as BaseExpVal +from .default_simulator import Noise as BaseNoise + + +class StatevectorGPU: + + def simulator(self): + if self._simulator: + return self._simulator + try: + from qiskit.providers.aer import AerSimulator + self._simulator = AerSimulator(method='statevector', device='GPU') + except: + from qiskit.providers.aer import QasmSimulator + self._simulator = QasmSimulator(method='statevector_gpu') + return self._simulator + + +class Benchmark(StatevectorGPU, BaseBanchmark): + + def __init__(self): + super().__init__([5, 15, 25]) + + +class ExpVal(StatevectorGPU, BaseExpVal): + + def __init__(self): + super().__init__([5, 15, 25]) + + +class Noise(StatevectorGPU, BaseNoise): + + def __init__(self): + super().__init__([5, 15]) diff --git a/test/benchmark/unitary_cpu.py b/test/benchmark/unitary_cpu.py new file mode 100644 index 0000000000..ae6f8065dd --- /dev/null +++ b/test/benchmark/unitary_cpu.py @@ -0,0 +1,39 @@ +# This code is part of Qiskit. +# +# (C) Copyright IBM 2018, 2019, 2020, 2021, 2022. +# +# This code is licensed under the Apache License, Version 2.0. You may +# obtain a copy of this license in the LICENSE.txt file in the root directory +# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. +# +# Any modifications or derivative works of this code must retain this +# copyright notice, and modified files need to carry a notice indicating +# that they have been altered from the originals. +from .default_simulator import Benchmark as BaseBanchmark + + + + +class UnitaryCPU: + + def simulator(self): + if self._simulator: + return self._simulator + try: + from qiskit.providers.aer import AerSimulator + self._simulator = AerSimulator(method='unitary', device='CPU') + except: + from qiskit.providers.aer import UnitarySimulator + self._simulator = UnitarySimulator(method='unitary') + return self._simulator + + +class Benchmark(UnitaryCPU, BaseBanchmark): + + def __init__(self): + super().__init__([5, 13]) + + def add_measure(self, circuit): + """append measurement""" + if self.simulator().__class__.__name__ != 'UnitarySimulator': + circuit.save_state() diff --git a/test/benchmark/vqe_application.py b/test/benchmark/vqe_application.py deleted file mode 100644 index 1f06f1411f..0000000000 --- a/test/benchmark/vqe_application.py +++ /dev/null @@ -1,109 +0,0 @@ -# This code is part of Qiskit. -# -# (C) Copyright IBM 2018, 2019, 2020. -# -# This code is licensed under the Apache License, Version 2.0. You may -# obtain a copy of this license in the LICENSE.txt file in the root directory -# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. -# -# Any modifications or derivative works of this code must retain this -# copyright notice, and modified files need to carry a notice indicating -# that they have been altered from the originals. -""" -Base class of Qiskit Aer Benchmarking -""" -import sys -import numpy as np -import multiprocessing -from time import time - -class UCCSDBenchmarkSuite: - - def __init__(self, - name = 'uccsd_benchmark'): - - self.mol_strings = { - 'H2': ('H .0 .0 .0; H .0 .0 0.735', 2), # qubits: 2 - 'LiH': ('H .0 .0 .0; Li .0 .0 2.5', 10), # qubits: 10 - 'HF': ('H .0 .0 .0; F .0 .0 1.25', 10), # qubits: 10 - } - - self.timeout = 60 * 60 - self.__name__ = name - self.params = ([mol_name for mol_name in self.mol_strings]) - self.param_names = ["mol"] - - def _run_uccsd_vqe(self, mol_string, method, simulator, threads): - - from qiskit_nature.circuit.library import HartreeFock, UCCSD - from qiskit_nature.converters.second_quantization import QubitConverter - from qiskit_nature.drivers import UnitsType, Molecule - from qiskit_nature.drivers.second_quantization.pyscfd import PySCFDriver - from qiskit_nature.mappers.second_quantization import JordanWignerMapper, ParityMapper - from qiskit_nature.problems.second_quantization import ElectronicStructureProblem - - driver = PySCFDriver(atom=mol_string, unit=UnitsType.ANGSTROM, basis='sto3g') - es_problem = ElectronicStructureProblem(driver) - qubit_converter = QubitConverter(JordanWignerMapper()) - max_evals_grouped = 1024 - - from qiskit.algorithms.optimizers import SLSQP - optimizer = SLSQP(maxiter=5000) - - from qiskit.utils import QuantumInstance - - quantum_instance = QuantumInstance(backend=simulator) - - from qiskit_nature.algorithms import VQEUCCFactory - - vqe_solver = VQEUCCFactory(quantum_instance, - optimizer=optimizer, - include_custom=True, - max_evals_grouped=max_evals_grouped) - - from qiskit_nature.algorithms import GroundStateEigensolver - - calc = GroundStateEigensolver(qubit_converter, vqe_solver) - - res = calc.solve(es_problem) - - def time_statevector(self, mol_name): - from qiskit.providers.aer import AerSimulator - threads = multiprocessing.cpu_count() - mol_string = self.mol_strings[mol_name][0] - qubit = self.mol_strings[mol_name][1] - self._run_uccsd_vqe(mol_string, 'statevector_cpu', AerSimulator(device='CPU'), threads) - - def time_statevector_gpu(self, mol_name): - from qiskit.providers.aer import AerSimulator - threads = 1 - mol_string = self.mol_strings[mol_name][0] - qubit = self.mol_strings[mol_name][1] - self._run_uccsd_vqe(mol_string, 'statevector_gpu', AerSimulator(device='GPU'), threads) - - def run_manual(self): - import timeout_decorator - @timeout_decorator.timeout(self.timeout) - def run_with_timeout (suite, method, molstring): - start = time() - eval(f'suite.time_{method}("{molstring}")') - return time() - start - - #for runtime in self.runtime_names: - for method in [ 'statevector' ]: - for mol_string in self.mol_strings: - print (f'{self.__name__},uccsd,{method},{mol_string},', end="") - try: - elapsed = run_with_timeout(self, method, mol_string) - print ('{0}'.format(elapsed)) - except ValueError as e: - print ('{0}'.format(e)) - except: - import traceback - traceback.print_exc(file=sys.stderr) - print ('unknown error') - -if __name__ == "__main__": - benchmarks = [ UCCSDBenchmarkSuite() ] - for benchmark in benchmarks: - benchmark.run_manual()