harishaseebat92 commited on
Commit
ed530ff
·
1 Parent(s): 6e27ad5

Clearly separated CUDA-Q backend execution from CPU Demo fallback

Browse files
Files changed (1) hide show
  1. qlbm_embedded.py +73 -8
qlbm_embedded.py CHANGED
@@ -167,8 +167,8 @@ def init_state():
167
 
168
  # Backend
169
  "qlbm_backend_type": None,
170
- "qlbm_selected_simulator": "IBM Qiskit simulator",
171
- "qlbm_selected_qpu": "IBM QPU",
172
 
173
  # Simulation state
174
  "qlbm_is_running": False,
@@ -1050,8 +1050,8 @@ def run_simulation():
1050
  _state.qlbm_status_message = "Simulation completed successfully."
1051
  _state.qlbm_status_type = "success"
1052
 
1053
- # === CUDA-Q or CPU Demo Backend ===
1054
- else:
1055
  _state.qlbm_qiskit_mode = False # Use PyVista display
1056
 
1057
  grid_size = int(_state.qlbm_grid_size)
@@ -1082,7 +1082,8 @@ def run_simulation():
1082
  progress_callback=_progress_callback
1083
  )
1084
  else:
1085
- log_to_console("Running CPU Demo Simulation...")
 
1086
  frames, times, grid_obj = _run_cpu_demo_simulation(
1087
  grid_size=grid_size,
1088
  T=T,
@@ -1127,6 +1128,69 @@ def run_simulation():
1127
  log_to_console("Error: Simulation produced no data.")
1128
  _state.qlbm_status_message = "Error: No data produced"
1129
  _state.qlbm_status_type = "error"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1130
 
1131
  except Exception as e:
1132
  _state.qlbm_run_error = f"Simulation failed: {str(e)}"
@@ -1485,9 +1549,9 @@ def _build_control_panels(plotter):
1485
  density="compact",
1486
  children=[
1487
  "Selected: ",
1488
- "{{ qlbm_backend_type || '' }}",
1489
  " - ",
1490
- "{{ qlbm_backend_type === 'Simulator' ? qlbm_selected_simulator : (qlbm_backend_type === 'QPU' ? qlbm_selected_qpu : '—') }}",
1491
  ],
1492
  )
1493
  with vuetify3.VMenu(open_on_hover=True, close_on_content_click=True, location="end"):
@@ -1498,6 +1562,7 @@ def _build_control_panels(plotter):
1498
  with vuetify3.Template(v_slot_activator="{ props }"):
1499
  vuetify3.VListItem(v_bind="props", title="Simulator", prepend_icon="mdi-robot-outline", append_icon="mdi-chevron-right")
1500
  with vuetify3.VList(density="compact"):
 
1501
  vuetify3.VListItem(title="IBM Qiskit simulator", click="qlbm_backend_type = 'Simulator'; qlbm_selected_simulator = 'IBM Qiskit simulator'")
1502
  with vuetify3.VMenu(open_on_hover=True, close_on_content_click=True, location="end", offset=8):
1503
  with vuetify3.Template(v_slot_activator="{ props }"):
@@ -1521,7 +1586,7 @@ def _build_control_panels(plotter):
1521
  text="Run",
1522
  color="primary",
1523
  block=True,
1524
- disabled=("qlbm_is_running || !qlbm_simulation_backend_ready", False),
1525
  click=run_simulation,
1526
  style=("qlbm_is_running ? '' : 'background-color:#87CEFA;'", ""),
1527
  )
 
167
 
168
  # Backend
169
  "qlbm_backend_type": None,
170
+ "qlbm_selected_simulator": None,
171
+ "qlbm_selected_qpu": None,
172
 
173
  # Simulation state
174
  "qlbm_is_running": False,
 
1050
  _state.qlbm_status_message = "Simulation completed successfully."
1051
  _state.qlbm_status_type = "success"
1052
 
1053
+ # === CUDA-Q Backend ===
1054
+ elif _state.qlbm_backend_type == "Simulator" and _state.qlbm_selected_simulator == "CUDA-Q simulator":
1055
  _state.qlbm_qiskit_mode = False # Use PyVista display
1056
 
1057
  grid_size = int(_state.qlbm_grid_size)
 
1082
  progress_callback=_progress_callback
1083
  )
1084
  else:
