Skip to content

Speed up PCS waveform evaluation - #95

Merged
kpentland merged 5 commits into
mainfrom
speed-pcs-interpolation
Aug 14, 2026
Merged

Speed up PCS waveform evaluation#95
kpentland merged 5 commits into
mainfrom
speed-pcs-interpolation

Conversation

@nicamo

@nicamo nicamo commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Summary

Reduce repeated interpolation overhead in the PCS control-loop hot path without changing waveform semantics or public calling syntax.

Changes

  • add a lightweight ConstantInterpolant for waveforms that are constant in time
  • use it for constant step and spline waveforms while preserving scalar and array output shapes and derivative compatibility
  • construct spline derivatives whenever controller interpolants are rebuilt
  • reuse cached derivatives in shape, systems, and virtual-circuit controller evaluations
  • add focused regression tests for constant waveform output shapes and derivative reuse

Motivation

PCS controllers may evaluate the same interpolants many times between equilibrium solves. Previously, derivative objects were reconstructed on every evaluation, and constant schedules still passed through general SciPy interpolators.

Performance

Focused microbenchmarks on this branch gave:

  • cached spline derivative evaluation: about 5.9x faster
  • constant step waveform evaluation: about 3.4x faster
  • constant spline evaluation: effectively unchanged

The expected end-to-end scenario gain is modest because Grad-Shafranov solves dominate runtime. The benefit is localized to PCS evaluation and grows when many PCS substeps are performed per equilibrium step.

Compatibility

  • no public API changes
  • non-constant waveforms retain the existing SciPy interpolation path
  • constant interpolants preserve scalar and array output shapes
  • cached derivatives are rebuilt whenever interpolants are updated

Validation

python -m pytest -q freegsnke/tests/test_control_loop_interpolation.py

Result: 3 passed.

@nicamo
nicamo changed the base branch from streamlining to main August 4, 2026 11:48
@kpentland kpentland self-assigned this Aug 14, 2026
@kpentland kpentland added the enhancement New feature or request label Aug 14, 2026

@kpentland kpentland left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Very nice - squeezing a little bit more efficiency!

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

2 participants