harishaseebat92 commited on
Commit
e507df4
·
1 Parent(s): e2e1a8c

Set Optimization Level = 1

Browse files
Files changed (5) hide show
  1. em/handlers.py +13 -11
  2. em/simulation.py +18 -0
  3. em/state.py +1 -1
  4. qlbm/qlbm_sample_app.py +10 -3
  5. qlbm_embedded.py +26 -0
em/handlers.py CHANGED
@@ -266,20 +266,22 @@ def register_handlers():
266
 
267
  @state.change("problem_selection")
268
  def on_problem_change(problem_selection, **kwargs):
269
- """Update geometry options based on problem selection."""
270
- # Filter geometry options based on problem
 
271
  if problem_selection == "Propagation in a given medium (no bodies)":
272
- # Hide "Square Metallic Body" for propagation problem
273
- state.geometry_options = ["None", "Square Domain", "Geometry 2", "Add"]
 
 
274
  elif problem_selection == "Scattering from a perfectly conducting body":
275
- # Hide "Square Domain" for scattering problem
276
- state.geometry_options = ["None", "Square Metallic Body", "Geometry 2", "Add"]
 
 
277
  else:
278
- # Show all options when no problem selected
279
- state.geometry_options = ["None", "Square Metallic Body", "Square Domain", "Geometry 2", "Add"]
280
-
281
- # Reset geometry selection if current selection is no longer valid
282
- if state.geometry_selection not in state.geometry_options:
283
  state.geometry_selection = None
284
 
285
  _apply_workflow_highlights(_determine_workflow_step())
 
266
 
267
  @state.change("problem_selection")
268
  def on_problem_change(problem_selection, **kwargs):
269
+ """Update geometry options and auto-select based on problem selection."""
270
+ from .simulation import log_to_console
271
+
272
  if problem_selection == "Propagation in a given medium (no bodies)":
273
+ # Only show "Square Domain" for propagation problem
274
+ state.geometry_options = ["Square Domain"]
275
+ state.geometry_selection = "Square Domain"
276
+ log_to_console("Auto-selected 'Square Domain' geometry for propagation problem.")
277
  elif problem_selection == "Scattering from a perfectly conducting body":
278
+ # Only show "Square Metallic Body" for scattering problem
279
+ state.geometry_options = ["Square Metallic Body"]
280
+ state.geometry_selection = "Square Metallic Body"
281
+ log_to_console("Auto-selected 'Square Metallic Body' geometry for scattering problem.")
282
  else:
283
+ # Show both options when no specific problem selected
284
+ state.geometry_options = ["Square Domain", "Square Metallic Body"]
 
 
 
285
  state.geometry_selection = None
286
 
287
  _apply_workflow_highlights(_determine_workflow_step())
em/simulation.py CHANGED
@@ -110,6 +110,21 @@ def _stop_progress_heartbeat():
110
  _heartbeat_on = False
111
  _heartbeat_thread = None
