Skip to content

Virtual Plasma Control System (FreeGSNKE Pulse Design Tool) - #64

Merged
kpentland merged 437 commits into
mainfrom
streamlining
Jul 30, 2026
Merged

Virtual Plasma Control System (FreeGSNKE Pulse Design Tool)#64
kpentland merged 437 commits into
mainfrom
streamlining

Conversation

@kpentland

@kpentland kpentland commented Mar 30, 2026

Copy link
Copy Markdown
Collaborator

Hi all,

In this PR, we introduce a virtual plasma control system (PCS) class that couples with FreeGSNKE's evolutive solver. This is useful for plasma scenario and control design enabling users to build plasma, shape, and position controllers that regulate the poloidal field coil voltages applied to the evolutive solver at each time step. It also enables one to encode machine safety limits such as coil voltage and current limits and coil activation times. It is inspired by the MAST-U PCS and more details can be found in the pre-print on arXiv.

The easiest way to see how the virtual PCS works is to check out the above paper and the new Example11 notebook. The different controllers can be used all together in the PCS framework or individually (for example, you may only care about the vertical controller, not the plasma current controller).

As can be seen this is quite a large PR and includes many small fixes to the FreeGSNKE ecosystem. The main changes related to the virtual PCS are the:

  • "freegsnke/control_loop" directory, which contains the PCS class ("pcs.py"), the individual modules that handle the different aspects of plasma control in this class (e.g. the "_category.py" files), and some "useful_functions.py" that enable all of the above.
  • Example11 notebook which demonstrates how to use the new virtual PCS with the evolutive solver in the MAST-U-like machine.

Other changes:

  • Example5 has been renamed to Example5a (to make way for two new notebooks Example 5b and 5c).
  • Example5b demonstrates how to use the (linear) evolutive solver without solving the full Grad-Shafranov equation at every time step (for rapid simulations to check scenario feasibility).
  • Example5c demonstrates how to use the (linear) evolutive solver (with or without solving GS at each step) but with automatic relinearisation throughout the simulation (i.e. updating the internal Jacobian matrices).

Here we can see a few screenshots from Example11 demonstrating the control of plasma current, shape parameters, and vertical position in the MAST-U-like tokamak:

Plasma current control:
Screenshot 2026-03-30 at 15 24 53

Vertical position control:
Screenshot 2026-03-30 at 15 25 01

Shape parameter control:
Screenshot 2026-03-30 at 15 25 19

alasdairross and others added 30 commits June 6, 2025 15:20
…e documentation and add another abstract method to validate a supplied observable registry.
The internal state was being updated before the integral term, which is
wrong.

Many logging variables are created in this commit for testing purposes,
and new arguments are added to the ControlSolenoid class and
calculate_solenoid_delta method.
…e documentation and add another abstract method to validate a supplied observable registry.
…oss/freegsnke_private into control_loop/code_reorganising
…oss/freegsnke_private into control_loop/code_reorganising
@kpentland kpentland self-assigned this Jul 28, 2026
@kpentland

Copy link
Copy Markdown
Collaborator Author

Some comments are questions or suggestions; others require a proper fix before merging.

Apart from all the comments throughout the code, just wanted to add the code would benefit of a systematic suite of tests (I can help with this). Also, there's virtually no type hint coverage in the arguments of the methods: this would help greatly when actually using the code (some methods have +20 arguments) and for debugging purposes.

Thanks for the notes @capstayn! I've addressed them all (except for the unit tests) and will wait now for @georgeholt1 to do a quick Codex review. Maybe we can add some tests before that.

@georgeholt1

Copy link
Copy Markdown
Contributor

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c2fffd9f47

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread freegsnke/nonlinear_solve.py
Comment thread freegsnke/control_loop/systems_category.py
Comment thread freegsnke/control_loop/pf_category.py
Comment thread freegsnke/control_loop/virtual_circuits_category.py
Comment thread freegsnke/control_loop/virtual_circuits_category.py
Comment thread freegsnke/nonlinear_solve.py Outdated
@kpentland kpentland added the ready-for-final-tests Pull request is ready to run final pre-merge tests label Jul 29, 2026
@kpentland

Copy link
Copy Markdown
Collaborator Author

Thank you all for the review comments and help building this PR (it's a big one)!

Hopefully should enable some more control-orientated simulation studies!

@kpentland kpentland added ready-for-final-tests Pull request is ready to run final pre-merge tests and removed ready-for-final-tests Pull request is ready to run final pre-merge tests labels Jul 29, 2026
@kpentland kpentland added ready-for-final-tests Pull request is ready to run final pre-merge tests and removed ready-for-final-tests Pull request is ready to run final pre-merge tests labels Jul 29, 2026
@kpentland
kpentland merged commit d4e1faa into main Jul 30, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request feature request ready-for-final-tests Pull request is ready to run final pre-merge tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants