Spaces:
Paused
Paused
harishaseebat92
commited on
Commit
·
4bfc0a9
1
Parent(s):
c131b0b
updated the EM UI to show the nearest position message for IBM QPU/Statevector Estimator Output Preference
Browse files
em/qpu.py
CHANGED
|
@@ -55,41 +55,32 @@ def hide_qpu_plots():
|
|
| 55 |
|
| 56 |
|
| 57 |
def update_qpu_sample_slot(slot: int):
|
| 58 |
-
"""Update QPU sample slot with grid point info."""
|
| 59 |
try:
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
|
|
|
| 63 |
|
| 64 |
samples = getattr(state, samples_var, "")
|
| 65 |
-
nx = int(state.nx or 16)
|
| 66 |
|
| 67 |
-
if not samples:
|
| 68 |
setattr(state, info_var, "")
|
| 69 |
setattr(state, gp_var, "")
|
| 70 |
return
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
setattr(state, info_var, "Invalid format. Use (x, y).")
|
| 76 |
setattr(state, gp_var, "")
|
| 77 |
return
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
j = int(round(y * (nx - 1)))
|
| 86 |
-
i = max(0, min(nx - 1, i))
|
| 87 |
-
j = max(0, min(nx - 1, j))
|
| 88 |
-
gps.append((i, j))
|
| 89 |
-
labels.append(f"({i}, {j})")
|
| 90 |
-
|
| 91 |
-
setattr(state, gp_var, "; ".join(labels))
|
| 92 |
-
setattr(state, info_var, f"Grid points: {', '.join(labels)}")
|
| 93 |
except Exception:
|
| 94 |
pass
|
| 95 |
|
|
|
|
| 55 |
|
| 56 |
|
| 57 |
def update_qpu_sample_slot(slot: int):
|
| 58 |
+
"""Update QPU sample slot with grid point info and nearest position message."""
|
| 59 |
try:
|
| 60 |
+
suffix = "" if slot == 1 else f"_{slot}"
|
| 61 |
+
samples_var = f"qpu_monitor_samples{suffix}"
|
| 62 |
+
info_var = f"qpu_monitor_sample_info{suffix}"
|
| 63 |
+
gp_var = f"qpu_monitor_gridpoints{suffix}"
|
| 64 |
|
| 65 |
samples = getattr(state, samples_var, "")
|
|
|
|
| 66 |
|
| 67 |
+
if not samples or not str(samples).strip():
|
| 68 |
setattr(state, info_var, "")
|
| 69 |
setattr(state, gp_var, "")
|
| 70 |
return
|
| 71 |
+
|
| 72 |
+
nx_val = state.nx
|
| 73 |
+
if nx_val is None:
|
| 74 |
+
setattr(state, info_var, "Select a grid size (nx) to compute the nearest grid position.")
|
|
|
|
| 75 |
setattr(state, gp_var, "")
|
| 76 |
return
|
| 77 |
+
|
| 78 |
+
# Import snap_samples_to_grid to get consistent position formatting
|
| 79 |
+
from .excitation import snap_samples_to_grid
|
| 80 |
+
|
| 81 |
+
snapped, message = snap_samples_to_grid(samples, int(nx_val))
|
| 82 |
+
setattr(state, gp_var, snapped)
|
| 83 |
+
setattr(state, info_var, message or "")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 84 |
except Exception:
|
| 85 |
pass
|
| 86 |
|