Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add benchmarks from MQTBench to red queen #48

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added __init__.py
Empty file.
9 changes: 5 additions & 4 deletions red_queen/games/applications/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import pytest

from qiskit.compiler import transpile
from qiskit.result import marginal_distribution
from qiskit.result import marginal_counts
from qiskit.providers.fake_provider import (
FakeWashington,
FakeBrooklyn,
Expand All @@ -33,7 +33,7 @@


def run_qiskit_circuit(
benchmark, circuit, backend, optimization_level, shots, expected_counts, marginalize=None
benchmark, circuit, backend, optimization_level, shots, expected_counts=None, marginalize=None
):
info, tqc = benchmark(
transpile,
Expand All @@ -53,11 +53,12 @@ def run_qiskit_circuit(
info.quality_stats["xi"] = num_2q / (num_1q + num_2q)
if marginalize:

counts = marginal_distribution(
counts = marginal_counts(
backend.run(tqc, shots=shots, seed_simulator=123456789).result().get_counts(),
marginalize,
)
else:
counts = backend.run(tqc, shots=shots, seed_simulator=123456789).result().get_counts()

info.quality_stats["fidelity"] = hellinger_fidelity(counts, expected_counts)
if expected_counts != None:
info.quality_stats["fidelity"] = hellinger_fidelity(counts, expected_counts)
81 changes: 81 additions & 0 deletions red_queen/games/applications/testmqt.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import os
import pytest

from qiskit import QuantumCircuit, QuantumRegister, ClassicalRegister
from red_queen.games.applications import backends, run_qiskit_circuit
from mqt.bench import get_one_benchmark
from mqt.bench.benchmarks import dj

@pytest.mark.qiskit
@pytest.mark.parametrize("optimization_level", [0, 1, 2, 3])
@pytest.mark.parametrize("backend", backends)
def bench_qiskit_mqt_ae(benchmark, optimization_level, backend):
shots = 65536
expected_counts = {"8": shots}
benchmark.name = "Amplitude Estimation"
circlevel = [0,1,2]
for i in circlevel:
circ = get_one_benchmark("ae",i,8)
benchmark.algorithm = f"Optimization level: {optimization_level} on {backend.name()}"
run_qiskit_circuit(benchmark, circ, backend, optimization_level, shots, expected_counts)

@pytest.mark.qiskit
@pytest.mark.parametrize("optimization_level", [0, 1, 2, 3])
@pytest.mark.parametrize("backend", backends)
def bench_qiskit_mqt_dj_constant(benchmark, optimization_level, backend):
shots = 20000
NUM = 5
expected_counts = {str("0" * NUM): shots}
benchmark.name = "Deutsch Jozsa - Constant Oracle"
circ = dj.create_circuit(NUM,False)
benchmark.algorithm = f"Optimization level: {optimization_level} on {backend.name()}"
run_qiskit_circuit(benchmark, circ, backend, optimization_level, shots, expected_counts)

@pytest.mark.qiskit
@pytest.mark.parametrize("optimization_level", [0, 1, 2, 3])
@pytest.mark.parametrize("backend", backends)
def bench_qiskit_mqt_dj_balanced(benchmark, optimization_level, backend):
shots = 20000
NUM = 5
expected_counts = {str("1" * NUM): shots}
benchmark.name = "Deutsch Jozsa - Balanced Oracle"
circ = dj.create_circuit(NUM,True)
benchmark.algorithm = f"Optimization level: {optimization_level} on {backend.name()}"
run_qiskit_circuit(benchmark, circ, backend, optimization_level, shots, expected_counts)

@pytest.mark.qiskit
@pytest.mark.parametrize("optimization_level", [0, 1, 2, 3])
@pytest.mark.parametrize("backend", backends)
def bench_qiskit_mqt_grover_noancilla(benchmark, optimization_level, backend):
shots = 20000
NUM = 5
benchmark.name = "grover-noancilla"
circlevel = [0,1,2]
for i in circlevel:
circ = get_one_benchmark("grover-noancilla",i,NUM)
benchmark.algorithm = f"Optimization level: {optimization_level} on {backend.name()}"
run_qiskit_circuit(benchmark, circ, backend, optimization_level, shots)

@pytest.mark.qiskit
@pytest.mark.parametrize("optimization_level", [0, 1, 2, 3])
@pytest.mark.parametrize("backend", backends)
def bench_qiskit_mqt_grover_vchain(benchmark, optimization_level, backend):
shots = 20000
NUM = 5
benchmark.name = "grover-v-chain"
circlevel = [0,1,2]
for i in circlevel:
circ = get_one_benchmark("grover-v-chain",i,NUM)
benchmark.algorithm = f"Optimization level: {optimization_level} on {backend.name()}"
run_qiskit_circuit(benchmark, circ, backend, optimization_level, shots)

@pytest.mark.qiskit
@pytest.mark.parametrize("optimization_level", [0, 1, 2, 3])
@pytest.mark.parametrize("backend", backends)
def bench_qiskit_mqt_ghz(benchmark, optimization_level, backend):
shots = 20000
NUM = 5
benchmark.name = "ghz"
circ = get_one_benchmark("ghz",0,NUM)
benchmark.algorithm = f"Optimization level: {optimization_level} on {backend.name()}"
run_qiskit_circuit(benchmark, circ, backend, optimization_level, shots)
54 changes: 54 additions & 0 deletions red_queen/games/applications/testmqtone.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import os
import pytest

from qiskit import QuantumCircuit, QuantumRegister, ClassicalRegister
from qiskit.compiler import transpile
from qiskit.providers.aer import AerSimulator
from red_queen.games.applications import backends, run_qiskit_circuit
from mqt.bench import get_one_benchmark
@pytest.mark.qiskit
@pytest.mark.parametrize(
"circuit_name, size",
[
("ae", 8),
("ghz", 5),
("dj", 5),
("grover-noancilla",5),
("grover-v-chain",5),
("ghz",5),
("graphstate",4),
("portfoliovqe",5),
("portfolioqaoa",5),
("qaoa",5),
("qft",8),
("qftentangled",8),
("qpeexact",8),
("qpeinexact",8),
("qgan",5),
("qwalk-noancilla",8),
("qwalk-v-chain",8),
("realamprandom",9),
("su2random",7),
("twolocalrandom",5),
("vqe",5),
("wstate",8),
("shor",9),
("hhl",2),
("pricingcall",5),
("pricinginput",5),
("tsp",3),
],
)
@pytest.mark.parametrize("circuit_level", [0, 1])
@pytest.mark.parametrize("optimization_level", [0, 1, 2, 3])
@pytest.mark.parametrize("backend", backends)
def bench_qiskit_mqt_all(benchmark, circuit_name, size, circuit_level, optimization_level, backend):
shots = 65536
benchmark.name = circuit_name
circ = get_one_benchmark(circuit_name,circuit_level,size)
simulator = AerSimulator(seed_simulator=1234)
tcirc = transpile(circ, simulator, optimization_level=0)
expected_counts = simulator.run(tcirc).result().get_counts()
benchmark.algorithm = f"Circ level: {circuit_level} Optimization level: {optimization_level} on {backend.name()}"
run_qiskit_circuit(benchmark, circ, backend, optimization_level, shots, expected_counts)

3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
mqt.bench
matplotlib
py-cpuinfo
pytest
Expand All @@ -6,4 +7,4 @@ qiskit-terra
qiskit-aer
pytket>1.0,<2.0
setproctitle
rich
rich