Skip to content

Conversation

@MateoBell
Copy link
Collaborator

@MateoBell MateoBell commented Oct 8, 2025

Add validators for the IMAS function to check that the required fields are properly filled in the input IDS and if not provide a clear warning.
Closes #1610.

Validation functions:

  • for profile_conditions
  • for plasma_composition
  • for geometry

Integration

  • Testing
  • see where to be called

@MateoBell MateoBell closed this Oct 8, 2025
@MateoBell MateoBell reopened this Oct 8, 2025
import torax._src.constants as constants

_PROFILE_CONDITIONS_REQUIRED_FIELDS = {
"gloabl_quantities": ["ip", "v_loop"],
Copy link
Collaborator

Choose a reason for hiding this comment

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

are there any constants from the imas-python library that can be referred to here instead of us using literal strings?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@mikesndrs can I ask your input on this ? Do you know if it exists in imas-python ?

for field in _PROFILE_CONDITIONS_REQUIRED_FIELDS["gloabl_quantities"]:
if not getattr(global_quantities, field):
# Warning or critical ?
logging.critical(
Copy link
Collaborator

Choose a reason for hiding this comment

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

I believe we'd want to raise an error here with an informative error message that the expected field is missing.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Not entirely sure about this. For geometry loader I think we'd want to raise an error but with core_profiles not necessarily. There might be cases where we want to load partially some profiles but not all from an IDS, like only electrons ones or ions ones and get the rest from elsewhere / prescribe it. In this case, it does not matter that the other fields are empty in the input IDS. Do you agree ?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah ok, yeah that makes sense. I think it would be good to converge on a minimal set of required attributes for using the profile_conditions_from_IMAS function though as that makes assumptions on certain fields being present?

Validator which should allow validation for plasma_composition and profile_conditions
Currently do not check if individual ions density are filled
@MateoBell
Copy link
Collaborator Author

Hey @Nush395, if you can have a look at this version to tell me if this goes in the right direction or not. Still needs some changes but just to know if it's worth making the changes or changing the structure.

  • I made a very generic validator which can handle all IDSs for TORAX I think. Currently adapted just to the 2 converter functions for core_profiles. Can be easily used for equilibrium as well.
  • Only checks that the fields have value, does not do further validation.
  • strict flag to make all fields required, in which case it will trigger an error and not just a warning
  • validation helper put at the beginning of the converter function to trigger validation everytime

Maybe it would be better to directly pass the validation_fields dict as an arg of the function instead of the current "target"? This way it would allow to be user defined fields.
-> What do you think of this way to validate ? Do you think we would need more specific functions for eahc IDS / help function ?
If keep it generic, should it live in another validator.py module inside imas_tools ?

Copy link
Collaborator

@Nush395 Nush395 left a comment

Choose a reason for hiding this comment

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

I'm wondering if it's actually cleaner to just do this validation explicitly. I've written out an example in #1866 to demonstrate.

I feel that is a slightly more transparent solution as you can directly see in the function what validation is being done and there aren't actually too many fields being validated. wdyt of that approach?

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