Skip to content
Open
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
c6420a2
Initial changes to store extra metrics.
Jul 16, 2025
d443c16
Tested extra metrics with Bernstein-Vazirani.
Jul 16, 2025
e446da4
Fixed polling without additional metrics.
Jul 16, 2025
bb0018e
Updated code comments.
Jul 16, 2025
728b38c
Added "extra_metrics" parameter to benchmarks and tested each.
Jul 16, 2025
6165846
Merge branch 'unitaryfoundation:main' into Supporting-Additional-QEDC…
Neerpatel125 Jul 16, 2025
6d5eb92
Rewording code comments.
Jul 16, 2025
f47863e
Added core code to plot the metrics.
Jul 16, 2025
eb092fa
Changing plot's name from Qiskit to qBraid.
Jul 16, 2025
a588c19
Fixed title for generated plots.
Jul 16, 2025
5440801
Added filters to remove create and execution time plots.
Jul 16, 2025
87cf987
Added the option to plot and tested with Bernstein-Vazirani.
Jul 16, 2025
08bc3df
Added plot_metrics parameter to other QED-C benchmarks.
Jul 16, 2025
cf38cee
Git ignoring local plot files.
Jul 16, 2025
dd3bc6b
Filtering plots when extra_metrics is false.
Jul 17, 2025
8c51e39
Code reformatting.
Jul 17, 2025
e1d9b00
Updated QEDC_Metrics data type example.
Jul 17, 2025
f05707d
Rewording comment.
Jul 17, 2025
b36d247
Updated code comments.
Jul 17, 2025
ab7ece1
Updated code comment.
Jul 17, 2025
5dcae25
Code cleaning.
Jul 18, 2025
291dc19
Merge branch 'unitaryfoundation:main' into Supporting-Additional-QEDC…
Neerpatel125 Jul 21, 2025
93da543
Fixing [nit]
Neerpatel125 Jul 21, 2025
6e464d1
Fixing [nit]
Neerpatel125 Jul 21, 2025
9e2ce46
Fixing [nit]
Neerpatel125 Jul 21, 2025
47d1159
Fixing [nit]
Neerpatel125 Jul 21, 2025
8cf03ee
Fixing [nit]
Jul 21, 2025
9886507
Merge branch 'unitaryfoundation:main' into Supporting-Additional-QEDC…
Neerpatel125 Jul 22, 2025
c5a8449
Merge branch 'unitaryfoundation:main' into Supporting-Additional-QEDC…
Neerpatel125 Jul 25, 2025
6b6d8c9
Merge remote-tracking branch 'upstream/main' into Supporting-Addition…
Jul 28, 2025
4681ab9
Merge branch 'unitaryfoundation:main' into Supporting-Additional-QEDC…
Neerpatel125 Jul 28, 2025
2231984
Cleaning plot filters code.
Jul 30, 2025
3fbb1cd
Merge branch 'unitaryfoundation:main' into Supporting-Additional-QEDC…
Neerpatel125 Jul 30, 2025
da766a9
Removed `extra_metrics` and `plot_metrics` from schemas.
Jul 30, 2025
ec28dfb
Merge branch 'unitaryfoundation:main' into Supporting-Additional-QEDC…
Neerpatel125 Jul 31, 2025
79d68d0
Merge branch 'unitaryfoundation:main' into Supporting-Additional-QEDC…
Neerpatel125 Aug 4, 2025
b50a365
Merge branch 'unitaryfoundation:main' into Supporting-Additional-QEDC…
Neerpatel125 Aug 7, 2025
c328f1b
Merge branch 'unitaryfoundation:main' into Supporting-Additional-QEDC…
Neerpatel125 Aug 8, 2025
596f8d5
Updated example schemas.
Aug 11, 2025
dacbbd8
Merge branch 'unitaryfoundation:main' into Supporting-Additional-QEDC…
Neerpatel125 Aug 12, 2025
986ad54
Merge branch 'unitaryfoundation:main' into Supporting-Additional-QEDC…
Neerpatel125 Aug 13, 2025
f931178
Merge branch 'unitaryfoundation:main' into Supporting-Additional-QEDC…
Neerpatel125 Aug 14, 2025
2007c4c
Merge branch 'unitaryfoundation:main' into Supporting-Additional-QEDC…
Neerpatel125 Aug 15, 2025
a349bf6
Merge branch 'unitaryfoundation:main' into Supporting-Additional-QEDC…
Neerpatel125 Aug 15, 2025
797a221
Merge branch 'unitaryfoundation:main' into Supporting-Additional-QEDC…
Neerpatel125 Aug 18, 2025
202581b
Merge branch 'unitaryfoundation:main' into Supporting-Additional-QEDC…
Neerpatel125 Aug 20, 2025
b1432ef
Merge branch 'unitaryfoundation:main' into Supporting-Additional-QEDC…
Neerpatel125 Aug 21, 2025
d4a1371
Merge branch 'unitaryfoundation:main' into Supporting-Additional-QEDC…
Neerpatel125 Aug 26, 2025
be83db7
Merge branch 'unitaryfoundation:main' into Supporting-Additional-QEDC…
Neerpatel125 Aug 29, 2025
1f8b104
Merge branch 'unitaryfoundation:main' into Supporting-Additional-QEDC…
Neerpatel125 Sep 8, 2025
8ba3b88
Merge branch 'unitaryfoundation:main' into Supporting-Additional-QEDC…
Neerpatel125 Sep 10, 2025
66d03e9
Merge branch 'unitaryfoundation:main' into Supporting-Additional-QEDC…
Neerpatel125 Sep 12, 2025
825e1a6
Merge branch 'unitaryfoundation:main' into Supporting-Additional-QEDC…
Neerpatel125 Sep 16, 2025
dfb7882
Merge branch 'unitaryfoundation:main' into Supporting-Additional-QEDC…
Neerpatel125 Sep 23, 2025
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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,7 @@ docs/_build/

