Skip to main content

SCPN Control — Neuro-symbolic Stochastic Petri Net controller for plasma control

Project description

SCPN-CONTROL — Formal Stochastic Petri Net Engine

CI Docs Pages License: AGPL v3 ORCID


scpn-control is a standalone neuro-symbolic control engine that compiles Stochastic Petri Nets into spiking neural network controllers with formal verification guarantees. Extracted from scpn-fusion-core as the minimal 41-file transitive closure of the control pipeline.

Quick Start

pip install -e "."
scpn-control demo --steps 1000
scpn-control benchmark --n-bench 5000

Documentation and Tutorials

  • Documentation site: https://anulum.github.io/scpn-control/
  • Local docs index: docs/index.md
  • Benchmark guide: docs/benchmarks.md
  • Notebook tutorials:
    • examples/neuro_symbolic_control_demo.ipynb
    • examples/q10_breakeven_demo.ipynb
    • examples/snn_compiler_walkthrough.ipynb

Build docs locally:

python -m pip install mkdocs
mkdocs serve

Execute all notebooks:

python -m pip install -e ".[viz]" jupyter nbconvert
jupyter nbconvert --to notebook --execute --output-dir artifacts/notebook-exec examples/q10_breakeven_demo.ipynb
jupyter nbconvert --to notebook --execute --output-dir artifacts/notebook-exec examples/snn_compiler_walkthrough.ipynb

Optional notebook (requires sc_neurocore available in environment):

jupyter nbconvert --to notebook --execute --output-dir artifacts/notebook-exec examples/neuro_symbolic_control_demo.ipynb

Features

  • Petri Net to SNN compilation -- Translates Stochastic Petri Nets into spiking neural network controllers with LIF neurons and bitstream encoding
  • Formal verification -- Contract-based pre/post-condition checking on all control observations and actions
  • Sub-millisecond latency -- <1ms control loop with optional Rust-accelerated kernels
  • Rust acceleration -- PyO3 bindings for SCPN activation, marking update, Boris integration, SNN pools, and MPC
  • Multiple controller types -- PID, MPC, H-infinity, SNN, neuro-cybernetic dual R+Z
  • Grad-Shafranov solver -- Free-boundary equilibrium solver with L-mode/H-mode profile support
  • Digital twin integration -- Real-time telemetry ingest, closed-loop simulation, and flight simulator
  • RMSE validation -- CI-gated regression testing against DIII-D and SPARC experimental reference data
  • Disruption prediction -- ML-based predictor with SPI mitigation and halo/RE physics

Architecture

src/scpn_control/
+-- scpn/              # Petri net -> SNN compiler
|   +-- structure.py   #   StochasticPetriNet graph builder
|   +-- compiler.py    #   FusionCompiler -> CompiledNet (LIF + bitstream)
|   +-- contracts.py   #   ControlObservation, ControlAction, ControlTargets
|   +-- controller.py  #   NeuroSymbolicController (main entry point)
+-- core/              # Solver + plant model (clean init, no import bombs)
|   +-- fusion_kernel.py           # Grad-Shafranov equilibrium solver
|   +-- integrated_transport_solver.py  # Multi-species transport
|   +-- scaling_laws.py            # IPB98y2 confinement scaling
|   +-- eqdsk.py                   # GEQDSK/EQDSK file I/O
|   +-- uncertainty.py             # Monte Carlo UQ
+-- control/           # Controllers (optional deps guarded)
|   +-- h_infinity_controller.py   # H-inf robust control
|   +-- fusion_sota_mpc.py         # Model Predictive Control
|   +-- disruption_predictor.py    # ML disruption prediction
|   +-- tokamak_digital_twin.py    # Digital twin
|   +-- tokamak_flight_sim.py      # IsoFlux flight simulator
|   +-- neuro_cybernetic_controller.py  # Dual R+Z SNN
+-- cli.py             # Click CLI

scpn-control-rs/       # Rust workspace (5 crates)
+-- control-types/     # PlasmaState, EquilibriumConfig, ControlAction
+-- control-math/      # LIF neuron, Boris pusher, matrix ops
+-- control-core/      # GS solver, transport, confinement scaling
+-- control-control/   # PID, MPC, H-inf, SNN controller
+-- control-python/    # Slim PyO3 bindings (~474 LOC)

