Skip to content

Commit

Permalink
✨ Support of Qiskit v1.0.0 (#306)
Browse files Browse the repository at this point in the history
Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after
your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge
and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating
it. You can achieve the same result by closing it manually
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore <dependency name> major version` will close this
group update PR and stop Dependabot creating any more for the specific
dependency's major version (unless you unignore this specific
dependency's major version or upgrade to it yourself)
- `@dependabot ignore <dependency name> minor version` will close this
group update PR and stop Dependabot creating any more for the specific
dependency's minor version (unless you unignore this specific
dependency's minor version or upgrade to it yourself)
- `@dependabot ignore <dependency name>` will close this group update PR
and stop Dependabot creating any more for the specific dependency
(unless you unignore this specific dependency or upgrade to it yourself)
- `@dependabot unignore <dependency name>` will remove all of the ignore
conditions of the specified dependency
- `@dependabot unignore <dependency name> <ignore condition>` will
remove the ignore condition of the specified dependency and ignore
conditions


</details>

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Nils Quetschlich <[email protected]>
  • Loading branch information
dependabot[bot] and nquetschlich authored Mar 15, 2024
1 parent 43bcdad commit 1ff0512
Show file tree
Hide file tree
Showing 21 changed files with 48 additions and 48 deletions.
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ description = "MQT Bench - A MQT tool for Benchmarking Quantum Software Tools"
readme = "README.md"
authors = [
{ name = "Nils Quetschlich", email = "[email protected]" },
{ name = "Lukas Burgholzer", email = "lukas.burgholzer@jku.at"},
{ name = "Lukas Burgholzer", email = "lukas.burgholzer@tum.de"},
]
keywords = ["MQT", "quantum computing", "benchmarking", "performance", "testing"]
license = { file = "LICENSE" }
requires-python = ">=3.10"
dynamic = ["version"]

dependencies = [
"pytket-qiskit>=0.48.0,<0.49.0", # manages the dependencies for qiskit and tket in a combined fashion
"pytket-qiskit>=0.50.0,<0.51.0", # manages the dependencies for qiskit and tket in a combined fashion
"qiskit_optimization",
"qiskit_nature",
"qiskit_finance",
Expand Down Expand Up @@ -119,7 +119,7 @@ module = ["pytket.*", "qiskit_finance.*"]
implicit_reexport = true

[[tool.mypy.overrides]]
module = ["qiskit.*", "qiskit_finance.*", "joblib.*", "networkx.*", "pandas.*"]
module = ["qiskit.*", "qiskit_finance.*", "joblib.*", "networkx.*", "pandas.*", "qiskit_algorithms.*", "qiskit_ibm_runtime.*"]
ignore_missing_imports = true

[tool.ruff]
Expand Down
2 changes: 1 addition & 1 deletion src/mqt/bench/benchmarks/ae.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import numpy as np
from qiskit import QuantumCircuit
from qiskit.algorithms import AmplitudeEstimation, EstimationProblem
from qiskit_algorithms import AmplitudeEstimation, EstimationProblem


def create_circuit(num_qubits: int) -> QuantumCircuit:
Expand Down
2 changes: 1 addition & 1 deletion src/mqt/bench/benchmarks/grover.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import numpy as np
from qiskit import AncillaRegister, QuantumCircuit, QuantumRegister
from qiskit.algorithms import Grover
from qiskit.circuit.library import GroverOperator
from qiskit_algorithms import Grover


def create_circuit(num_qubits: int, ancillary_mode: str = "noancilla") -> QuantumCircuit:
Expand Down
6 changes: 3 additions & 3 deletions src/mqt/bench/benchmarks/qaoa.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

from typing import TYPE_CHECKING

from qiskit.algorithms.minimum_eigensolvers import QAOA
from qiskit.algorithms.optimizers import SLSQP
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
Expand All @@ -28,7 +28,7 @@ def create_circuit(num_qubits: int) -> QuantumCircuit:

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)
qc = qaoa.ansatz.assign_parameters(qaoa_result.optimal_point)

qc.name = "qaoa"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
import datetime
from typing import TYPE_CHECKING

from qiskit.algorithms.minimum_eigensolvers import QAOA
from qiskit.algorithms.optimizers import COBYLA
from qiskit.primitives import Sampler
from qiskit_algorithms.minimum_eigensolvers import QAOA
from qiskit_algorithms.optimizers import COBYLA
from qiskit_finance.applications import PortfolioOptimization
from qiskit_finance.data_providers import RandomDataProvider
from qiskit_optimization.converters import QuadraticProgramToQubo
Expand Down Expand Up @@ -51,7 +51,7 @@ def create_circuit(num_qubits: int) -> QuantumCircuit:
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)
qc = qaoa.ansatz.assign_parameters(qaoa_result.optimal_point)

qc.name = "portfolioqaoa"
qc.measure_all()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
import datetime
from typing import TYPE_CHECKING

from qiskit.algorithms.minimum_eigensolvers import VQE
from qiskit.algorithms.optimizers import COBYLA
from qiskit.circuit.library import TwoLocal
from qiskit.primitives import Estimator
from qiskit_algorithms.minimum_eigensolvers import VQE
from qiskit_algorithms.optimizers import COBYLA
from qiskit_finance.applications import PortfolioOptimization
from qiskit_finance.data_providers import RandomDataProvider
from qiskit_optimization.converters import QuadraticProgramToQubo
Expand Down Expand Up @@ -52,7 +52,7 @@ def create_circuit(num_qubits: int) -> QuantumCircuit:
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)
qc = vqe.ansatz.assign_parameters(vqe_result.optimal_point)

qc.name = "portfoliovqe"
qc.measure_all()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from typing import TYPE_CHECKING

import numpy as np
from qiskit.algorithms import IterativeAmplitudeEstimation
from qiskit_algorithms import IterativeAmplitudeEstimation
from qiskit_finance.applications.estimation import EuropeanCallPricing
from qiskit_finance.circuit.library import LogNormalDistribution

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
from typing import TYPE_CHECKING

import numpy as np
from qiskit.algorithms import EstimationProblem, IterativeAmplitudeEstimation
from qiskit.circuit.library import LinearAmplitudeFunction
from qiskit_algorithms import EstimationProblem, IterativeAmplitudeEstimation
from qiskit_finance.circuit.library import LogNormalDistribution

if TYPE_CHECKING: # pragma: no cover
Expand Down
4 changes: 2 additions & 2 deletions src/mqt/bench/benchmarks/qiskit_application_ml/qnn.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ def create_circuit(num_qubits: int) -> QuantumCircuit:
ansatz = RealAmplitudes(num_qubits=num_qubits, reps=1)

qc = QuantumCircuit(num_qubits)
feature_map = feature_map.bind_parameters([1 for _ in range(feature_map.num_parameters)])
ansatz = ansatz.bind_parameters(np.random.rand(ansatz.num_parameters))
feature_map = feature_map.assign_parameters([1 for _ in range(feature_map.num_parameters)])
ansatz = ansatz.assign_parameters(np.random.rand(ansatz.num_parameters))
qc.compose(feature_map, inplace=True)
qc.compose(ansatz, inplace=True)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@

from typing import TYPE_CHECKING

from qiskit.algorithms.minimum_eigensolvers import VQE
from qiskit.algorithms.optimizers import COBYLA
from qiskit.circuit.library import TwoLocal
from qiskit.primitives import Estimator
from qiskit_algorithms.minimum_eigensolvers import VQE
from qiskit_algorithms.optimizers import COBYLA
from qiskit_nature.second_q.drivers import PySCFDriver
from qiskit_nature.second_q.mappers import JordanWignerMapper

Expand Down Expand Up @@ -41,7 +41,7 @@ def create_circuit(choice: str) -> QuantumCircuit:
another_solver = VQE(ansatz=tl_circuit, estimator=Estimator(), optimizer=COBYLA(maxiter=25))

result = another_solver.compute_minimum_eigenvalue(operator)
qc = another_solver.ansatz.bind_parameters(result.optimal_point)
qc = another_solver.ansatz.assign_parameters(result.optimal_point)

qc.name = "groundstate"
qc.name = qc.name + "_" + choice
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
from typing import TYPE_CHECKING, cast

import numpy as np
from qiskit.algorithms.minimum_eigensolvers import VQE
from qiskit.algorithms.optimizers import SLSQP
from qiskit.circuit.library import RealAmplitudes
from qiskit.primitives import Estimator
from qiskit.utils import algorithm_globals
from qiskit_algorithms.minimum_eigensolvers import VQE
from qiskit_algorithms.optimizers import SLSQP
from qiskit_optimization import QuadraticProgram
from qiskit_optimization.problems import LinearExpression, QuadraticExpression

Expand Down Expand Up @@ -120,12 +119,11 @@ def construct_problem(self, Q: QuadraticExpression, g: LinearExpression, c: floa
return qp

def solve_problem(self, qp: QuadraticProgram) -> QuantumCircuit:
algorithm_globals.random_seed = 10

ansatz = RealAmplitudes(self.n)
vqe = VQE(estimator=Estimator(), optimizer=SLSQP(maxiter=25), ansatz=ansatz)
vqe.random_seed = 10
vqe_result = vqe.compute_minimum_eigenvalue(qp.to_ising()[0])
return vqe.ansatz.bind_parameters(vqe_result.optimal_point)
return vqe.ansatz.assign_parameters(vqe_result.optimal_point)


def create_circuit(num_nodes: int = 3, num_vehs: int = 2) -> QuantumCircuit:
Expand Down
10 changes: 4 additions & 6 deletions src/mqt/bench/benchmarks/qiskit_application_optimization/tsp.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@

from typing import TYPE_CHECKING

from qiskit.algorithms.minimum_eigensolvers import VQE
from qiskit.algorithms.optimizers import SPSA
from qiskit.circuit.library import TwoLocal
from qiskit.primitives import Estimator
from qiskit.utils import algorithm_globals
from qiskit_algorithms.minimum_eigensolvers import VQE
from qiskit_algorithms.optimizers import SPSA
from qiskit_optimization.applications import Tsp
from qiskit_optimization.converters import QuadraticProgramToQubo

Expand All @@ -33,14 +32,13 @@ def create_circuit(num_nodes: int) -> QuantumCircuit:
qubo = qp2qubo.convert(qp)
qubit_op, offset = qubo.to_ising()

algorithm_globals.random_seed = 10

spsa = SPSA(maxiter=25)
ry = TwoLocal(qubit_op.num_qubits, "ry", "cz", reps=5, entanglement="linear")
vqe = VQE(ansatz=ry, optimizer=spsa, estimator=Estimator())
vqe.random_seed = 10

vqe_result = vqe.compute_minimum_eigenvalue(qubit_op)
qc = vqe.ansatz.bind_parameters(vqe_result.optimal_point)
qc = vqe.ansatz.assign_parameters(vqe_result.optimal_point)
qc.measure_all()
qc.name = "tsp"

Expand Down
2 changes: 1 addition & 1 deletion src/mqt/bench/benchmarks/realamprandom.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def create_circuit(num_qubits: int) -> QuantumCircuit:
np.random.seed(10)
qc = RealAmplitudes(num_qubits, entanglement="full", reps=3)
num_params = qc.num_parameters
qc = qc.bind_parameters(2 * np.pi * np.random.rand(num_params))
qc = qc.assign_parameters(2 * np.pi * np.random.rand(num_params))
qc.measure_all()
qc.name = "realamprandom"

Expand Down
3 changes: 2 additions & 1 deletion src/mqt/bench/benchmarks/shor.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from qiskit import QuantumCircuit, QuantumRegister
from qiskit.circuit import Gate, Instruction, ParameterVector
from qiskit.circuit.library import QFT
from qiskit.utils.validation import validate_min
from qiskit_algorithms.utils.validation import validate_min


def create_circuit(num_to_be_factorized: int, a: int = 2) -> QuantumCircuit:
Expand Down Expand Up @@ -203,6 +203,7 @@ def _validate_input(N: int, a: int) -> None:
ValueError: Invalid input
"""

validate_min("N", N, 3)
validate_min("a", a, 2)

Expand Down
2 changes: 1 addition & 1 deletion src/mqt/bench/benchmarks/su2random.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def create_circuit(num_qubits: int) -> QuantumCircuit:
np.random.seed(10)
qc = EfficientSU2(num_qubits, entanglement="full", reps=3)
num_params = qc.num_parameters
qc = qc.bind_parameters(2 * np.pi * np.random.rand(num_params))
qc = qc.assign_parameters(2 * np.pi * np.random.rand(num_params))
qc.measure_all()
qc.name = "su2random"

Expand Down
2 changes: 1 addition & 1 deletion src/mqt/bench/benchmarks/twolocalrandom.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def create_circuit(num_qubits: int) -> QuantumCircuit:
np.random.seed(10)
qc = TwoLocal(num_qubits, "ry", "cx", entanglement="full", reps=3)
num_params = qc.num_parameters
qc = qc.bind_parameters(2 * np.pi * np.random.rand(num_params))
qc = qc.assign_parameters(2 * np.pi * np.random.rand(num_params))
qc.measure_all()
qc.name = "twolocalrandom"

Expand Down
6 changes: 3 additions & 3 deletions src/mqt/bench/benchmarks/vqe.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

from typing import TYPE_CHECKING

from qiskit.algorithms.minimum_eigensolvers import VQE
from qiskit.algorithms.optimizers import SLSQP
from qiskit.circuit.library import RealAmplitudes
from qiskit.primitives import Estimator
from qiskit_algorithms.minimum_eigensolvers import VQE
from qiskit_algorithms.optimizers import SLSQP
from qiskit_optimization import QuadraticProgram

from mqt.bench.utils import get_examplary_max_cut_qp
Expand All @@ -30,7 +30,7 @@ def create_circuit(num_qubits: int) -> QuantumCircuit:
ansatz = RealAmplitudes(num_qubits, reps=2)
vqe = VQE(ansatz=ansatz, optimizer=SLSQP(maxiter=25), estimator=Estimator())
vqe_result = vqe.compute_minimum_eigenvalue(qp.to_ising()[0])
qc = vqe.ansatz.bind_parameters(vqe_result.optimal_point)
qc = vqe.ansatz.assign_parameters(vqe_result.optimal_point)

qc.measure_all()
qc.name = "vqe"
Expand Down
9 changes: 5 additions & 4 deletions src/mqt/bench/qiskit_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@

from mqt.bench.devices import Device, Provider

from qiskit.compiler import transpile
from qiskit import transpile
from qiskit.qasm2 import dumps

from mqt.bench import utils

Expand Down Expand Up @@ -69,7 +70,7 @@ def get_indep_level(
if return_qc:
return target_independent
return utils.save_as_qasm(
target_independent.qasm(),
dumps(target_independent),
filename_indep,
target_directory=target_directory,
)
Expand Down Expand Up @@ -146,7 +147,7 @@ def get_native_gates_level(
if return_qc:
return compiled_without_architecture
return utils.save_as_qasm(
compiled_without_architecture.qasm(),
dumps(compiled_without_architecture),
filename_native,
gate_set,
target_directory=target_directory,
Expand Down Expand Up @@ -226,7 +227,7 @@ def get_mapped_level(
if return_qc:
return compiled_with_architecture
return utils.save_as_qasm(
compiled_with_architecture.qasm(),
dumps(compiled_with_architecture),
filename_mapped,
device.basis_gates,
True,
Expand Down
4 changes: 2 additions & 2 deletions src/mqt/bench/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
import networkx as nx
import numpy as np
from pytket import __version__ as __tket_version__
from qiskit import QuantumCircuit, __qiskit_version__
from qiskit import QuantumCircuit
from qiskit import __version__ as __qiskit_version__
from qiskit.converters import circuit_to_dag
from qiskit_optimization.applications import Maxcut

Expand Down Expand Up @@ -198,7 +199,6 @@ def save_as_qasm(
f.write("// Qiskit version: " + str(__qiskit_version__) + "\n")
elif "tket" in filename:
f.write("// TKET version: " + str(__tket_version__) + "\n")

if gate_set:
f.write("// Used Gate Set: " + str(gate_set) + "\n")
if mapped:
Expand Down
2 changes: 1 addition & 1 deletion tests/devices/test_ibm_device_support.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

import pytest
from qiskit.providers.fake_provider import FakeMontreal, FakeMontrealV2
from qiskit_ibm_runtime.fake_provider import FakeMontreal, FakeMontrealV2

from mqt.bench.devices import IBMProvider

Expand Down
4 changes: 3 additions & 1 deletion tests/test_bench.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from typing import TYPE_CHECKING

import pytket
from qiskit.qasm2 import dump

if TYPE_CHECKING: # pragma: no cover
import types
Expand Down Expand Up @@ -1013,7 +1014,8 @@ def test_oqc_postprocessing() -> None:
def test_evaluate_qasm_file() -> None:
qc = get_benchmark("dj", 1, 5)
filename = "test_5.qasm"
qc.qasm(filename=filename)
with Path(filename).open("w") as f:
dump(qc, f)
path = Path(filename)
res = evaluation.evaluate_qasm_file(filename)
assert type(res) == evaluation.EvaluationResult
Expand Down

0 comments on commit 1ff0512

Please sign in to comment.