Skip to main content

plasmax logo

Plasmax: differentiable & parallelizable environments for transport control in Tokamaks

plasmax provides JAX-native fusion-control environments built on TORAX. The environments are inspired by real tokamak devices; ITER, SPARC, STEP, and KSTAR. Each tokamak contains different tasks for different scenarios and phases.

Environment design is inspired by recommendations from Challenges of Real World Reinforcement Learning, where missing, noisy observations are explicitly implemented.

Install

pip install plasmax

We did not package the training and agent stack to make the dependencies lighter. If you want to try training agents using our stack:

git clone https://github.com/TheodoreWolf/plasmax
cd plasmax
pip install -e . --group research

Quick start

import jax
import jax.numpy as jnp

import plasmax

env = plasmax.make(
    "iter/hybrid/flattop",
    backend="bohm_gyrobohm",
)

state, info = env.init(jax.random.key(0))
action = jnp.zeros(env.action_space.shape, dtype=env.action_space.dtype)
state, info = env.step(state, action)

print(info.obs, info.reward)
print(info.terminated, info.truncated)

Environments are loaded through the make function, the environment name is structured as such {tokamak}/{scenario}/{phase}.

By default, it applies the modifications recommended by Challenges of Real World Reinforcement Learning, use variant="oracle", to remove these.

The environments use the Envelope API and contracts, this includes e.g. explicit truncation versus termination.

Tasks and backends

Task aliases Compatible backend aliases
iter/{baseline,hybrid,advanced}/{rampup,flattop,rampdown} cgm, qlknn, bohm_gyrobohm, tglfnn, tglfnn_nr
sparc/{prd,reduced_field}/{rampup,flattop,rampdown} cgm, qlknn, bohm_gyrobohm, tglfnn, tglfnn_nr
step bohm_gyrobohm, tglfnn_spherical
kstar fusion_lstm

Unsupported environment/backend pairs are rejected before construction.

NB: the tglfnn_spherical backend requires a repository clone for now. TGLFNN-UKAEA is still an eager transitive TORAX dependency. TORAX 1.4.3 pins fusion-surrogates 0.4.6, whose TGLFNN extra pins the older 0.1.0 weights. Repository clones use a uv-only override to the final PyPI 0.2.0 weights until TORAX adopts fusion-surrogates 0.4.7. Published installs still follow TORAX's dependency metadata.

Equilibria generated with FreeGSNKE are committed artifacts, so FreeGSNKE is not a runtime dependency.

Every leaf task YAML owns its reward and terminal-penalty defaults:

task:
  reward: lh_transition
  terminal_penalty: -100

By default, reward and disruption_penalty; uses the task metadata. Explicit overrides are supported, including disruption_penalty=0.0. Ramp-up tasks use lh_transition, flat-top and STEP tasks use P_diff, and ramp-down tasks use rampdown. KSTAR uses its native learned-model reward and has no terminal penalty.

env = plasmax.make("iter/advanced/rampup", backend="qlknn")

oracle_ablation = plasmax.make(
    "iter/advanced/rampup",
    backend="qlknn",
    variant="oracle",
    reward="Q_fusion",
    disruption_penalty=0.0,
)

Environment boundary

init, step, and reset return (state, info). A transition exposes:

  • info.obs: the post-transition flat observation;
  • info.reward: a scalar float32 RL-boundary reward;
  • info.terminated: a physical or solver termination;
  • info.truncated: the configured time-limit cutoff;
  • info.termination_code: the environment's termination reason.

If termination and the time limit coincide, termination wins.

Fixed-shape rollout collection is part of the installed library:

from plasmax import collect_episode


def act(obs, key):
    del obs, key
    return jnp.zeros(env.action_space.shape, dtype=env.action_space.dtype)


trajectory = collect_episode(
    act,
    env,
    jax.random.key(1),
    num_steps=env.max_steps,
)

The collector retains the first terminal transition, stops stepping the environment, and pads the remaining fixed-size output with valid=False.

Contribution and Development

We welcome contributions! To contribute, first fork the repository, then:

git clone {your_gh_username}/plasmax
cd plasmax
# We highly encourage uv for developement
uv sync --group dev
git checkout {name}/{what_you_are_changing}

Then you can open a PR in this repository. Make sure to run tests, CI will do this for you as well. Please have respect for the developer's time and do not submit PRs that can not be reasonably reviewed (even with the help of agents).

Repository layout

src/plasmax/        installed environments, tooling, configs, and data
agents/             clone-only baseline agents
training/           clone-only training adapters
scripts/            generic baseline and rollout launchers
tools/              artifact and equilibrium generation
benchmarks/         backend agreement and throughput benchmarks
experiments/        research studies and plotting
tests/              library and release tests

License and attribution

The library is licensed under the Apache License 2.0. TORAX and packaged third-party data/model assets retain their own attribution and license terms; the relevant notices are shipped adjacent to those assets.

Agents

An AGENTS.md file is included, which has my own personal code preferences. We recommend users who want to use agents to obtain an explicit JAX skill (I've written my own, that I will open-source, when I'm happy with it), as current agents are still not great at this. Agents were utilized throughout this work, while I did my best to check the code, mistakes remain. In my experience, the most dangerous are comments that state mistakes or bad assumption as facts, this then further reinforce the agents in their bad ideas.

Citation

Coming soon, once I get the paper out...

Download files

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

Source Distribution

plasmax-0.1.0.tar.gz (26.1 MB view details)

Uploaded Source

Built Distribution

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

plasmax-0.1.0-py3-none-any.whl (26.2 MB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: plasmax-0.1.0.tar.gz
  • Upload date:
  • Size: 26.1 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for plasmax-0.1.0.tar.gz
Algorithm Hash digest
SHA256 43f98346686010189d1acab35a2792f5ebd86391a734750cdc5820eb504ace34
MD5 b9f3cc612863eb0a5fba9df74e4fc45b
BLAKE2b-256 c913960216f7a7e2cadc00d505398431dc7650129c7c3f18a54c9debde11ae8e

See more details on using hashes here.

Provenance

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

Publisher: publish.yml on TheodoreWolf/plasmax

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

File details

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

File metadata

  • Download URL: plasmax-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 26.2 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for plasmax-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 77b75091e9d7bd9d45c1cc0e18310a80e85ba0d1557d3a501da72dcce560944b
MD5 59d80ce3961f029cd1473cfc1b144265
BLAKE2b-256 256c085384b5b2c29300cf450f1a6f2c0551dd034192f35b3538c31eae18f8ad

See more details on using hashes here.

Provenance

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

Publisher: publish.yml on TheodoreWolf/plasmax

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

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page