Skip to content

Fix empty checkpoints for custom JAX mappings#1199

Open
MilesCranmerBot wants to merge 4 commits into
MilesCranmer:masterfrom
MilesCranmerBot:fix-1198-custom-jax-pickle
Open

Fix empty checkpoints for custom JAX mappings#1199
MilesCranmerBot wants to merge 4 commits into
MilesCranmer:masterfrom
MilesCranmerBot:fix-1198-custom-jax-pickle

Conversation

@MilesCranmerBot
Copy link
Copy Markdown
Contributor

Summary

  • omit non-picklable custom JAX/export mappings from checkpoints
  • write checkpoints atomically so failed pickles do not leave empty files
  • fall back to CSV backups when loading an empty/corrupt checkpoint

Fixes #1198

Tests

  • uv run --python /usr/bin/python3.12 --with pytest --with 'jax[cpu]>=0.4,<0.6' --with 'juliacall>=0.9.28,<0.9.29' --with 'sympy>=1,<2' --with 'pandas>=0.21,<4' --with 'numpy>=1.13,<3' --with 'scikit-learn>=1,<2' --with 'click>=7,<9' --with 'typing-extensions>=4,<5' python -m pytest pysr/test/test_jax.py -k "checkpoint or empty"\n- python3 -m compileall -q pysr/sr.py pysr/test/test_jax.py

@codecov
Copy link
Copy Markdown

codecov Bot commented Jun 1, 2026

Codecov Report

❌ Patch coverage is 91.46341% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 94.34%. Comparing base (14cbe96) to head (aea7cde).

Files with missing lines Patch % Lines
pysr/sr.py 91.46% 7 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1199      +/-   ##
==========================================
+ Coverage   94.24%   94.34%   +0.09%     
==========================================
  Files          21       21              
  Lines        1686     1714      +28     
==========================================
+ Hits         1589     1617      +28     
  Misses         97       97              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@MilesCranmer
Copy link
Copy Markdown
Owner

@MilesCranmerBot it feels like we are loading up this PySRRegressor with too much stuff In particular there are a bunch of new functions here which are not really "core" operations to the regressor. I believe there is a nice way to refactor this. Please do so.

Co-authored-by: Miles Cranmer <miles.cranmer@gmail.com>
@MilesCranmerBot
Copy link
Copy Markdown
Contributor Author

Refactored in 2e59bfd: moved the checkpoint/pickle/export-column helper logic into pysr/_checkpoint.py, leaving PySRRegressor with thin call sites.

Checks run:

  • uvx pycln pysr/sr.py pysr/_checkpoint.py pysr/test/test_jax.py
  • uvx black --check pysr/sr.py pysr/_checkpoint.py pysr/test/test_jax.py
  • uvx isort --check-only pysr/sr.py pysr/_checkpoint.py pysr/test/test_jax.py
  • uv run --python /usr/bin/python3.12 --with pytest --with "jax[cpu]>=0.4,<0.6" python -m pytest pysr/test/test_jax.py -k "checkpoint_custom_jax_mapping or empty_checkpoint"

Comment thread pysr/_checkpoint.py Outdated
Co-authored-by: Miles Cranmer <miles.cranmer@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

2 participants