Skip to content

Conversation

@akshat3410
Copy link

Summary

Moves hardcoded sawtooth test reference values from sawtooth_model_test.py to the centralized references.json file, making them auto-regeneratable via the regenerate_torax_refs.py script.

Closes #1762

Changes Made

1. Extended regenerate_torax_refs.py

  • Added _calculate_sawtooth_crash_references() function
  • This function runs a full simulation step to trigger sawtooth crash
  • Captures post-crash T_e, n_e, and psi profiles
  • Modified main() to route sawtooth case to this special function

2. Updated torax_refs.py

  • Added sawtooth_references() function with sawtooth-specific config
  • Registered in REFERENCES_REGISTRY for auto-regeneration
  • Includes proper error handling for missing JSON data

3. Modified sawtooth_model_test.py

  • Load post-crash reference values from JSON instead of hardcoded constants
  • Removed 38 lines of hardcoded numpy arrays (_POST_CRASH_TEMPERATURE, _POST_CRASH_N, _POST_CRASH_PSI)
  • Added JSON loading in setUp() method

4. Updated references.json

  • Added sawtooth_references entry with generated post-crash values

Testing

  • All sawtooth tests pass: pytest torax/_src/mhd/sawtooth/tests/sawtooth_model_test.py -v
  • Verified test assertions use generated values correctly
  • References can be regenerated with the script (when dependencies are available)

Future Usage

When the sawtooth model changes, developers can regenerate the test references automatically instead of manually editing arrays:

python -m torax.tests.scripts.regenerate_torax_refs \
    --case=sawtooth_references \
    --write_to_file

@google-cla
Copy link

google-cla bot commented Nov 24, 2025

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@tamaranorman
Copy link
Member

Adding these to the script is good but can they be in a separate file next to the relevant tests

And then if you can sign the CLA so we can run the tests

@jcitrin jcitrin mentioned this pull request Dec 7, 2025
@akshat3410
Copy link
Author

Sure, I’ll make the changes exactly as you requested — I’ll move the additions into a separate file next to the relevant tests and update the imports accordingly. I’ll push the updated commit shortly.

@akshat3410 akshat3410 force-pushed the fix/sawtooth-test-reference-1762 branch from f01509f to d950df2 Compare December 8, 2025 09:43
@jcitrin
Copy link
Collaborator

jcitrin commented Jan 2, 2026

Please fix failing tests

@akshat3410
Copy link
Author

I'll Fix it right away.

- Extend regenerate_torax_refs.py to handle sawtooth crash simulation
- Add sawtooth_references() to torax_refs.py and REFERENCES_REGISTRY
- Update sawtooth_model_test.py to load references from JSON
- Remove hardcoded _POST_CRASH_* constants (38 lines)
- Populate sawtooth_references in references.json

Fixes google-deepmind#1762
- Create regenerate_sawtooth_refs.py next to sawtooth tests
- Create sawtooth_references.json for local reference storage
- Update sawtooth_model_test.py to use local references
- Remove sawtooth code from central regenerate_torax_refs.py
- Remove sawtooth_references from torax_refs.py and references.json

This keeps sawtooth test references co-located with the tests,
making them easier to maintain independently.

Fixes google-deepmind#1762
- Update regenerate_sawtooth_refs.py to use new get_initial_state_and_post_processed_outputs API (step_fn only)
- Regenerate sawtooth_references.json with latest main branch values

Fixes failing CI tests after rebase to latest main.
@akshat3410 akshat3410 force-pushed the fix/sawtooth-test-reference-1762 branch from d950df2 to 790cfae Compare January 3, 2026 08:40
@akshat3410
Copy link
Author

@jcitrin Fixed! Rebased to latest main, updated the API call, and regenerated references. All 3 tests pass locally. Please approve the workflow run. Thanks!

@jcitrin
Copy link
Collaborator

jcitrin commented Jan 4, 2026

Please see test errors and fix.

@akshat3410
Copy link
Author

I'll Fix it right away.

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.

Move sawtooth_model_test reference values to test_utils/references.json

3 participants