Skip to content

Commit

Permalink
🔥 removed all benchmarks relying on qiskit_optimization, qiskit_natur…
Browse files Browse the repository at this point in the history
…e, and qiskit_algorithm dependencies
  • Loading branch information
nquetschlich committed Nov 27, 2024
1 parent b9327a0 commit 394c524
Show file tree
Hide file tree
Showing 18 changed files with 41 additions and 777 deletions.
3 changes: 0 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,6 @@ repos:
args: []
additional_dependencies:
- pytket_qiskit
- qiskit_optimization
- qiskit_nature
- qiskit_finance
- importlib_resources
- pytest
- types-setuptools
Expand Down
3 changes: 0 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ dependencies = [
# there is a bug in 1.2.0 that causes an error some benchmarks, see https://github.com/Qiskit/qiskit/issues/12969
"qiskit!=1.2.0",
"qiskit_qasm3_import>=0.5.0",
"qiskit_optimization>=0.6",
"qiskit_nature[pyscf]>=0.7",
"qiskit_finance>=0.4.1",
"networkx>=2.8.8",
"joblib>=1.3.0",
"numpy>=1.26; python_version >= '3.12'",
Expand Down
18 changes: 3 additions & 15 deletions src/mqt/bench/benchmark_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,15 +128,6 @@ def define_benchmark_instances(self, benchmark: Benchmark) -> None:
elif benchmark["name"] == "shor":
instances = [lib.get_instance(choice) for choice in benchmark["instances"]]

elif benchmark["name"] in ("routing", "tsp"):
instances = range(benchmark["min_nodes"], benchmark["max_nodes"])

elif benchmark["name"] == "groundstate":
instances = benchmark["instances"]

elif benchmark["name"] in ("pricingcall", "pricingput"):
instances = range(benchmark["min_uncertainty"], benchmark["max_uncertainty"])

else:
instances = range(
benchmark["min_qubits"],
Expand Down Expand Up @@ -344,7 +335,7 @@ def get_benchmark(
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"
benchmark_instance_name: Input selection for some benchmarks, namely and "shor"
compiler: "qiskit" or "tket"
compiler_settings: Data class containing the respective compiler settings for the specified compiler (e.g., optimization level for Qiskit)
gateset: Name of the gateset or tuple containing the name of the gateset and the gateset itself (required for "nativegates" level)
Expand All @@ -362,11 +353,11 @@ def get_benchmark(
msg = f"Selected level must be in {get_supported_levels()}."
raise ValueError(msg)

if benchmark_name not in ["shor", "groundstate"] and not (isinstance(circuit_size, int) and circuit_size > 0):
if benchmark_name != "shor" and not (isinstance(circuit_size, int) and circuit_size > 0):
msg = "circuit_size must be None or int for this benchmark."
raise ValueError(msg)

if benchmark_name in ["shor", "groundstate"] and not isinstance(benchmark_instance_name, str):
if benchmark_name == "shor" and not isinstance(benchmark_instance_name, str):
msg = "benchmark_instance_name must be defined for this benchmark."
raise ValueError(msg)

Expand All @@ -386,9 +377,6 @@ def get_benchmark(
to_be_factored_number, a_value = lib.get_instance(benchmark_instance_name)
qc = lib.create_circuit(to_be_factored_number, a_value)

elif benchmark_name == "groundstate":
qc = lib.create_circuit(benchmark_instance_name)

else:
qc = lib.create_circuit(circuit_size)

Expand Down
15 changes: 0 additions & 15 deletions src/mqt/bench/benchmarks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,8 @@

from __future__ import annotations

from mqt.bench.benchmarks.qiskit_application_finance import (
portfolioqaoa,
portfoliovqe,
pricingcall,
pricingput,
)
from mqt.bench.benchmarks.qiskit_application_ml import qnn
from mqt.bench.benchmarks.qiskit_application_nature import groundstate
from mqt.bench.benchmarks.qiskit_application_optimization import routing, tsp

__all__ = [
"groundstate",
"portfolioqaoa",
"portfoliovqe",
"pricingcall",
"pricingput",
"qnn",
"routing",
"tsp",
]
57 changes: 36 additions & 21 deletions src/mqt/bench/benchmarks/qaoa.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,49 @@

from __future__ import annotations

from typing import TYPE_CHECKING
import numpy as np
from qiskit import QuantumCircuit

from qiskit.primitives import Sampler
from qiskit_algorithms.minimum_eigensolvers import QAOA
from qiskit_algorithms.optimizers import SLSQP
from qiskit_optimization import QuadraticProgram

from mqt.bench.utils import get_examplary_max_cut_qp

if TYPE_CHECKING: # pragma: no cover
from qiskit import QuantumCircuit


def create_circuit(num_qubits: int) -> QuantumCircuit:
"""Returns a quantum circuit implementing the Quantum Approximation Optimization Algorithm for a specific max-cut example.
def create_circuit(num_qubits: int, repetitions: int = 2, seed: int = 42) -> QuantumCircuit:
"""Constructs a quantum circuit implementing QAOA for a Max-Cut example with random parameters.
Arguments:
num_qubits: number of qubits of the returned quantum circuit
num_qubits: Number of qubits in the circuit (equal to the number of graph nodes).
repetitions: Number of QAOA layers (repetitions of the ansatz).
seed: Random seed for reproducibility.
Returns:
QuantumCircuit: quantum circuit implementing the Quantum Approximation Optimization Algorithm
QuantumCircuit: Quantum circuit implementing QAOA.
"""
qp = get_examplary_max_cut_qp(num_qubits)
assert isinstance(qp, QuadraticProgram)

qaoa = QAOA(sampler=Sampler(), reps=2, optimizer=SLSQP(maxiter=25))
qaoa_result = qaoa.compute_minimum_eigenvalue(qp.to_ising()[0])
qc = qaoa.ansatz.assign_parameters(qaoa_result.optimal_point)
# Set the random number generator
rng = np.random.default_rng(seed)

# Example adjacency matrix for Max-Cut (toy problem)
adjacency_matrix = rng.integers(0, 2, size=(num_qubits, num_qubits))
adjacency_matrix = np.triu(adjacency_matrix, 1) # Upper triangular part for undirected graph

# Random initialization of parameters
gamma_values = rng.uniform(0, np.pi, repetitions)
beta_values = rng.uniform(0, np.pi, repetitions)

# Initialize QAOA circuit
qc = QuantumCircuit(num_qubits)

# Start in uniform superposition
qc.h(range(num_qubits))

# Define cost and mixer operators for each layer
for layer in range(repetitions):
# Cost Hamiltonian
for i in range(num_qubits):
for j in range(i + 1, num_qubits):
if adjacency_matrix[i, j] != 0:
qc.rzz(2 * gamma_values[layer], i, j)

# Mixer Hamiltonian
for i in range(num_qubits):
qc.rx(2 * beta_values[layer], i)

qc.name = "qaoa"

Expand Down

This file was deleted.

This file was deleted.

67 changes: 0 additions & 67 deletions src/mqt/bench/benchmarks/qiskit_application_finance/pricingcall.py

This file was deleted.

Loading

0 comments on commit 394c524

Please sign in to comment.