quantum / em /globals.py
harishaseebat92
Turbo Colorscale, EM : IONQ QPU Integration
b0f5437
"""
EM Embedded - Global Variables and Constants
Contains PyVista plotter, simulation data, caches, and constants
shared across the EM module.
"""
import numpy as np
import pyvista as pv
# Set PyVista to use off-screen rendering for Trame
pv.OFF_SCREEN = True
__all__ = [
"plotter",
"simulation_data",
"current_mesh",
"data_frames",
"X_grids",
"Y_grids",
"surface_clims",
"stop_simulation",
"snapshot_times",
"z_scale",
"GRID_SIZES",
"DEFAULT_AXIS_TICKS",
"EXCITATION_SURFACE_COLORSCALE",
"qpu_ts_cache",
"sim_ts_cache",
"qpu_cfg_id_counter",
]
# --- Constants ---
GRID_SIZES = [8, 16, 32, 64, 128, 256, 512]
DEFAULT_AXIS_TICKS = (0.0, 0.25, 0.5, 0.75, 1.0)
EXCITATION_SURFACE_COLORSCALE = "Turbo"
# --- PyVista and Simulation Data ---
plotter = pv.Plotter()
simulation_data = None
current_mesh = None
data_frames = None
z_scale = 1.0
X_grids = {} # Dictionary: field -> meshgrid X
Y_grids = {} # Dictionary: field -> meshgrid Y
surface_clims = {}
stop_simulation = False # Flag to stop running simulation
snapshot_times = None # Times corresponding to saved frames
# --- Caches ---
# Cache for QPU Plotly export/selection
qpu_ts_cache = {
"times": None,
"series_map": None,
"field": None,
"fig": None,
"positions_by_field": {"All": []},
"key_to_label": {},
"label_to_keys": {},
"nx": None,
"unique_fields": [],
}
# Cache for Simulator Time Series
sim_ts_cache = {
"fig": None,
"field": None,
}
# Stable id generator for QPU monitor config rows
qpu_cfg_id_counter = 1
def new_monitor_cfg(field: str = "Ez", points: str = "(8, 8)") -> dict:
"""Create a new QPU monitor configuration."""
global qpu_cfg_id_counter
cfg = {"id": qpu_cfg_id_counter, "field": field, "points": points}
qpu_cfg_id_counter += 1
return cfg
def reset_globals():
"""Reset global simulation state."""
global simulation_data, current_mesh, data_frames, X_grids, Y_grids
global surface_clims, stop_simulation, snapshot_times, z_scale
simulation_data = None
current_mesh = None
data_frames = None
X_grids = {}
Y_grids = {}
surface_clims = {}
stop_simulation = False
snapshot_times = None
z_scale = 1.0
def set_stop_simulation(value: bool):
"""Set the stop simulation flag."""
global stop_simulation
stop_simulation = value