Skip to content

Conversation

@Aman-codes0-0
Copy link

Navigate to the GitHub pull request creation page and create a new pull request.

URL to visit: https://github.com/Aman-codes0-0/torax/pull/new/fix_imas_loader_test

Once the page loads:

  1. Fill in the PR title: "Fix issue Loading IMAS geometry from equilibrium ids object is incompatible with saving config to output #1744: IMAS geometry serialization with equilibrium_object"
  2. Fill in the PR description with the following content:

Summary

Fixes #1744 - Loading IMAS geometry from equilibrium_object is now compatible with saving config to output.

Problem

When using equilibrium_object (IDS object) in IMAS geometry configuration, the simulation would fail during output serialization because IDS objects cannot be JSON-serialized.

Solution

Added a custom Pydantic @model_serializer to the IMASConfig class that:

  • Excludes the equilibrium_object field from serialization
  • Logs a warning when equilibrium_object is used to inform users
  • Maintains full backward compatibility with imas_filepath and imas_uri

Changes

Modified Files

  • torax/_src/geometry/imas.py: Added custom serializer and imports
  • torax/_src/geometry/tests/imas_test.py: Added unit tests for serialization

New Files

  • test_issue_1744_fix.py: Standalone test script demonstrating the fix

Testing

Added two new unit tests:

  1. test_imas_config_serialization_with_filepath - Verifies normal serialization still works
  2. test_imas_config_serialization_excludes_equilibrium_object - Verifies the fix for Loading IMAS geometry from equilibrium ids object is incompatible with saving config to output #1744

Backward Compatibility

✅ All existing functionality preserved
✅ No breaking changes
✅ Existing tests continue to pass

theo-brown and others added 30 commits December 3, 2025 14:49
- Retune parameters to account for new He impurity
- Remove neoclassical transport, pending further verification (e.g. Shaing corrections on axis)
- Remove Bremsstrahlung, which was wrongly included
- Improve comments
This commit addresses issue google-deepmind#529 by integrating ICRH minority species
with the plasma composition system, ensuring physical consistency across
all plasma calculations.

Changes:
- Add optional 'minority_species' parameter to IonCyclotronSourceConfig
  that allows specifying which species in plasma_composition to use as
  the ICRH minority (e.g., 'He3', 'D', 'T')
- Add _get_minority_concentration_from_composition() helper function that
  extracts minority concentration from plasma composition, supporting:
  * Minority species in main ions (for hydrogenic species)
  * Minority species in impurities (for helium species)
  * All three impurity modes: fractions, n_e_ratios, n_e_ratios_Z_eff
- Update icrh_model_func() to read minority concentration from
  plasma_composition when minority_species is set
- Maintain backward compatibility: existing configs using
  minority_concentration parameter continue to work

Testing:
- Add test_source_with_minority_species_from_composition() to verify
  new functionality with He3 minority in impurities
- All existing ICRH tests pass (backward compatibility confirmed)
- All 651 source tests pass (no regressions)

This implementation completes the first task in issue google-deepmind#529:
"Map ICRH minority to either main-ion (if hydrogenic) or impurity (if He)"
PiperOrigin-RevId: 841156742
It was an omission earlier that divertor_domain was not in the Pydantic config. The default lower_null was being used in the internal functions.

PiperOrigin-RevId: 841161054
Before it was a vector of state variables. The actual residual used for the Newton solver convergence is a scalar.

PiperOrigin-RevId: 841163789
PiperOrigin-RevId: 841165700
This results in differences for the TGLFNN-UKAEA test case.
	T_i: Mean abs diff: 4.76e-01, mean relative diff: 3.25e-02
	T_e: Mean abs diff: 5.07e-01, mean relative diff: 3.17e-02
	n_e: Mean abs diff: 1.91e+17, mean relative diff: 2.11e-03
	psi: Mean abs diff: 4.79e-01, mean relative diff: 2.77e-02
	q: Mean abs diff: 2.24e-02, mean relative diff: 7.97e-03

PiperOrigin-RevId: 841527882
Parts requiring specific discussion on implementation left to be reviewed in another PR
The data has been moved since 1.1.1 but the colab installs from the version on PyPI.

PiperOrigin-RevId: 841725848
Otherwise `import torax` fails when installing TORAX from source without the optional dep.

PiperOrigin-RevId: 841734235
…put_core_profiles_coupling

PiperOrigin-RevId: 842152033
This follows the description of the rotation rule from the original QLKNN paper (van de Plassche K.L. 2020). The application of the rotation rule is gated by a flag that is false by default.

Validation of this rule will be required for both QLKNN10D and QLKNN_7_11 before we can enable it by default. It is possible that the rule cannot be directly applied to QLKNN_7_11 and requires further work.

PiperOrigin-RevId: 842207600
PiperOrigin-RevId: 842245809
- Add smooth transition between models
- Fix conversion from psi with 2pi factor
- Tune default parameters for an 'ok' match with NCLASS on STEP and ITER cases
- Add regression test
Needed because MEQ postprocessing does not work for all geometries and fallbacks are needed for robustness.

