-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
57 lines (42 loc) · 2.15 KB
/
Copy pathutils.py
File metadata and controls
57 lines (42 loc) · 2.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
"""
Shared utilities for the cudaq-performance-benchmarking suite.
Provides common helpers used by both the Streamlit dashboard and the static
plot generation script to avoid logic drift between the two.
"""
from typing import Any
# ─── Visual Constants ───────────────────────────────────────────────
COLORS = ['#E63946', '#2A9D8F', '#264653', '#E9C46A', '#F4A261', '#6A0572', '#1B998B']
MARKER_STYLES = ['o', 's', '^', 'd', 'v', 'p', '*']
# ─── Data Extraction ───────────────────────────────────────────────
def extract_value(val: Any) -> float:
"""Extract the primary latency value from either new multi-trial or legacy format."""
if isinstance(val, dict):
return val["mean"]
return val
def extract_std(val: Any) -> float:
"""Extract standard deviation from multi-trial format, or 0.0 for legacy."""
if isinstance(val, dict):
return val.get("std", 0.0)
return 0.0
def extract_values(data_dict: dict, qubits: list[int]) -> tuple[list[float], list[float]]:
"""Extract mean/std lists for a sequence of qubit counts.
Works with both the new multi-trial format ({mean, std, ...}) and the
legacy flat format (single float per qubit count).
"""
means = [extract_value(data_dict[str(q)]) for q in qubits]
stds = [extract_std(data_dict[str(q)]) for q in qubits]
return means, stds
# ─── Key Parsing ───────────────────────────────────────────────────
def parse_result_keys(results: dict) -> tuple[set[str], set[str]]:
"""Parse result keys into (circuits, targets) sets.
Keys are expected to follow the ``target_circuit`` pattern
(e.g. ``nvidia_ghz``, ``qpp-cpu_hea``).
"""
circuits: set[str] = set()
targets: set[str] = set()
for key in results:
if "_" in key:
t, c = key.rsplit('_', 1)
circuits.add(c)
targets.add(t)
return circuits, targets