Speed up linearization construction - #96
Merged
Merged
Conversation
Reuse accepted finite-difference current perturbations and build independent current and profile Jacobian columns in configurable worker processes. Reset each finite-difference solve to the unperturbed plasma state and deterministic NK random state. Keep the existing relinearization trigger and full-update policy unchanged.
kpentland
approved these changes
Aug 19, 2026
kpentland
left a comment
Collaborator
There was a problem hiding this comment.
Multithreading was so needed here! Makes things much faster!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Reduce the cost of constructing and refreshing the nonlinear-solver linearization while preserving the existing relinearization trigger and full-update policy.
This also fixes an existing Lao85 profile-derivative bug on
main: whenalpha_logicorbeta_logicis enabled, the stored arrays already contain the dependent final coefficient. Passing those complete arrays back throughinitialize_profile()appends another dependent coefficient on every finite-difference profile update. The corrected path passes only the independent coefficients and letsinitialize_profile()reconstruct the dependent term exactly once.Changes
n_linearization_workerstonl_solver, defaulting to1to preserve serial behavior.dIydIcurrent columns anddIydthetaprofile-parameter columns in isolated worker processes.4/3; otherwise fall back to the original calibration path.plasma_psi, profile state, and deterministic NK random state.main.The implementation uses multiprocessing on platforms supporting the
forkstart method. The serial default remains portable.Performance
At the expensive shot-53320 step-356 checkpoint, constructing 74 current-response columns took:
378.32 swith one worker.85.57 swith six workers.This is a measured
4.42xspeedup for that Jacobian build.For perturbation reuse, the first full build is deliberately unchanged. In the measured replay, the clean second 74-column rebuild took
85.73 s; guarded reuse reduced it to approximately69 s. Later gains depend on how stale the accepted perturbations have become.A live shot-53320 replay through step 399 and five relinearizations remained within:
3.08 mmmaximum plasma-descriptor deviation.91.84 Amaximum physical active-coil deviation.These figures isolate the linearization improvements. End-to-end gains depend on how much of a run is spent rebuilding Jacobians.
Compatibility
n_linearization_workers=1preserves the existing serial route.alpha_logicand/orbeta_logicnow retain only their intended independent coefficients during finite-difference construction.Validation
python -m black --check freegsnke/python -m isort --check --diff freegsnke/python -m pytest -q freegsnke/tests/test_linearisation_perturbations.pyResult:
13 passed.