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.

scpn_fusion.ui.app.main()[source]

Run the dashboard and render all interactive modules.

Return type:

None

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: object

Build 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)

kernel

Solved equilibrium kernel exposing RR, ZZ, Psi, cfg, R, Z, NR, NZ, dR, and dZ.

Type:

object

__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

generate_poincare_plot(n_lines=20, n_transits=500)[source]

Generate a lightweight Poincaré-like magnetic topology figure.

The implementation is a surrogate map suitable for quick quality checks. It plots both sampled field-line-like trajectories and flux-surface contours.

Parameters:
  • n_lines (int, default=20) – Number of seeded trajectories.

  • n_transits (int, default=500) – Iteration count per trajectory.

Returns:

Matplotlib figure containing the generated topology view.

Return type:

Figure

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 FusionKernel is 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.

scpn_fusion.ui.dashboard_launcher.main()[source]

Execute Streamlit in a process with hardened temporary defaults.

Return type:

int

Returns:

The subprocess exit code from Streamlit.

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:

True when Tornado is present and the hook is installed or already installed. False when Tornado is not importable.

Return type:

bool

Raises:

ValueError – If headers is empty or contains blank names or values.