The `_resolve_param` helper now checks if the value provided by the Geometry object is valid (non-zero and not NaN). If the Geometry value is invalid, it falls back to the value provided in the ExtendedLengyelConfig. If no fallback is available in the Config, an error is raised.

PiperOrigin-RevId: 842254161
PiperOrigin-RevId: 842283315
Nush395 and others added 29 commits January 9, 2026 03:47
…_grid`.

I'm not sure of the exact behaviour but it's possible we're overriding the properties by doing this at the moment.

PiperOrigin-RevId: 854125011
… variable.

At the moment we assume the face values for the other variable can be linearly extrapolated from the cell values but this might not always be the case. e.g. for rmid if the underlying intermediate has greater resolution than our grid resolution this might yield incorrect values.

PiperOrigin-RevId: 854125699
…hanging

If a min_dt was reached computations could hang as too many steps were performed and the end state was never reached
Other errors such as NAN etc generally cause a MIN_DT on the next step so this is a bit of a catch-all for all the errors

Check for the other errors first as MIN_DT is the least informative and can often be caused by other errors

PiperOrigin-RevId: 854235567
…_imas_loader

PiperOrigin-RevId: 854236534
- Avoid using newton-raphson when not needed - aka in update tests
- Move slow gradient tests to their own file
- Remove the transport model from the radiation collapse to streamline

PiperOrigin-RevId: 854240055
…ion-fractions

PiperOrigin-RevId: 854353254
This change also introduces a validation module for IMAS tools within which we can home validators for different IDS objects.

PiperOrigin-RevId: 854566069
…rs versus arrays etc

PiperOrigin-RevId: 855158526
PiperOrigin-RevId: 855260677
The main ion information previously needed from RuntimeParamsProvider is no longer required in this function, allowing for the removal of the dependency on build_runtime_params.

PiperOrigin-RevId: 855428716
Introduces a dW_dt_smoothing_time_scale parameter in the numerics config to control an exponential moving average for dW/dt. The smoothed dW/dt is now used in the calculation of P_SOL terms and the energy confinement time (tauE). The raw dW/dt is still available as a separate output, for backwards compatibility and also helping with judging the impact of the smoothing.

Sim tests regenerated due to modified post processed outputs.

P_SOL and P_loss terms with dW/dt verified against RAPTOR.

PiperOrigin-RevId: 855645290
Tests for `gaussian_profile` and `exponential_profile` functions:
- Volume integrals equal the specified `total` parameter
- Gaussian profiles peak at the specified `center` location
- Profile shapes respond correctly to `width` parameters
- Output shapes match the geometry grid
…imas_core_sources

PiperOrigin-RevId: 856083552
This change moves the `min_rho_norm` parameter, used for axis extrapolation in psi calculations, from a hardcoded constant to a field in the `Numerics` configuration. All functions in `psi_calculations.py` that use this value now accept it as an argument, and calls to these functions are updated to pass `runtime_params.numerics.min_rho_norm`.

PiperOrigin-RevId: 856140920
…ources-formulas-tests

PiperOrigin-RevId: 856177150
PiperOrigin-RevId: 856207243
…s new function.

PiperOrigin-RevId: 857066892
Added cached_property to computed `CellVariable` quantities. This was very important for not blowing up compile times.

PiperOrigin-RevId: 857145577
…grids.

For face_grad we interpolate between sets of three points in a consistent way that is accurate to second order differences.

PiperOrigin-RevId: 857219014
…29-arbitrary-ions

PiperOrigin-RevId: 858124963
…k-(issue-1358)The-plotlib_run.py-

PiperOrigin-RevId: 858135062
This change modifies the CoreProfiles structure to include the full ChargeStateInfo object, calculated during the core profile initialization and updates. A new cached property, impurity_density_scaling, is added to CoreProfiles to provide the scaling factor needed for true impurity density calculations, avoiding redundant computations in various source and output modules.

PiperOrigin-RevId: 858172360
The definition of `toroidal_velocity` is changed from linear velocity (m/s) to angular velocity (rad/s). The calculation of the radial electric field (Er) in `rotation.py` is updated to reflect this change by multiplying the angular velocity by the major radius. Documentation and type hints are also updated to specify "toroidal angular velocity" and units of [rad/s].

PiperOrigin-RevId: 858292690
…librium_object from JSON output

- Added @pydantic.model_serializer to IMASConfig class
- Excludes non-serializable equilibrium_object field during serialization
- Added warning logging when equilibrium_object is used
- Added unit tests to verify serialization works correctly
- Maintains backward compatibility with imas_filepath and imas_uri

This fix allows IMAS geometry to be loaded from equilibrium_object
without causing serialization errors when saving config to output.
@google-cla
Copy link

google-cla bot commented Jan 20, 2026

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.

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.