Skip to content

Commit 1d0ab48

Browse files
committed
Removing the dependencies 'qiskit_optimization' and 'qiskit_algorithms' by implementing QAOA to solve a QUBO problem. Additional fixes to support Qiskit >= 2.0.0.
1 parent 04abda5 commit 1d0ab48

9 files changed

Lines changed: 523 additions & 307 deletions

File tree

.pre-commit-config.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,5 @@ repos:
9090
- mqt.ddsim
9191
- pytest
9292
- pandas-stubs
93+
- scipy-stubs
94+
- mqt.core

pyproject.toml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,19 @@ requires-python = ">=3.8"
1919
dynamic = ["version"]
2020

2121
dependencies = [
22-
"qiskit>=0.36.0,<0.42.0",
22+
"qiskit>=2.0.0",
2323
"joblib",
2424
"numpy",
2525
"matplotlib",
26-
"mqt.ddsim",
26+
"mqt.core",
2727
"networkx",
2828
"python_tsp",
2929
"docplex",
30-
"qiskit_optimization",
30+
"qubovert",
3131
"qiskit_aer",
32-
"pandas"
32+
"qiskit_ibm_runtime",
33+
"pandas",
34+
"scipy"
3335
]
3436

3537
classifiers = [

src/mqt/problemsolver/csp.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
from typing import TYPE_CHECKING, TypedDict
44

55
import numpy as np
6-
from qiskit import QuantumCircuit, QuantumRegister, execute
6+
from qiskit import QuantumCircuit, QuantumRegister, qasm3
77

8-
from mqt.ddsim import DDSIMProvider
8+
import mqt.core
9+
from mqt.core.dd import sample
910

1011
if TYPE_CHECKING:
1112
from qiskit.circuit import Instruction
@@ -223,7 +224,7 @@ def create_oracle(
223224
compute = qc.to_instruction()
224225

225226
# mark solution
226-
qc.mct(mct_list, flag, ancilla_qubits=anc_mct, mode="v-chain")
227+
qc.mcx(mct_list, flag, ancilla_qubits=anc_mct, mode="v-chain")
227228

228229
# uncompute
229230
uncompute = compute.inverse()
@@ -309,9 +310,10 @@ def create_grover(
309310
return qc
310311

311312
def simulate(self, qc: QuantumCircuit) -> tuple[int, int, int, int] | None:
312-
backend = DDSIMProvider().get_backend("qasm_simulator")
313-
job = execute(qc, backend, shots=10000)
314-
counts = job.result().get_counts(qc)
313+
qc = qc.decompose()
314+
qasm_string = qasm3.dumps(qc)
315+
quantum_computation = mqt.core.ir.QuantumComputation().from_qasm_str(qasm_string)
316+
counts = sample(quantum_computation, shots=10000)
315317

316318
mean_counts = np.mean(list(counts.values()))
317319

0 commit comments

Comments
 (0)