Dependencies

Required Optional
numpy >= 1.24 matplotlib (pip install -e ".[viz]")
scipy >= 1.10 streamlit (pip install -e ".[dashboard]")
click >= 8.0 torch (pip install -e ".[ml]")
nengo (pip install -e ".[nengo]")

CLI

scpn-control demo --scenario combined --steps 1000   # Closed-loop control demo
scpn-control benchmark --n-bench 5000                 # PID vs SNN timing benchmark
scpn-control validate                                 # RMSE validation dashboard
scpn-control hil-test --shots-dir ...                 # HIL test campaign

Benchmarks

Python micro-benchmark:

scpn-control benchmark --n-bench 5000 --json-out

Rust Criterion benchmarks:

cd scpn-control-rs
cargo bench --workspace

Benchmark docs: docs/benchmarks.md

Dashboard

pip install -e ".[dashboard]"
streamlit run dashboard/control_dashboard.py

Four tabs: Trajectory Viewer, RMSE Dashboard, Timing Benchmark, Shot Replay.

Rust Acceleration

cd scpn-control-rs
cargo test --workspace

# Build Python bindings
pip install maturin
maturin develop --release

# Verify
python -c "import scpn_control_rs; print('Rust backend active')"

The Rust backend provides PyO3 bindings for:

  • PyFusionKernel -- Grad-Shafranov solver
  • PySnnPool / PySnnController -- Spiking neural network pools
  • PyMpcController -- Model Predictive Control
  • PyPlasma2D -- Digital twin
  • PyTransportSolver -- Chang-Hinton + Sauter bootstrap
  • SCPN kernels -- dense_activations, marking_update, sample_firing

Citation

@software{sotek2026scpncontrol,
  title   = {SCPN Control: Neuro-Symbolic Stochastic Petri Net Controller},
  author  = {Sotek, Miroslav and Reiprich, Michal},
  year    = {2026},
  url     = {https://github.com/anulum/scpn-control},
  license = {AGPL-3.0-or-later}
}

Release and PyPI

Publishing is handled by workflow:

  • .github/workflows/publish-pypi.yml

Authors

  • Miroslav Sotek — ANULUM CH & LI — ORCID
  • Michal Reiprich — ANULUM CH & LI

License

  • Concepts: Copyright 1996-2026
  • Code: Copyright 2024-2026
  • License: GNU AGPL v3

GNU Affero General Public License v3.0 — see LICENSE.

For commercial licensing inquiries, contact: protoscience@anulum.li

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

scpn_control-0.1.0.tar.gz (256.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

scpn_control-0.1.0-py3-none-any.whl (214.2 kB view details)

Uploaded Python 3

File details

Details for the file scpn_control-0.1.0.tar.gz.

File metadata

  • Download URL: scpn_control-0.1.0.tar.gz
  • Upload date:
  • Size: 256.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for scpn_control-0.1.0.tar.gz
Algorithm Hash digest
SHA256 988d7bd8e4b0386beed0d0e78b7fcd193ba37206cc1a88d06888f862cbc57b97
MD5 4a3a32141d4536dadc841dbcc5408491
BLAKE2b-256 25e8b9aad16b6fcec6d5eac72bae5c34dbdffaf334d98f6b1fbf74017abbb45e

See more details on using hashes here.

Provenance

The following attestation bundles were made for scpn_control-0.1.0.tar.gz:

Publisher: publish-pypi.yml on anulum/scpn-control

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file scpn_control-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: scpn_control-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 214.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for scpn_control-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b61642f580b3983501ca1472feba76592f59c7cfd6c428ff61229c64ab05671d
MD5 b318d8d5983e54439acd5ec8c82e3204
BLAKE2b-256 3cb963d3403b8828abe5d36442265d67176d09ebb54a40ee69d8ecd3ece34962

See more details on using hashes here.

Provenance

The following attestation bundles were made for scpn_control-0.1.0-py3-none-any.whl:

Publisher: publish-pypi.yml on anulum/scpn-control

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page