Skip to content

Update to VC generator in pulse design tool - #89

Merged
kpentland merged 54 commits into
FusionComputingLab:mainfrom
alasdairross:86-update-vc-generator
Aug 3, 2026
Merged

Update to VC generator in pulse design tool #89
kpentland merged 54 commits into
FusionComputingLab:mainfrom
alasdairross:86-update-vc-generator

Conversation

@alasdairross

@alasdairross alasdairross commented Jul 16, 2026

Copy link
Copy Markdown
Collaborator

This PR contains updates to Virtual Circuit generation for use in the pulse design tool. It fixes code in the vc_provider.py module in the control_loop, as highlighted in #86.
There are two main updates contained in this PR :

  1. Adding the option to use tikhonov regularisation in the matrix inversion when computing VCs.
  2. Fixing and updating the VC provider module in the control_loop.

Tikhonov inversion
By default the Moore-Penrose is used as previously, and there is an optional argument to provide an array or diagonal matrix to define the Lambda regularisation terms (see https://en.wikipedia.org/wiki/Ridge_regression for example)

The main change is in the VirtualcCircuitHandlng in virtual_circuits.py where the new matrix inversion is done.
The following methods now have an optional tikhonov_lambda argument

  • VirtualCircuitsHandling.calculate_VC()
  • PlasmaControlSystem.calculate_control_voltages()
  • VirtualCircuitsController.run_control()

VC provider
The vc_provider.py module contains a class VCGenerator which can interface with the PCS class (PCS(...,vc_generator = ,..))

  • get_vc() : a method to compute a vc matrix that can be use in the PCS control loop, to compute a 'real time' vc using the virtual circuits functionality in FreeGSNKE..
  • generate_fixed_schedule : generates a dictionary which defines a fixed schedule of custom VCs, given a list of equilibria and time stamps, which can be passed to the PCS class as circuits data (PCS(...,circuits_data = , ...) )

The example notebook example11 - pulse_design_tool.ipynb has been updated to demonstrate these new functionalities.

@alasdairross

Copy link
Copy Markdown
Collaborator Author

Need to add or modify example notebook to provide example on how to use it.

@alasdairross alasdairross changed the title 86 update vc generator Update to VC generator in pulse design tool Jul 16, 2026
@kpentland
kpentland changed the base branch from streamlining to main July 30, 2026 09:05
@kpentland kpentland self-assigned this Jul 30, 2026
@kpentland kpentland added the enhancement New feature or request label Jul 30, 2026
@kpentland

kpentland commented Jul 30, 2026

Copy link
Copy Markdown
Collaborator

PR looks good so far - I've currently only tested the 'generate_fixed_schedule' in the Example11 notebook.

Couple of things I changed to streamline:

  • removed targets_all input (as this can be taken from the initialisation of the VCGenerator class).
  • added the tikhonov_lamba option to this function call as it was missing (still need to test that feature later on anyway).
  • minor formatting and enabling printing (with verbose=True).
  • checked if generate_fixed_schedule can be used with more than one time stamp.

Will check other parts later...

@kpentland

Copy link
Copy Markdown
Collaborator

The Tikhonov regularisation for the VC calculations looks great!

I made a few adjustments in virtual_circuits.py:

  • replaced explicit use of np.linalg.inv with more stable/faster np.linalg.solve.
  • added type hints everywhere.
  • also added an extra example of how to use the Tikhonov regularisation into Example09.

@kpentland

Copy link
Copy Markdown
Collaborator

Things that still need checking:

  1. Do the VC generators work within the virtual PCS (i.e. generating freegsnke and/or emulated VCs) on the fly?
  2. Can we simplify the number of inputs passed into the PCS class calls when doing the above?

@alasdairross

alasdairross commented Jul 31, 2026

Copy link
Copy Markdown
Collaborator Author

In response to the comments above,

  1. Do the VC generators work within the virtual PCS (i.e. generating freegsnke and/or emulated VCs) on the fly?

I've added an example notebook to demonstrate this and the simulation looks to be successful.

Choice of coils/targets for calculation are now specified when initialising the VCGenerator
Update associated variable names
update VirtualCircuitProvider base class
update example 11b notebook to show new api
@alasdairross

Copy link
Copy Markdown
Collaborator Author
  1. Can we simplify the number of inputs passed into the PCS class calls when doing the above?
    I've addressed this now. The extra arguments that previously were passed in the PCS.calcluate_control_voltages are now set as attributes of the VCGenerator class.

@kpentland

Copy link
Copy Markdown
Collaborator

Ok so after some more streamlining of the inputs to the VC generators, we can successfully call them during an FPDT simulation to update VCs on-the-fly (i.e. calculate new VCs every now and again using FreeGSNKE's in-built methods).

Last thing to check will be to see if this all works when we replace the VC generator with one built from the emulated VCs. Maybe @alasdairross you can check this on your end? Hopefully should be smooth but let me know if not...

@alasdairross

Copy link
Copy Markdown
Collaborator Author

I've run the notebook with a VC generator with the neural net emulators to recompute VC's during a simulation, and that runs successfully now as well.

@kpentland

Copy link
Copy Markdown
Collaborator

Great, I've also checked and the emulated VCs runs on my side too! Barring any other comments, I'm happy to run the tests and merge.

@kpentland kpentland added the ready-for-final-tests Pull request is ready to run final pre-merge tests label Aug 3, 2026
@kpentland
kpentland merged commit 0ef7413 into FusionComputingLab:main Aug 3, 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 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.

3 participants