Skip to content

Commit

Permalink
Dev (#144)
Browse files Browse the repository at this point in the history
* Update dependencies (#137)

* 📦 support versioning in git

* ✨updated groundstate benchmark

* ✨updated vqe benchmarks

* ✨updated vqe benchmarks

* ✨updated vqe benchmarks

* ✨updated qaoa benchmarks

* ✨updated dependency requirements

* ✨put very long test case in comment

* 🚨

* 🚨 commented out unused imports

* 🙈 added gitignore to make sure the folder exists

* ✅ added tests for hhl and shor for the indep level and fixed unnecessary conversion

* 🎨 removed unnecessary comments

* 📦 loosened dependencies

* 📦 loosened dependencies

* Fix oqc qasm (#138)

* ✨ adjusted the OQC adjustment and added it immediately after the qasm file is saved

* ✨ removed the indepedent level because there will never be an ECR during that step

* 🎨 removed commented code

* 🎨 improved OQC qasm file postprocessing

* Imrove get one benchmark (#141)

* ✨ added error handling and deprecation warning for get_one_benchmark

* 🐛 fixed faulty tests

* ✨ set bool type for some of the pandas dataframe columns to reduce future warnings

* ✨ updated from rigetti m1 to m2

* 🐛 fixed typos

* 📌 simplified qiskit dependencies

* ✨ added get_benchmark method

* ✨ substituted aspen m1 with m2

* 🐛 adjusted tket fullpeephole optimization method call

* ✨ added method for get_benchmark in init

* ✨ adjusted timeout for benchmark calculation

* 🎨 removed assert statement

* 🐛 changed if statement such that also OQC files with a custom filename are postprocessed

* 🐛 changed oqc postprocessing such that the compiler information is not needed anymore

* 🐛 bugfixed the version stamp in qasm files

* ✅ added test for oqc postprocessing

* 🐛 fixed a bug in qiskit native gates with custom filename

* 💡 removed comment and commented out the zipping

* 🎨 removed the m2 identifier to show also m1 benchmarks which have the same connectivity

* 🎨 removed the m2 identifier to show also m1 benchmarks which have the same connectivity

* 📌 added pyscf dependency
  • Loading branch information
nquetschlich authored Dec 11, 2022
1 parent 7fce784 commit 86f81dd
Show file tree
Hide file tree
Showing 20 changed files with 384 additions and 303 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ So far, MQT Bench supports the following devices:

1. IBMQ Washington with 127 qubits
2. IBMQ Montreal with 27 qubits
3. Rigetti Aspen-M1 with 80 qubits
3. Rigetti Aspen-M2 with 80 qubits
4. IonQ with 11 qubits
5. OQC Lucy with 8 qubits

Expand Down
2 changes: 1 addition & 1 deletion config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"timeout": 1,
"timeout": 120,
"benchmarks": [
{
"name": "ae",
Expand Down
1 change: 1 addition & 0 deletions mqt/bench/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from mqt.bench.benchmark_generator import (
create_benchmarks_from_config,
get_benchmark,
get_one_benchmark,
)
102 changes: 96 additions & 6 deletions mqt/bench/benchmark_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import json
import signal
from os import mkdir, path
from warnings import warn

from joblib import Parallel, delayed
from qiskit import QuantumCircuit
Expand Down Expand Up @@ -269,7 +270,7 @@ def generate_target_dep_level_circuit(

compilation_paths = [
("ibm", [("ibm_washington", 127), ("ibm_montreal", 27)]),
("rigetti", [("rigetti_aspen_m1", 80)]),
("rigetti", [("rigetti_aspen_m2", 80)]),
("ionq", [("ionq11", 11)]),
("oqc", [("oqc_lucy", 8)]),
]
Expand Down Expand Up @@ -483,7 +484,7 @@ def get_one_benchmark(
gate_set_name: str = "ibm",
device_name: str = "ibm_washington",
):
"""Returns one benchmark as a Qiskit::QuantumCircuit Object.
"""Returns one benchmark as a Qiskit::QuantumCircuit Object. Deprecated method, please use 'get_benchmark' instead.
Keyword arguments:
benchmark_name -- name of the to be generated benchmark
Expand All @@ -493,13 +494,103 @@ def get_one_benchmark(
compiler -- "qiskit" or "tket"
compiler_settings -- Dictionary containing the respective compiler settings for the specified compiler (e.g., optimization level for Qiskit or placement for TKET)
gate_set_name -- "ibm", "rigetti", "ionq", or "oqc"
device_name -- "ibm_washington", "ibm_montreal", "aspen_m1", "ionq11", ""lucy""
device_name -- "ibm_washington", "ibm_montreal", "aspen_m2", "ionq11", ""lucy""
Return values:
Quantum Circuit Object -- Representing the benchmark with the selected options, either as Qiskit::QuantumCircuit or Pytket::Circuit object (depending on the chosen compiler---while the algorithm level is always provided using Qiskit)
"""

warn(
"'get_one_benchmark' is deprecated and will be removed in the future. Please use the 'get_benchmark' method with the same parameters.",
DeprecationWarning,
stacklevel=2,
)

return get_benchmark(
benchmark_name=benchmark_name,
level=level,
circuit_size=circuit_size,
benchmark_instance_name=benchmark_instance_name,
compiler=compiler,
compiler_settings=compiler_settings,
gate_set_name=gate_set_name,
device_name=device_name,
)


def get_benchmark(
benchmark_name: str,
level: str | int,
circuit_size: int = None,
benchmark_instance_name: str = None,
compiler: str = "qiskit",
compiler_settings: dict[str, dict[str, any]] = None,
gate_set_name: str = "ibm",
device_name: str = "ibm_washington",
):
"""Returns one benchmark as a Qiskit::QuantumCircuit Object.
Keyword arguments:
benchmark_name -- name of the to be generated benchmark
level -- Choice of level, either as a string ("alg", "indep", "nativegates" or "mapped") or as a number between 0-3 where 0 corresponds to "alg" level and 3 to "mapped" level
circuit_size -- Input for the benchmark creation, in most cases this is equal to the qubit number
benchmark_instance_name -- Input selection for some benchmarks, namely "groundstate" and "shor"
compiler -- "qiskit" or "tket"
compiler_settings -- Dictionary containing the respective compiler settings for the specified compiler (e.g., optimization level for Qiskit or placement for TKET)
gate_set_name -- "ibm", "rigetti", "ionq", or "oqc"
device_name -- "ibm_washington", "ibm_montreal", "rigetti_aspen_m2", "ionq11", ""oqc_lucy""
Return values:
Quantum Circuit Object -- Representing the benchmark with the selected options, either as Qiskit::QuantumCircuit or Pytket::Circuit object (depending on the chosen compiler---while the algorithm level is always provided using Qiskit)
"""

init_module_paths()

if benchmark_name not in utils.get_supported_benchmarks():
raise ValueError(
f"Selected benchmark is not supported. Valid benchmarks are {utils.get_supported_benchmarks()}."
)

if level not in utils.get_supported_levels():
raise ValueError(f"Selected level must be in {utils.get_supported_levels()}.")

if benchmark_name not in ["shor", "groundstate"] and not isinstance(
circuit_size, int
):
raise ValueError("circuit_size must be None or int for this benchmark.")
elif benchmark_name in ["shor", "groundstate"] and not isinstance(
benchmark_instance_name, str
):
raise ValueError("benchmark_instance_name must be defined for this benchmark.")

if benchmark_instance_name is not None and not isinstance(
benchmark_instance_name, str
):
raise ValueError("Selected benchmark_instance_name must be None or str.")

if compiler is not None and compiler.lower() not in utils.get_supported_compilers():
raise ValueError(
f"Selected compiler must be in {utils.get_supported_compilers()}."
)

if compiler_settings is not None and not isinstance(compiler_settings, dict):
raise ValueError(
"Selected compiler_settings must be None or 'dict[str, dict[str, any]]'."
)

if (
gate_set_name is not None
and gate_set_name not in utils.get_supported_gatesets()
):
raise ValueError(
f"Selected gate_set_name must be None or in {utils.get_supported_gatesets()}."
)

if device_name is not None and device_name not in utils.get_supported_devices():
raise ValueError(
f"Selected device_name must be None or in {utils.get_supported_devices()}."
)

if "grover" in benchmark_name or "qwalk" in benchmark_name:
if "noancilla" in benchmark_name:
anc_mode = "noancilla"
Expand Down Expand Up @@ -551,6 +642,7 @@ def get_one_benchmark(
"tket": {"placement": "lineplacement"},
}

compiler = compiler.lower()
if level == "alg" or level == 0:
return qc

Expand Down Expand Up @@ -617,9 +709,7 @@ def get_one_benchmark(
args = parser.parse_args()

print("#### Start generating")
# create_benchmarks_from_config(args.file_name)
print("#### Start preprocessing")
utils.postprocess_oqc_qasm_files()
create_benchmarks_from_config(args.file_name)
print("#### Start zipping")
# utils.create_zip_file()
print("#### Generation ended")
10 changes: 3 additions & 7 deletions mqt/bench/benchmarks/qaoa.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@

from __future__ import annotations

from qiskit import Aer
from qiskit.algorithms import QAOA
from qiskit.algorithms.minimum_eigensolvers import QAOA
from qiskit.algorithms.optimizers import SLSQP
from qiskit.utils import QuantumInstance
from qiskit.primitives import Sampler

from mqt.bench.utils.utils import get_examplary_max_cut_qp

Expand All @@ -19,11 +18,8 @@ def create_circuit(num_qubits: int):
"""

qp = get_examplary_max_cut_qp(num_qubits)
sim = QuantumInstance(
backend=Aer.get_backend("aer_simulator"), shots=1024, seed_simulator=10
)

qaoa = QAOA(reps=2, optimizer=SLSQP(maxiter=25), quantum_instance=sim)
qaoa = QAOA(sampler=Sampler(), reps=2, optimizer=SLSQP(maxiter=25))
qaoa_result = qaoa.compute_minimum_eigenvalue(qp.to_ising()[0])
qc = qaoa.ansatz.bind_parameters(qaoa_result.optimal_point)

Expand Down
16 changes: 4 additions & 12 deletions mqt/bench/benchmarks/qiskit_application_finance/portfolioqaoa.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@

import datetime

from qiskit import Aer
from qiskit.algorithms import QAOA
from qiskit.algorithms.minimum_eigensolvers import QAOA
from qiskit.algorithms.optimizers import COBYLA
from qiskit.utils import QuantumInstance
from qiskit.primitives import Sampler
from qiskit_finance.applications import PortfolioOptimization
from qiskit_finance.data_providers import RandomDataProvider
from qiskit_optimization.converters import QuadraticProgramToQubo
Expand Down Expand Up @@ -44,18 +43,11 @@ def create_circuit(num_qubits: int):
conv = QuadraticProgramToQubo()
qp_qubo = conv.convert(qp)

backend = Aer.get_backend("aer_simulator")
seed = 10

cobyla = COBYLA()
cobyla.set_options(maxiter=25)

sim = QuantumInstance(
backend=backend, seed_simulator=seed, seed_transpiler=seed, shots=1024
)

qaoa = QAOA(cobyla, 3, quantum_instance=sim)
qaoa.random_seed = seed
qaoa = QAOA(sampler=Sampler(), optimizer=cobyla, reps=3)
qaoa.random_seed = 10
qaoa_result = qaoa.compute_minimum_eigenvalue(qp_qubo.to_ising()[0])
qc = qaoa.ansatz.bind_parameters(qaoa_result.optimal_point)

Expand Down
16 changes: 4 additions & 12 deletions mqt/bench/benchmarks/qiskit_application_finance/portfoliovqe.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@

import datetime

from qiskit import Aer
from qiskit.algorithms import VQE
from qiskit.algorithms.minimum_eigensolvers import VQE
from qiskit.algorithms.optimizers import COBYLA
from qiskit.circuit.library import TwoLocal
from qiskit.utils import QuantumInstance
from qiskit.primitives import Estimator
from qiskit_finance.applications import PortfolioOptimization
from qiskit_finance.data_providers import RandomDataProvider
from qiskit_optimization.converters import QuadraticProgramToQubo
Expand Down Expand Up @@ -44,19 +43,12 @@ def create_circuit(num_qubits: int):
qp = portfolio.to_quadratic_program()
conv = QuadraticProgramToQubo()
qp_qubo = conv.convert(qp)

backend = Aer.get_backend("aer_simulator")
seed = 10

cobyla = COBYLA()
cobyla.set_options(maxiter=25)
ry = TwoLocal(num_assets, "ry", "cz", reps=3, entanglement="full")
sim = QuantumInstance(
backend=backend, seed_simulator=seed, seed_transpiler=seed, shots=1024
)

vqe = VQE(ry, optimizer=cobyla, quantum_instance=sim)
vqe.random_seed = seed
vqe = VQE(ansatz=ry, optimizer=cobyla, estimator=Estimator())
vqe.random_seed = 10
vqe_result = vqe.compute_minimum_eigenvalue(qp_qubo.to_ising()[0])
qc = vqe.ansatz.bind_parameters(vqe_result.optimal_point)

Expand Down
30 changes: 10 additions & 20 deletions mqt/bench/benchmarks/qiskit_application_nature/groundstate.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,27 @@

from __future__ import annotations

from qiskit import Aer
from qiskit.algorithms import VQE
from qiskit.algorithms.minimum_eigensolvers import VQE
from qiskit.algorithms.optimizers import COBYLA
from qiskit.circuit.library import TwoLocal
from qiskit.utils import QuantumInstance
from qiskit_nature.converters.second_quantization import QubitConverter
from qiskit_nature.drivers.second_quantization import (
ElectronicStructureDriverType,
ElectronicStructureMoleculeDriver,
)
from qiskit_nature.mappers.second_quantization import JordanWignerMapper
from qiskit_nature.problems.second_quantization import ElectronicStructureProblem
from qiskit.primitives import Estimator
from qiskit_nature.second_q.drivers import PySCFDriver
from qiskit_nature.second_q.mappers import JordanWignerMapper, QubitConverter


def create_circuit(molecule, basis: str = "sto3g"):
def create_circuit(molecule):
"""Returns a quantum circuit implementing Ground State Estimation.
Keyword arguments:
molecule -- Molecule for which the ground state shall be estimated.
"""

driver = ElectronicStructureMoleculeDriver(
molecule, basis=basis, driver_type=ElectronicStructureDriverType.PYSCF
)
driver = PySCFDriver(atom=molecule)
es_problem = driver.run()

es_problem = ElectronicStructureProblem(driver)
qubit_converter = QubitConverter(JordanWignerMapper())
converter = QubitConverter(JordanWignerMapper())
second_q_op = es_problem.second_q_ops()
operator = qubit_converter.convert_only(second_q_op[0])
operator = converter.convert_only(second_q_op[0])

tl_circuit = TwoLocal(
rotation_blocks=["h", "rx"],
Expand All @@ -42,9 +34,7 @@ def create_circuit(molecule, basis: str = "sto3g"):
)

another_solver = VQE(
ansatz=tl_circuit,
quantum_instance=QuantumInstance(Aer.get_backend("aer_simulator"), shots=1024),
optimizer=COBYLA(maxiter=25),
ansatz=tl_circuit, estimator=Estimator(), optimizer=COBYLA(maxiter=25)
)

result = another_solver.compute_minimum_eigenvalue(operator)
Expand Down
Loading

0 comments on commit 86f81dd

Please sign in to comment.