Skip to content

Add explicit check for missing j_phi in IMAS equilibrium loader#1935

Open
nytdevansh wants to merge 3 commits intogoogle-deepmind:mainfrom
nytdevansh:fix/1610-check-required-terms-imas-load
Open

Add explicit check for missing j_phi in IMAS equilibrium loader#1935
nytdevansh wants to merge 3 commits intogoogle-deepmind:mainfrom
nytdevansh:fix/1610-check-required-terms-imas-load

Conversation

@nytdevansh
Copy link

This PR adds an explicit availability check for the profiles_1d.j_phi
field when loading IMAS equilibrium data.

When j_phi is missing, TORAX previously failed downstream with a
misleading Pydantic broadcasting error. This change fails fast with a
clear, domain-specific error message instead.

Closes #1610

# spr = vpr * <1/R> / ( 2 * np.pi )
# -> Ip_profile = integrate(y = spr * jtor, x= rhon, initial = 0.0)
jtor = -1 * IMAS_data.profiles_1d.j_phi
if not np.any(jtor):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is jtor here if `the profile is missing?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the profile is missing, Jtor will be an array of zeros multiplied by -1 which the line 172 checks for with np.any(jtor), after that if the jtor is all zeros than it will raise an ValueError. Hence , stopping the execution.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, then I'd recommend validating the j_phi object directly to check if it is empty or not.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion ! That makes sense, validating j_phi directly is a better and much cleaner approach. Should I check if it exists or is non-empty before the multiplication?

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.

Add check that required terms are present in IMAS on load

2 participants