Spaces:
Runtime error
Runtime error
harishaseebat92
commited on
Commit
·
dae35a5
1
Parent(s):
10c45a9
Modified em_trame console window
Browse files- em_trame.py +28 -7
em_trame.py
CHANGED
|
@@ -367,7 +367,7 @@ def _refresh_qpu_plot_figures():
|
|
| 367 |
state.qpu_ts_other_ready = False
|
| 368 |
state.qpu_other_plot_style = "display: none; width: 900px; height: 660px; margin: 0 auto;"
|
| 369 |
|
| 370 |
-
def _build_qpu_timeseries_plotly_multi(configs, nx: int, T: float, snapshot_dt: float, impulse_pos):
|
| 371 |
times = qutils.create_time_frames(T, snapshot_dt)
|
| 372 |
fig = go.Figure()
|
| 373 |
# Gather all validated positions across configs (after expanding 'All') to compute color normalization
|
|
@@ -408,10 +408,20 @@ def _build_qpu_timeseries_plotly_multi(configs, nx: int, T: float, snapshot_dt:
|
|
| 408 |
dashes = ["solid", "dash", "dot", "dashdot"]
|
| 409 |
markers = ["circle", "square", "diamond", "triangle-up", "x"]
|
| 410 |
|
| 411 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 412 |
# Fetch time series from QPU for this field and the validated positions
|
| 413 |
try:
|
| 414 |
-
series_map_field = qutils.run_qpu(field_type, valid_positions, None, float(T), float(snapshot_dt), int(nx), None, impulse_pos)
|
| 415 |
except Exception as e:
|
| 416 |
print(f"QPU error for {field_type} positions {valid_positions}: {e}")
|
| 417 |
continue
|
|
@@ -753,6 +763,15 @@ def run_simulation_only():
|
|
| 753 |
state.show_progress = True
|
| 754 |
state.simulation_progress = 0
|
| 755 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 756 |
# Reset stop flag and enable Stop button at start
|
| 757 |
stop_simulation = False
|
| 758 |
state.stop_button_disabled = False
|
|
@@ -817,7 +836,7 @@ def run_simulation_only():
|
|
| 817 |
state.status_message = "Building QPU time series..."
|
| 818 |
state.simulation_progress = 60
|
| 819 |
# Build and render Plotly chart (multi-config)
|
| 820 |
-
fig = _build_qpu_timeseries_plotly_multi(configs, nx, T, snapshot_dt, impulse_pos)
|
| 821 |
qpu_ts_cache["fig"] = fig
|
| 822 |
try:
|
| 823 |
ctrl.qpu_ts_update(fig)
|
|
@@ -827,6 +846,7 @@ def run_simulation_only():
|
|
| 827 |
state.run_button_text = "Successful!"
|
| 828 |
state.simulation_progress = 100
|
| 829 |
state.status_message = "QPU simulation completed successfully!"
|
|
|
|
| 830 |
state.status_type = "success"
|
| 831 |
state.show_progress = False
|
| 832 |
# Show chart only if it has data
|
|
@@ -867,8 +887,9 @@ def run_simulation_only():
|
|
| 867 |
return stop_simulation
|
| 868 |
|
| 869 |
state.simulation_progress = 50
|
| 870 |
-
simulation_data, snapshot_times = run_sim(nx, na, R, initial_state, T, snapshot_dt=snapshot_dt, stop_check=_stop_check)
|
| 871 |
print("Simulation complete.")
|
|
|
|
| 872 |
|
| 873 |
state.simulation_progress = 80
|
| 874 |
state.status_message = "Processing simulation results..."
|
|
@@ -1211,7 +1232,7 @@ def generate_plot():
|
|
| 1211 |
points_str = state.timeseries_gridpoints or ""
|
| 1212 |
positions = [tuple(map(int, match)) for match in re.findall(r'\((\d+)\s*,\s*(\d+)\)', points_str)]
|
| 1213 |
if not positions and (state.timeseries_points or "").strip():
|
| 1214 |
-
raise ValueError("No valid monitor positions found. Enter (x, y) pairs in [0,1].")
|
| 1215 |
fig = _build_sim_timeseries_plotly(state.timeseries_field, positions, nx, snapshot_times, simulation_data)
|
| 1216 |
if fig is not None:
|
| 1217 |
try:
|
|
@@ -1554,7 +1575,7 @@ def _snap_samples_to_grid(sample_str: str, nx: int):
|
|
| 1554 |
return "", ""
|
| 1555 |
matches = _SAMPLE_PAIR_RE.findall(str(sample_str))
|
| 1556 |
if not matches:
|
| 1557 |
-
return "", "Enter sample position(s) as (x, y) pairs in [0,1]."
|
| 1558 |
|
| 1559 |
nx_int = int(nx)
|
| 1560 |
denom = float(max(nx_int - 1, 1))
|
|
|
|
| 367 |
state.qpu_ts_other_ready = False
|
| 368 |
state.qpu_other_plot_style = "display: none; width: 900px; height: 660px; margin: 0 auto;"
|
| 369 |
|
| 370 |
+
def _build_qpu_timeseries_plotly_multi(configs, nx: int, T: float, snapshot_dt: float, impulse_pos, progress_callback=None):
|
| 371 |
times = qutils.create_time_frames(T, snapshot_dt)
|
| 372 |
fig = go.Figure()
|
| 373 |
# Gather all validated positions across configs (after expanding 'All') to compute color normalization
|
|
|
|
| 408 |
dashes = ["solid", "dash", "dot", "dashdot"]
|
| 409 |
markers = ["circle", "square", "diamond", "triangle-up", "x"]
|
| 410 |
|
| 411 |
+
total_configs = len(cfg_expanded)
|
| 412 |
+
for idx, (field_type, valid_positions) in enumerate(cfg_expanded):
|
| 413 |
+
# Create a sub-callback for this config's portion of progress
|
| 414 |
+
def _sub_progress(p):
|
| 415 |
+
if progress_callback:
|
| 416 |
+
# Map p (0-100) to the slice for this config
|
| 417 |
+
base = (idx / total_configs) * 100
|
| 418 |
+
fraction = (1 / total_configs) * 100
|
| 419 |
+
total_p = base + (p / 100.0) * fraction
|
| 420 |
+
progress_callback(total_p)
|
| 421 |
+
|
| 422 |
# Fetch time series from QPU for this field and the validated positions
|
| 423 |
try:
|
| 424 |
+
series_map_field = qutils.run_qpu(field_type, valid_positions, None, float(T), float(snapshot_dt), int(nx), None, impulse_pos, progress_callback=_sub_progress)
|
| 425 |
except Exception as e:
|
| 426 |
print(f"QPU error for {field_type} positions {valid_positions}: {e}")
|
| 427 |
continue
|
|
|
|
| 763 |
state.show_progress = True
|
| 764 |
state.simulation_progress = 0
|
| 765 |
|
| 766 |
+
last_logged_percent = 0
|
| 767 |
+
def _progress_callback(percent):
|
| 768 |
+
nonlocal last_logged_percent
|
| 769 |
+
state.simulation_progress = percent
|
| 770 |
+
# Log every 10%
|
| 771 |
+
if percent - last_logged_percent >= 10:
|
| 772 |
+
log_to_console(f"Simulation progress: {int(percent)}%")
|
| 773 |
+
last_logged_percent = percent
|
| 774 |
+
|
| 775 |
# Reset stop flag and enable Stop button at start
|
| 776 |
stop_simulation = False
|
| 777 |
state.stop_button_disabled = False
|
|
|
|
| 836 |
state.status_message = "Building QPU time series..."
|
| 837 |
state.simulation_progress = 60
|
| 838 |
# Build and render Plotly chart (multi-config)
|
| 839 |
+
fig = _build_qpu_timeseries_plotly_multi(configs, nx, T, snapshot_dt, impulse_pos, progress_callback=_progress_callback)
|
| 840 |
qpu_ts_cache["fig"] = fig
|
| 841 |
try:
|
| 842 |
ctrl.qpu_ts_update(fig)
|
|
|
|
| 846 |
state.run_button_text = "Successful!"
|
| 847 |
state.simulation_progress = 100
|
| 848 |
state.status_message = "QPU simulation completed successfully!"
|
| 849 |
+
log_to_console("Simulation Completed")
|
| 850 |
state.status_type = "success"
|
| 851 |
state.show_progress = False
|
| 852 |
# Show chart only if it has data
|
|
|
|
| 887 |
return stop_simulation
|
| 888 |
|
| 889 |
state.simulation_progress = 50
|
| 890 |
+
simulation_data, snapshot_times = run_sim(nx, na, R, initial_state, T, snapshot_dt=snapshot_dt, stop_check=_stop_check, progress_callback=_progress_callback)
|
| 891 |
print("Simulation complete.")
|
| 892 |
+
log_to_console("Simulation complete.")
|
| 893 |
|
| 894 |
state.simulation_progress = 80
|
| 895 |
state.status_message = "Processing simulation results..."
|
|
|
|
| 1232 |
points_str = state.timeseries_gridpoints or ""
|
| 1233 |
positions = [tuple(map(int, match)) for match in re.findall(r'\((\d+)\s*,\s*(\d+)\)', points_str)]
|
| 1234 |
if not positions and (state.timeseries_points or "").strip():
|
| 1235 |
+
raise ValueError("No valid monitor positions found. Enter (x, y) pairs in [0,1] x [0,1].")
|
| 1236 |
fig = _build_sim_timeseries_plotly(state.timeseries_field, positions, nx, snapshot_times, simulation_data)
|
| 1237 |
if fig is not None:
|
| 1238 |
try:
|
|
|
|
| 1575 |
return "", ""
|
| 1576 |
matches = _SAMPLE_PAIR_RE.findall(str(sample_str))
|
| 1577 |
if not matches:
|
| 1578 |
+
return "", "Enter sample position(s) as (x, y) pairs in [0,1] x [0,1]."
|
| 1579 |
|
| 1580 |
nx_int = int(nx)
|
| 1581 |
denom = float(max(nx_int - 1, 1))
|