1085
+ # Fallback to CPU demo if CUDA-Q not available
1086
+ log_to_console("CUDA-Q not available, falling back to CPU Demo...")
1087
  frames, times, grid_obj = _run_cpu_demo_simulation(
1088
  grid_size=grid_size,
1089
  T=T,
 
1128
  log_to_console("Error: Simulation produced no data.")
1129
  _state.qlbm_status_message = "Error: No data produced"
1130
  _state.qlbm_status_type = "error"
1131
+
1132
+ # === CPU Demo Backend (for QPU or fallback) ===
1133
+ else:
1134
+ _state.qlbm_qiskit_mode = False # Use PyVista display
1135
+
1136
+ grid_size = int(_state.qlbm_grid_size)
1137
+ num_reg_qubits = int(math.log2(grid_size)) if grid_size > 0 else 3
1138
+ T = int(_state.qlbm_time_steps)
1139
+ distribution_type = _state.qlbm_dist_type
1140
+ boundary_condition = _state.qlbm_boundary_condition
1141
+
1142
+ vx_func = make_velocity_func(_state.qlbm_vx_expr)
1143
+ vy_func = make_velocity_func(_state.qlbm_vy_expr)
1144
+ vz_func = make_velocity_func(_state.qlbm_vz_expr)
1145
+
1146
+ _progress_callback(0)
1147
+
1148
+ # CPU Demo Simulation
1149
+ log_to_console("Running CPU Demo Simulation...")
1150
+ frames, times, grid_obj = _run_cpu_demo_simulation(
1151
+ grid_size=grid_size,
1152
+ T=T,
1153
+ distribution_type=distribution_type or "Sinusoidal",
1154
+ vx_func=vx_func,
1155
+ vy_func=vy_func,
1156
+ vz_func=vz_func,
1157
+ progress_callback=_progress_callback
1158
+ )
1159
+
1160
+ _progress_callback(100)
1161
+
1162
+ # Update plotter with results
1163
+ if grid_obj:
1164
+ _plotter.clear()
1165
+ isosurfaces = grid_obj.contour(isosurfaces=7, scalars="scalars")
1166
+ _plotter.add_mesh(isosurfaces, cmap="Blues", opacity=0.3, show_scalar_bar=True)
1167
+ _plotter.add_axes()
1168
+ _plotter.show_grid()
1169
+
1170
+ # Store Results
1171
+ if frames and len(frames) > 0:
1172
+ simulation_data_frames = frames
1173
+ simulation_times = times
1174
+ current_grid_object = grid_obj
1175
+
1176
+ _state.qlbm_max_time_step = len(frames) - 1
1177
+ _state.qlbm_time_val = 0
1178
+ _state.qlbm_time_slider_labels = [f"{t:.1f}" for t in times] if times else [str(i) for i in range(len(frames))]
1179
+ _state.qlbm_simulation_has_run = True
1180
+
1181
+ _ensure_point_picking(on_pick_point)
1182
+
1183
+ if hasattr(_ctrl, "qlbm_view_update"):
1184
+ _ctrl.qlbm_view_update()
1185
+ log_to_console("Simulation completed successfully.")
1186
+ _state.qlbm_status_message = "Simulation completed successfully."
1187
+ _state.qlbm_status_type = "success"
1188
+ _state.qlbm_simulation_progress = 100
1189
+ else:
1190
+ _state.qlbm_run_error = "Simulation produced no data."
1191
+ log_to_console("Error: Simulation produced no data.")
1192
+ _state.qlbm_status_message = "Error: No data produced"
1193
+ _state.qlbm_status_type = "error"
1194
 
1195
  except Exception as e:
1196
  _state.qlbm_run_error = f"Simulation failed: {str(e)}"
 
1549
  density="compact",
1550
  children=[
1551
  "Selected: ",
1552
+ "{{ qlbm_backend_type || 'None - Please select a backend' }}",
1553
  " - ",
1554
+ "{{ qlbm_backend_type === 'Simulator' ? (qlbm_selected_simulator || '—') : (qlbm_backend_type === 'QPU' ? (qlbm_selected_qpu || '—') : '—') }}",
1555
  ],
1556
  )
1557
  with vuetify3.VMenu(open_on_hover=True, close_on_content_click=True, location="end"):
 
1562
  with vuetify3.Template(v_slot_activator="{ props }"):
1563
  vuetify3.VListItem(v_bind="props", title="Simulator", prepend_icon="mdi-robot-outline", append_icon="mdi-chevron-right")
1564
  with vuetify3.VList(density="compact"):
1565
+ vuetify3.VListItem(title="CUDA-Q simulator", click="qlbm_backend_type = 'Simulator'; qlbm_selected_simulator = 'CUDA-Q simulator'")
1566
  vuetify3.VListItem(title="IBM Qiskit simulator", click="qlbm_backend_type = 'Simulator'; qlbm_selected_simulator = 'IBM Qiskit simulator'")
1567
  with vuetify3.VMenu(open_on_hover=True, close_on_content_click=True, location="end", offset=8):
1568
  with vuetify3.Template(v_slot_activator="{ props }"):
 
1586
  text="Run",
1587
  color="primary",
1588
  block=True,
1589
+ disabled=("qlbm_is_running || !qlbm_backend_type", True),
1590
  click=run_simulation,
1591
  style=("qlbm_is_running ? '' : 'background-color:#87CEFA;'", ""),
1592
  )