Optimize Coordinates construction and de-duplicate coordinate syntax docs#75
Merged
Merged
Conversation
…docs Coordinates.__init__ parsed the rich input syntax on every construction (~7 us even for a single point), which dominated single-point evaluations such as eq.B_R(R, Z) (~half of the 25 us call) and the field-line tracer RHS, which builds three Coordinates objects per ODE evaluation. Performance: - Add Coordinates.from_coords() classmethod as the canonical rich-syntax factory; Coordinates.__init__ now takes a fast path for the common case of 1-3 positional scalars/1-D arrays in the default coordinate type and emits a DeprecationWarning for direct rich-syntax construction (named coordinates, (N, dim) arrays, non-default coord_type). - Cache cocos_coefs() with lru_cache and return a read-only mapping (it is a pure function of the COCOS index and was rebuilt per init). - Move the _valid_coordinates* sets to class attributes. - Clean up the slow parser (module-level Iterable import, single np.atleast_1d conversions, set comparison instead of permutation scans; 3D named input is now also converted with np.atleast_1d). - Migrate internal call sites (Equilibrium.coordinates, Surface/ FluxSurface, metis.py, examples, tests) to the warning-free paths. Measured: Coordinates(eq, 0.7, 0.1) 7 -> 2.1 us; kwargs construction 7 -> 3.0 us; eq.B_R(0.7, 0.1) 25 -> 20.7 us. Bulk array calls are spline-bound and unchanged. Documentation: - The coordinate input syntax was fully documented only in Coordinates.__init__ and duplicated in docs/source/coordinates.rst, while the ~44 coordinate-accepting Equilibrium methods documented it not at all (empty :param: stubs). The syntax now lives once in COORDINATES_DOC/COORD_PARAMS_DOC and a new append_to_doc decorator injects the full text into Coordinates.from_coords and Equilibrium.coordinates, and a short cross-referencing note into all coordinate-accepting Equilibrium methods; the empty :param: stubs are removed and coordinates.rst embeds the canonical docstring via automethod instead of a copy. Tests: add fast/slow path parity tests and deprecation tests; full suite 777 passed. Sphinx build warning count drops from 10 to 8 (remaining ones pre-date this change). https://claude.ai/code/session_01KvV66UPfmyCtKH71MthmWo
- coordinates.py: remove unused itertools import, fix import sort order, remove redundant `object` base class, annotate mutable class-level sets/dict with ClassVar to satisfy RUF012 - equilibrium.py: remove unused `import pleque`, collapse duplicate import blocks (F811 redefinitions introduced by the previous commit), fix import sort order https://claude.ai/code/session_012QryKbWtWjQQrWmHdhe1pR
kripnerl
pushed a commit
that referenced
this pull request
Jun 12, 2026
Resolve conflict in pleque/core/coordinates.py: keep the Coordinates refactor from develop (PR #75) and re-apply the named logger, converting the warning print added by the refactor to logger.warning as well. https://claude.ai/code/session_01T8Bv18R1iJkgxQ7e4rTAKc
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.
Coordinates.init parsed the rich input syntax on every construction
(~7 us even for a single point), which dominated single-point evaluations
such as eq.B_R(R, Z) (~half of the 25 us call) and the field-line tracer
RHS, which builds three Coordinates objects per ODE evaluation.
Performance:
factory; Coordinates.init now takes a fast path for the common case
of 1-3 positional scalars/1-D arrays in the default coordinate type and
emits a DeprecationWarning for direct rich-syntax construction
(named coordinates, (N, dim) arrays, non-default coord_type).
(it is a pure function of the COCOS index and was rebuilt per init).
np.atleast_1d conversions, set comparison instead of permutation scans;
3D named input is now also converted with np.atleast_1d).
FluxSurface, metis.py, examples, tests) to the warning-free paths.
Measured: Coordinates(eq, 0.7, 0.1) 7 -> 2.1 us; kwargs construction
7 -> 3.0 us; eq.B_R(0.7, 0.1) 25 -> 20.7 us. Bulk array calls are
spline-bound and unchanged.
Documentation:
Coordinates.init and duplicated in docs/source/coordinates.rst,
while the ~44 coordinate-accepting Equilibrium methods documented it
not at all (empty :param: stubs). The syntax now lives once in
COORDINATES_DOC/COORD_PARAMS_DOC and a new append_to_doc decorator
injects the full text into Coordinates.from_coords and
Equilibrium.coordinates, and a short cross-referencing note into all
coordinate-accepting Equilibrium methods; the empty :param: stubs are
removed and coordinates.rst embeds the canonical docstring via
automethod instead of a copy.
Tests: add fast/slow path parity tests and deprecation tests; full suite
777 passed. Sphinx build warning count drops from 10 to 8 (remaining
ones pre-date this change).
https://claude.ai/code/session_01KvV66UPfmyCtKH71MthmWo