112
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
113
  __all__ = [
114
  "run_simulation_only",
115
  "reset_to_defaults",
@@ -541,6 +556,7 @@ async def _run_simulation_async():
541
  log_to_console("Statevector Estimator run completed")
542
  state.status_type = "success"
543
  state.show_progress = False
 
544
 
545
  ready = bool(getattr(fig, "data", None)) and len(fig.data) > 0
546
  state.qpu_ts_ready = ready
@@ -734,6 +750,7 @@ async def _run_simulation_async():
734
  log_to_console("IBM QPU run completed")
735
  state.status_type = "success"
736
  state.show_progress = False
 
737
  await _flush_async() # Update UI with completion status
738
 
739
  ready = bool(field_values) and len(field_values) > 0
@@ -847,6 +864,7 @@ async def _run_simulation_async():
847
  state.status_message = "Simulation completed successfully!"
848
  state.status_type = "success"
849
  state.show_progress = False
 
850
  generate_plot()
851
  else:
852
  state.error_message = "Simulation produced no data. Check parameters (e.g., T > 0)."
 
110
  _heartbeat_on = False
111
  _heartbeat_thread = None
112
 
113
+
114
+ def _auto_hide_status_window(delay_seconds=3.0):
115
+ """
116
+ Schedule the status window to auto-hide after a delay.
117
+ Shows the completion message briefly then closes automatically.
118
+ """
119
+ def _hide_after_delay():
120
+ time.sleep(delay_seconds)
121
+ state.status_visible = False
122
+ _flush_state_threadsafe()
123
+
124
+ hide_thread = threading.Thread(target=_hide_after_delay, daemon=True)
125
+ hide_thread.start()
126
+
127
+
128
  __all__ = [
129
  "run_simulation_only",
130
  "reset_to_defaults",
 
556
  log_to_console("Statevector Estimator run completed")
557
  state.status_type = "success"
558
  state.show_progress = False
559
+ _auto_hide_status_window(3.0) # Auto-hide after 3 seconds
560
 
561
  ready = bool(getattr(fig, "data", None)) and len(fig.data) > 0
562
  state.qpu_ts_ready = ready
 
750
  log_to_console("IBM QPU run completed")
751
  state.status_type = "success"
752
  state.show_progress = False
753
+ _auto_hide_status_window(3.0) # Auto-hide after 3 seconds
754
  await _flush_async() # Update UI with completion status
755
 
756
  ready = bool(field_values) and len(field_values) > 0
 
864
  state.status_message = "Simulation completed successfully!"
865
  state.status_type = "success"
866
  state.show_progress = False
867
+ _auto_hide_status_window(3.0) # Auto-hide after 3 seconds
868
  generate_plot()
869
  else:
870
  state.error_message = "Simulation produced no data. Check parameters (e.g., T > 0)."
em/state.py CHANGED
@@ -198,7 +198,7 @@ def _init_state_defaults():
198
  """Initialize all EM state defaults."""
199
  state.update({
200
  "problem_selection": None,
201
- "geometry_options": ["None", "Square Metallic Body", "Square Domain", "Geometry 2", "Add"],
202
  "dist_type": None,
203
  "impulse_x": 0.5,
204
  "impulse_y": 0.5,
 
198
  """Initialize all EM state defaults."""
199
  state.update({
200
  "problem_selection": None,
201
+ "geometry_options": ["Square Domain", "Square Metallic Body"],
202
  "dist_type": None,
203
  "impulse_x": 0.5,
204
  "impulse_y": 0.5,
qlbm/qlbm_sample_app.py CHANGED
@@ -761,19 +761,26 @@ def run_sampling_hw_ionq(
761
 
762
  # backend = provider.get_backend("simulator")
763
  backend = provider.get_backend("qpu.forte-enterprise-1")
764
- log(f"Selected IonQ backend: {backend.name()}")
765
- update_progress(15, f"Backend: {backend.name()}")
 
 
766
 
767
  qc_list=get_circuit(n,ux,uy,uz,init_state_prep_circ,T_list,vel_resolution,flag_qubits=flag_qubits,midcircuit_meas=False)
768
 
769
  log(f"Generated {len(qc_list)} circuit(s) for timesteps {T_list}")
770
  update_progress(45, f"Generated {len(qc_list)} circuits")
771
 
 
 
 
 
 
772
  # === STEP 2: Job Submission (50%) ===
773
  log("Submitting job to IonQ...")
774
  update_progress(50, "Submitting job to IonQ...")
775
 
776
- job = backend.run(qc_list, shots=shots)
777
  job_id = job.job_id() if hasattr(job, 'job_id') else str(job)
778
  log(f"Job submitted! Job ID: {job_id}")
779
  update_progress(52, f"Job submitted: {job_id}")
 
761
 
762
  # backend = provider.get_backend("simulator")
763
  backend = provider.get_backend("qpu.forte-enterprise-1")
764
+ # Use backend.name (property) instead of backend.name() (method) for Qiskit compatibility
765
+ backend_name = backend.name if isinstance(backend.name, str) else backend.name()
766
+ log(f"Selected IonQ backend: {backend_name}")
767
+ update_progress(15, f"Backend: {backend_name}")
768
 
769
  qc_list=get_circuit(n,ux,uy,uz,init_state_prep_circ,T_list,vel_resolution,flag_qubits=flag_qubits,midcircuit_meas=False)
770
 
771
  log(f"Generated {len(qc_list)} circuit(s) for timesteps {T_list}")
772
  update_progress(45, f"Generated {len(qc_list)} circuits")
773
 
774
+ # Transpile circuits for IonQ with optimization_level=1 (recommended by IonQ)
775
+ log("Transpiling circuits for IonQ (optimization_level=1)...")
776
+ qc_list_transpiled = transpile(qc_list, backend=backend, optimization_level=1)
777
+ update_progress(48, "Circuits transpiled")
778
+
779
  # === STEP 2: Job Submission (50%) ===
780
  log("Submitting job to IonQ...")
781
  update_progress(50, "Submitting job to IonQ...")
782
 
783
+ job = backend.run(qc_list_transpiled, shots=shots)
784
  job_id = job.job_id() if hasattr(job, 'job_id') else str(job)
785
  log(f"Job submitted! Job ID: {job_id}")
786
  update_progress(52, f"Job submitted: {job_id}")
qlbm_embedded.py CHANGED
@@ -173,6 +173,22 @@ def _qlbm_stop_progress_heartbeat():
173
  _qlbm_heartbeat_on = False
174
  _qlbm_heartbeat_thread = None
175
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
176
  GRID_SIZES = [8, 16, 32, 64, 128, 256]
177
  _WORKFLOW_BASE_STYLE = "font-size: 0.8rem; border: 1px solid transparent; transition: box-shadow 0.2s ease;"
178
  _WORKFLOW_HIGHLIGHT_STYLE = "font-size: 0.8rem; box-shadow: 0 0 0 2px #6200ea;"
@@ -1503,6 +1519,8 @@ async def _run_simulation_async():
1503
  log_to_console("Qiskit simulation completed successfully.")
1504
  _state.qlbm_status_message = "Simulation completed successfully."
1505
  _state.qlbm_status_type = "success"
 
 
1506
  await _qlbm_flush_async()
1507
 
1508
  # === IBM QPU Backend ===
@@ -1618,6 +1636,8 @@ async def _run_simulation_async():
1618
  log_to_console("IBM QPU simulation completed successfully.")
1619
  _state.qlbm_status_message = "Simulation completed successfully."
1620
  _state.qlbm_status_type = "success"
 
 
1621
  await _qlbm_flush_async()
1622
 
1623
  # === IonQ QPU Backend ===
@@ -1733,6 +1753,8 @@ async def _run_simulation_async():
1733
  log_to_console("IonQ QPU simulation completed successfully.")
1734
  _state.qlbm_status_message = "Simulation completed successfully."
1735
  _state.qlbm_status_type = "success"
 
 
1736
  await _qlbm_flush_async()
1737
 
1738
  # === CUDA-Q Backend ===
@@ -1822,6 +1844,8 @@ async def _run_simulation_async():
1822
  _state.qlbm_status_message = "Simulation completed successfully."
1823
  _state.qlbm_status_type = "success"
1824
  _state.qlbm_simulation_progress = 100
 
 
1825
  await _qlbm_flush_async()
1826
  else:
1827
  _state.qlbm_run_error = "Simulation produced no data."
@@ -1897,6 +1921,8 @@ async def _run_simulation_async():
1897
  _state.qlbm_status_message = "Simulation completed successfully."
1898
  _state.qlbm_status_type = "success"
1899
  _state.qlbm_simulation_progress = 100
 
 
1900
  await _qlbm_flush_async()
1901
  else:
1902
  _state.qlbm_run_error = "Simulation produced no data."
 
173
  _qlbm_heartbeat_on = False
174
  _qlbm_heartbeat_thread = None
175
 
176
+
177
+ def _qlbm_auto_hide_status_window(delay_seconds=3.0):
178
+ """
179
+ Schedule the QLBM status window to auto-hide after a delay.
180
+ Shows the completion message briefly then closes automatically.
181
+ """
182
+ def _hide_after_delay():
183
+ time_module.sleep(delay_seconds)
184
+ if _state is not None:
185
+ _state.qlbm_status_visible = False
186
+ _qlbm_flush_state_threadsafe()
187
+
188
+ hide_thread = threading.Thread(target=_hide_after_delay, daemon=True)
189
+ hide_thread.start()
190
+
191
+
192
  GRID_SIZES = [8, 16, 32, 64, 128, 256]
193
  _WORKFLOW_BASE_STYLE = "font-size: 0.8rem; border: 1px solid transparent; transition: box-shadow 0.2s ease;"
194
  _WORKFLOW_HIGHLIGHT_STYLE = "font-size: 0.8rem; box-shadow: 0 0 0 2px #6200ea;"
 
1519
  log_to_console("Qiskit simulation completed successfully.")
1520
  _state.qlbm_status_message = "Simulation completed successfully."
1521
  _state.qlbm_status_type = "success"
1522
+ _state.qlbm_show_progress = False
1523
+ _qlbm_auto_hide_status_window(3.0) # Auto-hide after 3 seconds
1524
  await _qlbm_flush_async()
1525
 
1526
  # === IBM QPU Backend ===
 
1636
  log_to_console("IBM QPU simulation completed successfully.")
1637
  _state.qlbm_status_message = "Simulation completed successfully."
1638
  _state.qlbm_status_type = "success"
1639
+ _state.qlbm_show_progress = False
1640
+ _qlbm_auto_hide_status_window(3.0) # Auto-hide after 3 seconds
1641
  await _qlbm_flush_async()
1642
 
1643
  # === IonQ QPU Backend ===
 
1753
  log_to_console("IonQ QPU simulation completed successfully.")
1754
  _state.qlbm_status_message = "Simulation completed successfully."
1755
  _state.qlbm_status_type = "success"
1756
+ _state.qlbm_show_progress = False
1757
+ _qlbm_auto_hide_status_window(3.0) # Auto-hide after 3 seconds
1758
  await _qlbm_flush_async()
1759
 
1760
  # === CUDA-Q Backend ===
 
1844
  _state.qlbm_status_message = "Simulation completed successfully."
1845
  _state.qlbm_status_type = "success"
1846
  _state.qlbm_simulation_progress = 100
1847
+ _state.qlbm_show_progress = False
1848
+ _qlbm_auto_hide_status_window(3.0) # Auto-hide after 3 seconds
1849
  await _qlbm_flush_async()
1850
  else:
1851
  _state.qlbm_run_error = "Simulation produced no data."
 
1921
  _state.qlbm_status_message = "Simulation completed successfully."
1922
  _state.qlbm_status_type = "success"
1923
  _state.qlbm_simulation_progress = 100
1924
+ _state.qlbm_show_progress = False
1925
+ _qlbm_auto_hide_status_window(3.0) # Auto-hide after 3 seconds
1926
  await _qlbm_flush_async()
1927
  else:
1928
  _state.qlbm_run_error = "Simulation produced no data."