-
Notifications
You must be signed in to change notification settings - Fork 12
Storing and Plotting Additional QED-C Metrics #437
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
base: main
Are you sure you want to change the base?
Changes from 21 commits
c6420a2
d443c16
e446da4
bb0018e
728b38c
6165846
6d5eb92
f47863e
eb092fa
a588c19
5440801
87cf987
08bc3df
cf38cee
dd3bc6b
8c51e39
e1d9b00
f05707d
b36d247
ab7ece1
5dcae25
291dc19
93da543
6e464d1
9e2ce46
47d1159
8cf03ee
9886507
c5a8449
6b6d8c9
4681ab9
2231984
3fbb1cd
da766a9
ec28dfb
79d68d0
b50a365
c328f1b
596f8d5
dacbbd8
986ad54
f931178
2007c4c
a349bf6
797a221
202581b
b1432ef
d4a1371
be83db7
1f8b104
8ba3b88
66d03e9
825e1a6
dfb7882
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -43,3 +43,7 @@ docs/_build/ | |
|
|
||
| # mypy | ||
| .mypy_cache/ | ||
|
|
||
| # QC-App-Oriented-Benchmarks | ||
| __data/ | ||
| __images/ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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] = { | ||
|
|
@@ -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} | ||
| } | ||
| } | ||
|
|
@@ -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]] | ||
|
|
||
|
|
||
|
|
@@ -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): | ||
|
|
@@ -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>" | ||
|
||
|
|
||
| # Set plot titles. | ||
| benchmark_title = f"{benchmark_name} ({params.get('method', '1')})" | ||
vprusso marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| suptitle = f"Benchmark Results - {benchmark_title} - {provider_name}" | ||
Neerpatel125 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| 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"] | ||
vprusso marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| # Plot the metrics. | ||
| metrics.plot_metrics(suptitle=suptitle, filters=filters) | ||
Neerpatel125 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| # 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]]]: | ||
| """ | ||
|
|
@@ -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 = [] | ||
|
|
@@ -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 | ||
Neerpatel125 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| 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 | ||
Neerpatel125 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| return flat_circuits, circuit_metrics, circuit_identifiers | ||
|
|
||
|
|
||
|
|
@@ -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( | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.