scpn_fusion.ui – UI Helpers¶
The UI package contains the Streamlit dashboard app, launcher, dashboard generation utilities, and browser security-header helpers.
Dashboard App¶
SCPN Fusion Core Streamlit application.
This module defines the interactive control-room experience for the fusion core simulator. The dashboard exposes five tabs covering equilibrium solve, ignition performance, nuclear wall loading, power plant balancing, and disruption-shot replay.
Dashboard Generator¶
Visualization helpers for SCPN Fusion dashboards.
The generator produces high-level geometry diagnostics derived from a solved FusionKernel equilibrium instance.
- class scpn_fusion.ui.dashboard_generator.DashboardGenerator(kernel)[source]¶
Bases:
objectBuild and render Poincaré-style diagnostic plots.
The class acts as a compatibility-safe visualization layer over a solved equilibrium object. It deliberately avoids solving physics itself and only renders diagnostics based on already computed equilibrium fields.
- Parameters:
kernel (_DashboardKernel)
- __init__(kernel)[source]¶
Create a generator bound to an already-solved equilibrium kernel.
- Parameters:
kernel (object) – Object exposing the equilibrium fields used by the plotting path.
- Raises:
ValueError – If the object does not expose the required field layout.
- Return type:
None
- scpn_fusion.ui.dashboard_generator.run_dashboard(config_path, output_path='Poincare_Topology.png', *, n_lines=20, n_transits=500)[source]¶
Run the Poincaré dashboard end-to-end from a config file.
This helper is intentionally defensive for CLI use and exits with explicit diagnostics when the compatibility shim is unavailable or the config is not loadable.
- Parameters:
config_path (str or Path) – Path to solver configuration.
output_path (str or Path, default="Poincare_Topology.png") – PNG path to write. Parent directories are created when needed.
n_lines (int, default=20) – Number of seeded trajectories in the generated plot.
n_transits (int, default=500) – Iteration count per trajectory.
- Returns:
Resolved output path used for the PNG render.
- Return type:
Path
- Raises:
RuntimeError – If
FusionKernelis unavailable in the runtime environment.
Dashboard Launcher¶
Launcher utility for running the Streamlit control-room dashboard.
The launcher writes a temporary Streamlit config to enforce safe defaults before execing the dashboard process.
Security Headers¶
Install browser security headers for the Streamlit dashboard server.
- scpn_fusion.ui.security_headers.install_tornado_security_headers(headers={'Content-Security-Policy': "default-src 'self'; base-uri 'self'; object-src 'none'; frame-ancestors 'none'; img-src 'self' data: blob:; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval'; connect-src 'self' ws: wss:; font-src 'self' data:", 'Referrer-Policy': 'no-referrer', 'X-Content-Type-Options': 'nosniff', 'X-Frame-Options': 'DENY'})[source]¶
Patch Tornado request handlers so Streamlit responses carry security headers.
- Parameters:
headers (Mapping[str, str]) – Non-empty security header policy installed on Tornado responses.
- Returns:
Truewhen Tornado is present and the hook is installed or already installed.Falsewhen Tornado is not importable.- Return type:
- Raises:
ValueError – If
headersis empty or contains blank names or values.