Repository navigation
ForceFreeStates - BUGFIX! - Trigger the Gaussian reduction on the conditioning of U₁ and factor U₁ in the plasma energy matrix - #520
Conversation
|
cc-ing @logan-nc @matt-pharr since this would basically fundamentally change the decades-old approach of how fixups are done in ForceFreeStates. After a lot of investigation/tests, it seems that the growth oriented reduction does not properly capture when a fixup is needed. Instead, the condition number of the displacement columns is more accurate, producing good numerics. Specifically, this fixes the Solov'ev case, which has a higher alpha (Frobenius coefficient in the expansion) at the singular surfaces, and was giving garbage as And on a related note, I've verified and tested that the 3D code also has this same issue (but worse) and is fixed by this method |
|
I'm happy to implement tested improvemlike this! this! The fixup is the magic sauce, so having our own recipe is a good result of the rewrite effort |
|
@jhalpern30 be sure to post some plots highlighting the results, a table is nice but a plot is a much better record! |
|
@matt-pharr figures are in the artifact linked in in the description |
d-burg
left a comment
There was a problem hiding this comment.
The mechanism is convincing to me: columns that grow alike and turn parallel are invisible to a spread test, and the new unit tests separate the two triggers nicely. The storage overflow and the U₂ / lu(U₁) fix are clear bug fixes. I'm less sure the evidence is there yet for replacing the reduction trigger itself.
My and claude's brains merged into a disconcerting synthetic hybrid network and yielded the following items:
Blocking
- Migration. The title carries
!and Migration starts with "none", which is what fails the title check, and substantively a forward-path deck with a hand-setucritis reinterpreted without a warning. Suggested text: "Migration: forward-integrator decks that setucritby hand should return it to the default 1e3. The value is now compared with a condition estimate of the column-normalized U₁, not with the spread of column-norm growth; small values such as 10 now reduce very often, and values above about 1e10 lose digits. Riccati decks need no change." - Regression report. The code block is empty and the stamp (
1dc6138aa) predates the last two commits. This changes when every forward run reduces and how W is formed for every integrator, so I'd like the full harness now,d50a5e5b6against the current head as two git refs, especially the Riccati, perturbed-equilibrium, kinetic Solovev and multi-n cases. Rerunning at merge time is cheap; reviewing blind is not.
Evidence I'd want for "changes the decades-old approach"
- Every error in the table is measured against the same build with
ucrit= 1, which shows self-consistency, not correctness. One independent reference per headline row would help: the Riccati integrator on the same Solovev decks atsingfac_min1e-8, or a tolerance-converged or Fortran value where available. The figures sit behind a link "shared on request"; the numbers the argument rests on should be in the PR. - Per case: accepted steps, number of reductions, the largest estimate at the moment of reduction, wall time and peak memory against #489's head. Without reduction counts nobody can judge 1e3 against 1e6, and with unbounded storage a run that reduces every other step is a memory problem the old 100-slot cap used to hide.
- Cases not yet covered: an ideal-unstable equilibrium where det U₁ passes through zero inside the plasma (U₁ is singular there for a physical reason, so the trigger fires whatever its threshold), a kinetic run, and the largest multi-n deck.
On your five decisions
- 1e3 vs 1e6: undecided until the reduction counts are shown; leaning 1e6 for the forward path. The stated reason for 1e3 is about Riccati sharing the key, not about the forward path.
- One key, two meanings: I'd add a forward-path key. Decks are reinterpreted silently, switching
integratorchanges what the same number means, and the shared key is already forcing a default neither path would pick on its own. The!in the title makes a new key cheap now. - cond(U₁) rather than cond([U₁; U₂]): agree; the elimination pivots on U₁ and W inverts U₁.
- Elimination rather than an (S, I) or QR reset: agree for this PR. Worth a follow-up issue: the elimination never rescales columns, which is why the norms span 1e110 in the first place.
- No test for the
lufix: disagree; a 4×4 matrix reproduces it (inline).
Suggestion: the storage fix and the lu fix stand on their own and are easy to verify; the trigger change is a design decision that needs the evidence above. Splitting them would let the two bug fixes go in quickly on #489.
Small, outside the diff
- The
OdeStatefield docstrings inEulerLagrange.jlstill give the reduction arrays fixed shapes ((numpert_total, numunorms_init), "lengthnumunorms_init"); they are initial capacities now.docs/src/stability.mdstill callsnumunorms_inita "renorm checkpoint budget". - The comment at
Riccati/Driver.jl:77still quoteswp = u[:,:,2] / u[:,:,1]. - The description's notes refer to
column_condition, which the last two commits inlined.
logan-nc
left a comment
There was a problem hiding this comment.
One item not in the six open threads, on the kinetic crossing. compute_solution_norms! (head 2baa20b, EulerLagrange.jl:1007) returns early when odet.new && !at_ideal_crossing, resetting the baseline. The kinetic-crossing call at EulerLagrange.jl:847 passes sing_flag = true with no resonant_rows, so when the step before the surface already reduced (odet.new == true), that crossing resets and skips the reduction the flag is supposed to force. Fortran GPEC closed the same hole in PrincetonUniversity/GPEC#332 (fix_required = sing_flag ahead of the branch). The early return is pre-existing on develop, but this PR owns the trigger now, so if odet.new && !at_ideal_crossing && !sing_flag (or passing the surface's rows from the kinetic path too) belongs here.
|
@jhalpern30 what is the status on this? Can this make it in for 2.0.0? |
|
@logan-nc thoughts? This seems like it would be valuable. If Jake doesn't have time before APS then I guess this could be 2.1? Or someone else could get into the weeds on this? |
Probably not. Daniel raised some valid points that I don't have the time/effort to look into before APS |
|
@jhalpern30 @matt-pharr it's time to face reality on v2.0 scope and it seems reasonable that such a fundamental change could come in a minor version update with clean validation. That lets us release the "decades-old approach" for warm familiarity and creates a clean historical record of the improvement. I am not afraid of releasing 2.1 in Dec. so please do keep this on your todo list for immediately post APS. |
|
@jhalpern30 The kinetic-crossing hole I flagged above (Fortran GPEC PR 332) is fixed separately in #626, so it doesn't wait on this PR's trigger change. In This PR rewrites the trigger in the same function, so whichever of the two lands second needs a small rebase there. The changes compose: #626 only replaces the early return, and your conditioning test slots in where the |
…ditioning of U₁ and factor U₁ in the plasma energy matrix - `plasma_energy_matrix(u, psio)` forms W_p = U₂U₁⁻¹/ψ₀² by pivoted LU of U₁; `U₂ / U₁` factored U₁ᴴ, whose rows carry the column-norm spread, so partial pivoting failed on graded columns - Forward reduces when the 1-norm condition number of U₁ with unit columns exceeds `renorm_threshold` (default 1e6), instead of on the column-norm growth ratio; a large norm spread with independent columns no longer reduces - Decks drop the `[Forward] renorm_threshold = 1e3` pin; docs updated - Tests: 4×4 graded pivot test, conditioning trigger cases, threshold ladder in fullruns
b8e1e71 to
a395b14
Compare
|
Thanks, this reshaped the PR. Rebased and rescoped; here is where each item landed. Blocking
Evidence
Your five decisions
Split: the storage fix went to #662; this PR is now the Small items: the |
|
@logan-nc Rebased onto develop with #626 and #602. The conditioning test replaces the |
|
Hi all - human Jake here. I think this is now ready to go. Incorporated Daniel's comments, got something I think is fairly robust/clean in the cond(U_1) estimate and affects runtime in the < 2% range / doesn't break on any case I can find. This is now stacked on 662 which has the reduction storage resizing that was originally on this branch. Ready for another look through A short artifact to remind what the main results were here: https://claude.ai/artifact/DCuvCWYrkv2Pe7m3rNHurT |
d-burg
left a comment
There was a problem hiding this comment.
@jhalpern30 Thanks, this answers everything from my October review. The Riccati et₁ on n = 3 is the independent reference I was after, and the reduction counts settle 1e6 for the forward path. Splitting the storage fix into #662 makes this PR easy to read. I checked the head (a395b14aa):
- The trigger normalizes by the current column norms before taking
cond(·, 1), and still sets the pivot order from the growth since the last reduction. An exactly singular u₁ givescond = Infand reduces, which is the right behavior. fix_required = sing_flagwith no early return, so Logan's kinetic-crossing hole is closed.- Every shipped deck that still sets
renorm_thresholddoes so under[Riccati], so no deck is silently reinterpreted.
Before merge (both mechanical, and both CI failures):
- Stamp. The release note needs
_(harness @ <sha>)_at the head. The report ran at an earlier commit plus a spot check, and the gate wants a run at the stamped commit with nosrc/changes after it. - Formatter. JuliaFormatter wants
(L.*exp10.(range(110, 0; length=4))')attest/runtests_eulerlagrange.jl:392.
Non-blocking:
- On the sf 1e-8 test, I take the CI-time point about an eight-run ladder. A single pair would still pin the motivating case, though: the default threshold against threshold 1.0 at
singfac_min1e-8, with the stock ladder left as is. If even two runs are too slow for CI, fine as is. docs/src/stability.mdsays "condition number of u₁" in two places. "with unit columns" matters here, asIntegrators.jlsays.compute_solution_norms!still ends with "Port of Fortranode_unorm". The trigger no longer matches it, so I'd drop that line.
Approving. It lands after #662, which it's stacked on.
|
@d-burg thanks. I will clean up CI once 662 is merged. |
|
Poll @d-burg @matt-pharr @jhalpern30 - I have my ai proactively fix clear bugs and minor annotation cleanup when certain. In the review above, it could have made this pr g2g and saved a full iteration. An iteration, despite being small, could take weeks depending on how busy a author is and how high a priority the pr is for them. On the other hand, its always possible an author disagrees and has to revert... but that is doable and the commit diff is more clear then an ai block of verbose text? What do you prefer? Proactive help or just listing requested changes even when minor formatting and such? If the second, at least have your ai enter any 1-3 line changes as "suggest changes" inline so the author can just click accept as they read through. Please and thank you. |
|
@logan-nc i think the best etiquette here is if you can't work something and you don't feel strongly about custodianship then you should precisely document your intentions, reasoning, and results, and then deassign yourself from the PR. That way we can distinguish from places where the author would prefer the PR is/is not touched by someone else yet. This can also be achieved with a DM. |
Closes #490 and enables #481. Stacked on #662 (base
bugfix/high-n-sing-start-qlow-unorm), which now carries the reduction-storage fix; retarget todeveloponce #662 merges.Two changes to the forward integrator:
plasma_energy_matrix(u, psio)forms W_p = U₂U₁⁻¹/ψ₀² by pivoted LU of U₁. The oldU₂ / U₁factored U₁ᴴ, whose rows carry the column-norm spread, so partial pivoting failed on graded columns (relative error 0.15 on the 4×4 case from review, 2e-16 now). Used byfree_run,free_compute_totalandbuild_result.cond(U₁ ./ ‖columns‖, 1), exceeds[Forward] renorm_threshold(default 1e6), instead of when column-norm growth spreads. Columns that grow alike and turn parallel now trigger; a large norm spread with independent columns no longer does. Riccati is unchanged ([Riccati] renorm_thresholdkeeps its entry-size meaning and its 1e3 default).singfac_minsingfac_min1e-8, et₁ vs reduce-every-stepsingfac_min5e-4, on #676's headruntests_fullruns.jl)Release note
plasma_energy_matrix, at rounding level (≤ 2e-13).[Forward] renorm_thresholdby hand should drop it and take the new default 1e6. The value is now a limit on the condition number of U₁ with unit columns, not on the spread of column-norm growth: small values such as 10 reduce very often, and values above about 1e10 lose digits. Riccati decks need no change.Regression report
Full harness, all 28 cases, on Landau (2026-11-18), develop + #662 (
b037e9323) against this change at the time; the later commits only rename, inline and restructure, and a spot check at heada395b14aa(solovev_n1,diiid_multi_n) reproduces those values bit for bit (all 43 quantities, runtime aside).lar_ggj_*.diiid_kinetic_multi_net₁ 6e-9); accepted steps +0.3 to +3%; runtime within noise.diiid_error_fieldEFC scan 1.4e-5).tj_kinetic_calculatedrawpe_clebsch_{psi1,alpha}norms +7% andb_theta_reg+1.2%, while its NTV torque moves 3e-4 and the energies ≤ 5e-6. These are raw matrix norms on a changed step grid; not yet compared on a common grid.Unit tests:
runtests_eulerlagrange.jl224/224 ata395b14aa; CI runs the full suite.