# mypy
.mypy_cache/

# QC-App-Oriented-Benchmarks
__data/
__images/
79 changes: 65 additions & 14 deletions metriq_gym/benchmarks/qedc_benchmarks.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from metriq_gym.helpers.task_helpers import flatten_counts

from _common import metrics
from _common.qiskit import execute as ex


QEDC_BENCHMARK_IMPORTS: dict[JobType, str] = {
Expand All @@ -41,22 +42,17 @@
Example for Bernstein-Vazirani:
{
'3': {
'1': {'create_time': 0.16371703147888184,
'fidelity': 1.0,
'1': {'fidelity': 1.0,
'hf_fidelity': 1.0},
'2': {'create_time': 0.0005087852478027344,
'fidelity': 1.0,
'2': {'fidelity': 1.0,
'hf_fidelity': 1.0}
},
'4': {
'1': {'create_time': 0.0005209445953369141,
'fidelity': 1.0,
'1': {'fidelity': 1.0,
'hf_fidelity': 1.0},
'3': {'create_time': 0.00047206878662109375,
'fidelity': 1.0,
'3': {'fidelity': 1.0,
'hf_fidelity': 1.0},
'5': {'create_time': 0.0005078315734863281,
'fidelity': 1.0,
'5': {'fidelity': 1.0,
'hf_fidelity': 1.0}
}
}
Expand All @@ -75,7 +71,7 @@ class QEDCData(BenchmarkData):
used to preserve order when polling.
"""

circuit_metrics: QEDC_Metrics
circuit_metrics: QEDC_Metrics | None
circuit_identifiers: list[tuple[str, str]]


Expand Down Expand Up @@ -141,8 +137,9 @@ def get_counts(self, _):
benchmark_name = str(params["benchmark_name"])
benchmark = import_benchmark_module(benchmark_name)

# Restore circuit metrics dictionary from the dispatch data
metrics.circuit_metrics = job_data.circuit_metrics
# Restore circuit metrics from the dispatch data if needed
if params["extra_metrics"]:
metrics.circuit_metrics = job_data.circuit_metrics

# Iterate and get the metrics for each circuit in the list.
for curr_idx, (num_qubits, circuit_id) in enumerate(job_data.circuit_identifiers):
Expand Down Expand Up @@ -171,13 +168,42 @@ def get_counts(self, _):
None, result_object, int(num_qubits), int(circuit_id), params["num_shots"]
)

# Store the fidelity.
metrics.store_metric(num_qubits, circuit_id, "fidelity", fidelity)

# Optionally plotting metrics
if params["plot_metrics"]:
# Compute statistics for metrics.
metrics.aggregate_metrics()

# Set backend information for plot titles.
provider_name = "qBraid"
device_name = "<unknown>"
Copy link
Contributor Author

@Neerpatel125 Neerpatel125 Jul 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure how to get the provider_name and device_name when polling.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any clever ideas on how to do this, @cosenal ? My initial thought would be to change the arguments for the polling function, but this would require changes to all benchmarks and going forward as well. Maybe supporting some type of *kwargs for polling here is a reasonable approach?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As we discussed on Friday, this is likely something outside of scope for this MR but something that we should perhaps spin up a separate issue about as this is likely a use-case that will crop up again (@cosenal )


# Set plot titles.
benchmark_title = f"{benchmark_name} ({params.get('method', '1')})"
suptitle = f"Benchmark Results - {benchmark_title} - {provider_name}"
metrics.circuit_metrics["subtitle"] = f"device = {device_name}"

# Determine which metrics to plot.
if params["extra_metrics"]:
filters = ["fidelity", "hf_fidelity", "depth", "2q", "vbplot"]
else:
metrics.do_volumetric_plots = False
filters = ["fidelity", "hf_fidelity"]

# Plot the metrics.
metrics.plot_metrics(suptitle=suptitle, filters=filters)

# Remove subtilte key.
metrics.circuit_metrics.pop("subtitle", None)

return metrics.circuit_metrics


def get_circuits_and_metrics(
benchmark_name: str,
extra_metrics: bool,
params: dict[str, float | str],
) -> tuple[list[QuantumCircuit], QEDC_Metrics, list[tuple[str, str]]]:
"""
Expand All @@ -204,6 +230,10 @@ def get_circuits_and_metrics(
# Remove the subtitle key to keep our desired format.
circuit_metrics.pop("subtitle", None)

# Optionally copy any initial creation metrics (i.e. create_time).
if extra_metrics:
metrics.circuit_metrics = circuit_metrics

# Store the circuit identifiers and a flat list of circuits.
circuit_identifiers = []
flat_circuits = []
Expand All @@ -212,6 +242,23 @@ def get_circuits_and_metrics(
circuit_identifiers.append((num_qubits, circuit_id))
flat_circuits.append(circuits[num_qubits][circuit_id])

# Optionally storing extra metrics.
if extra_metrics:
# Compute circuit properties (depth, etc) and store to active circuit object
ex.compute_and_store_circuit_info(
circuits[num_qubits][circuit_id],
str(num_qubits),
str(circuit_id),
do_transpile_metrics=True,
use_normalized_depth=True,
)

# Optionally returning extra metrics.
if extra_metrics:
circuit_metrics = metrics.circuit_metrics
else:
circuit_metrics = None

return flat_circuits, circuit_metrics, circuit_identifiers


Expand All @@ -222,10 +269,14 @@ def dispatch_handler(self, device: QuantumDevice) -> QEDCData:
# For more information on the parameters, view the schema for this benchmark.
num_shots = self.params.num_shots
benchmark_name = self.params.benchmark_name
extra_metrics = self.params.extra_metrics

circuits, circuit_metrics, circuit_identifiers = get_circuits_and_metrics(
benchmark_name=benchmark_name,
params=self.params.model_dump(exclude={"benchmark_name"}),
extra_metrics=extra_metrics,
params=self.params.model_dump(
exclude={"benchmark_name", "extra_metrics", "plot_metrics"}
),
)

return QEDCData.from_quantum_job(
Expand Down
12 changes: 12 additions & 0 deletions metriq_gym/schemas/bernstein_vazirani.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,18 @@
"type": "integer",
"description": "Specifies the secret int for the benchmark; note that max_circuits must be 1 if this is used.",
"examples": [1]
},
"extra_metrics": {
"type": "boolean",
"description": "Determines whether to store circuit depth, width, and more metrics.",
"default": true,
"examples": [false]
},
"plot_metrics": {
"type": "boolean",
"description": "Determines whether to plot metrics and store them.",
"default": true,
"examples": [false]
}
},
"required": ["benchmark_name"],
Expand Down
4 changes: 3 additions & 1 deletion metriq_gym/schemas/examples/bernstein_vazirani.example.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@
"max_qubits": 6,
"skip_qubits": 1,
"max_circuits": 3,
"method": 1
"method": 1,
"extra_metrics": true,
"plot_metrics": true
}
4 changes: 3 additions & 1 deletion metriq_gym/schemas/examples/hidden_shift.example.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@
"max_qubits": 6,
"skip_qubits": 1,
"max_circuits": 3,
"method": 1
"method": 1,
"extra_metrics": true,
"plot_metrics": true
}
4 changes: 3 additions & 1 deletion metriq_gym/schemas/examples/phase_estimation.example.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@
"skip_qubits": 1,
"max_circuits": 3,
"method": 1,
"use_midcircuit_measurement": false
"use_midcircuit_measurement": false,
"extra_metrics": true,
"plot_metrics": true
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@
"skip_qubits": 1,
"max_circuits": 3,
"method": 1,
"use_midcircuit_measurement": false
"use_midcircuit_measurement": false,
"extra_metrics": true,
"plot_metrics": true
}
12 changes: 12 additions & 0 deletions metriq_gym/schemas/hidden_shift.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,18 @@
"type": "integer",
"description": "Specifies the secret int for the benchmark; note that max_circuits must be 1 if this is used.",
"examples": [1]
},
"extra_metrics": {
"type": "boolean",
"description": "Determines whether to store circuit depth, width, and more metrics.",
"default": true,
"examples": [false]
},
"plot_metrics": {
"type": "boolean",
"description": "Determines whether to plot metrics and store them.",
"default": true,
"examples": [false]
}
},
"required": ["benchmark_name"],
Expand Down
13 changes: 12 additions & 1 deletion metriq_gym/schemas/phase_estimation.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,18 @@
"description": "Creates circuits with mid-circuit measurements.",
"default": false,
"examples": [true]

},
"extra_metrics": {
"type": "boolean",
"description": "Determines whether to store circuit depth, width, and more metrics.",
"default": true,
"examples": [false]
},
"plot_metrics": {
"type": "boolean",
"description": "Determines whether to plot metrics and store them.",
"default": true,
"examples": [false]
}
},
"required": ["benchmark_name"],
Expand Down
13 changes: 12 additions & 1 deletion metriq_gym/schemas/quantum_fourier_transform.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,18 @@
"description": "Creates circuits with mid-circuit measurements.",
"default": false,
"examples": [true]

},
"extra_metrics": {
"type": "boolean",
"description": "Determines whether to store circuit depth, width, and more metrics.",
"default": true,
"examples": [false]
},
"plot_metrics": {
"type": "boolean",
"description": "Determines whether to plot metrics and store them.",
"default": true,
"examples": [false]
}
},
"required": ["benchmark_name"],
Expand Down
Loading
Loading