Skip to content

Optimize Coordinates construction and de-duplicate coordinate syntax docs#75

Merged
kripnerl merged 3 commits into
developfrom
claude/coordinates-init-optimization-f2rrvs
Jun 12, 2026
Merged

Optimize Coordinates construction and de-duplicate coordinate syntax docs#75
kripnerl merged 3 commits into
developfrom
claude/coordinates-init-optimization-f2rrvs

Conversation

@kripnerl

Copy link
Copy Markdown
Owner

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

claude and others added 3 commits June 10, 2026 14:05
…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 kripnerl merged commit 92581c9 into develop Jun 12, 2026
8 checks passed
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants