Repository navigation
Collapse duplicated loss APIs - #206
Merged
Merged
Conversation
rogeriojorge
marked this pull request as ready for review
November 11, 2026 02:40
rogeriojorge
marked this pull request as draft
November 11, 2026 02:40
rogeriojorge
marked this pull request as ready for review
November 11, 2026 03:01
This was referenced Nov 13, 2026
eduardolneto
approved these changes
Nov 13, 2026
eduardolneto
left a comment
Contributor
There was a problem hiding this comment.
This seems correct and reducing number of lines.
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.
Replaces the four
Tracingloss methods with one and the sevenloss_particle_*functions with a shared trace helper.dynamics.py:
loss_fraction_BioSavart,loss_fraction_BioSavart_collisions,loss_fractionandloss_fraction_collisionsbecomeloss_fraction(boundary=None, r_max=1.0). Withboundary=Nonea particle is lost ats >= r_max; with aSurfaceClassifierit is lost when the signed distance goes negative. Collision models return the two extra arrays (energy and position at loss), decided fromself.model.objective_functions.py: One private
_orbitdoes the trace and the axis offsets; eachloss_particle_*keeps its name and is a few lines. Trace options (timestep,maxtime,num_steps,trace_tolerance,model,boundary) are now keyword-only through**trace, andtarget_iotainloss_particle_iotamoved to the second positional slot. No example imports these functions (the two optimization examples define their own), so nothing else changed excepttrace_particles_interpolated_dipoles.py, which now callsloss_fraction(classifier).API changes: The three removed
Tracingmethods are gone;loss_fraction(r_max)positional use must becomeloss_fraction(r_max=...).Equivalence: Before/after run on main vs this branch (QA VMEC and QH coils + classifier, plain and collision models, several
r_max, all seven objectives plus a non-defaulttarget_iota): 51 output arrays, all bitwise identical. Tests pass withJAX_ENABLE_X64=1 pytest -n 2 tests.External callers:
gh search code --owner uwplasmaforloss_fraction_BioSavart,loss_fraction_collisionsandloss_fraction(finds onlyessos/dynamics.pyandtrace_particles_interpolated_dipoles.py(both updated here) in the whole organisation; no other uwplasma repository uses them. No other searched source calls them.Analytic test:
test_loss_fraction_of_analytic_gyro_orbitsbuilds gyro-orbits of radius rho about guiding centres at distance d from the origin and checksloss_fractionagainst a sphere of radius R: a particle is lost iff d + rho > R, one starting outside is lost at t = 0 (first time, not -1), and a particle with d + rho < R stays confined; ther_maxbranch is checked on the same orbits.Overlap: #193 also edits
dynamics.pyandobjective_functions.py, but I found no changes to the loss methods orloss_particle_*in its diff, so I expect at most a trivial textual conflict.Diff: 82 additions, 252 deletions.
Reviewer commands:
JAX_ENABLE_X64=1 python -m pytest -q -n 2 tests(391 passed, 1 xfailed on Python 3.13; 386 passed, 5 skipped, 1 xfailed on Python 3.10 with JAX 0.6.2) andpytest tests/test_dynamics.py -k analytic_gyro. Limit: the equivalence script compares against main, so it only covers the configurations listed above.