Skip to content

Large refactor -- replace jitclasses and the relaxation solver with only functions and an explicit solver, pedagogical usability pass#32

Merged
matt-pharr merged 14 commits into
mainfrom
large_refactor
Jul 22, 2026
Merged

Large refactor -- replace jitclasses and the relaxation solver with only functions and an explicit solver, pedagogical usability pass#32
matt-pharr merged 14 commits into
mainfrom
large_refactor

Conversation

@matt-pharr

Copy link
Copy Markdown
Collaborator

Three main changes here:

  • Explicit power balance solver is more stable than and much faster than the relaxation solver used previously, and is much simpler. No longer iterates until a solution within tolerance is found, just takes an algebraic root. This method is superior for all but unfixed impurity cases.
  • Removed jitclasses from the code, which are unable to be cached. This was the single biggest thing affecting runtime. Before, would need to be recompiled every run; now, the compiled code is cached and therefore one popcon takes ~ 1s from start as opposed to paying the 30s precompile time.
  • Fixed a number of bugs and problems, and refactored for usability. Added pyproject.toml to avoid python dependency issues and enable packaging. Added relative gfile name resolution. Updated for numpy 2.0. Fixed the current calculations which were missing a 1/mu0 and incorrectly assumed to be in MA instead of Amps, causing a significant but O(1) disagreement.

Includes a large rewrite of the main source code.

matt-pharr and others added 14 commits July 17, 2026 14:02
- Updated pyproject.toml to use hatchling as the build backend.
- Added xarray and contourpy as dependencies.
- Specified optional dependency for netCDF4.
- Defined project scripts for CLI entry point.
- Excluded unnecessary files from the build.
- Updated uv.lock to reflect new dependency versions and editable source.
- Power balance: make diagnostics consistent with the closed-form solver.
  populate_outputs/_par and single_point now subtract P_synch from Pheat, and
  Ploss = Pconf + Pbrems + Psynch, so Pheat == Wtot/tauE at every solved point
  and Psol/f_rad agree between the grid and single_point. Paux and Q unchanged.
- _W_tot_prof: use the electron profile (ID 1) for the electron energy term
  instead of the ion profile (ID 2).
- __check_settings: reject a scaling law with Pheat_alpha == -1, which makes
  the closed-form (W_tot/K)**(1/(1+alpha)) singular, instead of a NaN grid.
- NSF example notebook: replace the stale 5-arg single_point call with the
  current signature.
- README: drop the deleted environment.yml/conda instructions, add pip -e .
- pyproject: pin numba>=0.60 (np.trapezoid in njit, cache=True + parallel=True).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ME7GDe8m85XX9WBMyDFWQo
- Introduced `generate_golden.py` to regenerate the golden regression file.
- Created `helpers.py` for shared setup and utility functions for tests.
- Added `test_invariants.py` to validate physics consistency across runs.
- Implemented `test_regression.py` to ensure output matches golden values.
- Developed `test_validation.py` to validate settings and reject bad configurations.
- Updated `uv.lock` to include new dependencies for testing.
Set each runtime dependency to the lowest version that installs and passes the
test suite, verified with a uv resolution sweep (lowest-direct vs highest) across
Python 3.10-3.14. numpy 2.0 (for np.trapezoid) is the hard gate and forces the
numpy-facing packages up to their first numpy-2-compatible release.

- numba>=0.61 (was 0.60): 0.60 cannot compile np.trapezoid in njit, so the
  previous floor would fail at runtime.
- scipy>=1.13, matplotlib>=3.9, contourpy>=1.2.1: first releases allowing numpy 2.
- pyyaml>=6.0.2: 6.0/6.0.1 sdists fail to build on Python 3.12+.
- xarray>=2023.9.0: lowest verified working under numpy 2.
- requires-python raised to <3.15; 3.14 passes on current dependencies.

uv.lock relocked to match.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ME7GDe8m85XX9WBMyDFWQo
@matt-pharr
matt-pharr merged commit 1816ae2 into main Jul 22, 2026
2 checks passed
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.

1 participant