-
Notifications
You must be signed in to change notification settings - Fork 3
validation rule for sign of EM fields #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
validation rule for sign of EM fields #6
Conversation
and profiles_2d.psi.has_value | ||
and profiles_2d.r.has_value | ||
): | ||
continue |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So it will not verify (or can't do it) is any of these quantities is missing in the equilibrium?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, It will not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please note that the rule function will skip calling the compute_COCOS function if any required fields are missing, without reporting an error. @olivhoenen , do you think an error should be reported?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, an error shall not be reported in case one of these fields is missing.
But we should be able to check COCOS compliancy with DD major version without being mandatory to have ALL these fields, or have it mandatory to have a 2D profiles on a rectangular grid and profiles_2d.grid_type.index == 1
(what is the point of having 33 types of grids -- agreed it's probably too many ;-) -- if we use a single one?)
""" | ||
Validate that COCOS computed corresponds to the one in DD. | ||
""" | ||
from idstools.cocos import IDS_COCOS, compute_COCOS |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we avoid this dependency on idstools
? It's not yet open access.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also I don't understand why the rule is added into the scenarios
rulesets, IMO it shall be inside the generic
rulesets.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, we can. The cocos.py file has been available in the folder common
, and the rule validate_cocos
was moved to assets/rulesets/generic
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like it much for cocos.py
to be in common
, as this is part of the rulesets it should better be next to the rules.
imas_validator/common/cocos.py
Outdated
import imas | ||
|
||
# set cocos in the DD version from the environment | ||
IDS_COCOS = int(imas.dd_zip.dd_etree().find("cocos").text) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this correct? It needs to get the COCOS of the DD version associated with the data-entry being read. I fear that this is going to give the latest no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your comment. The latest commit validates with the DD used to write the IDS.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds a new validation rule for comparing computed COCOS values against those provided by DD in the IMAS-Validator, while also updating a related comment in an existing scenario rule.
- Updated comment in scenarios/equilibrium.py to clarify the accessed attribute.
- Introduced a new generic rule in generic/equilibrium.py to validate COCOS computation.
Reviewed Changes
Copilot reviewed 2 out of 3 changed files in this pull request and generated 1 comment.
File | Description |
---|---|
imas_validator/assets/rulesets/scenarios/equilibrium.py | Updated comment to reference global_quantities rather than only ip |
imas_validator/assets/rulesets/generic/equilibrium.py | Added validate_cocos function to compare computed COCOS with DD values |
Comments suppressed due to low confidence (1)
imas_validator/assets/rulesets/scenarios/equilibrium.py:11
- The updated comment does not reflect that the subsequent assertion still checks the 'ip' attribute. Consider updating the comment to clarify that 'ip' is being validated.
# time_slice[:].global_quantities
I'd like to propose to change the name of module from |
addapting flake8 fixing format error type annotations in cocos.py mypy style requirements for coding isort cocos validation with version_put in IDS/equilibrium fixing for a CI error fixing the docstring fixing the docstring fixing the docstring fixing the docstring fix on flake8 Update imas_validator/assets/rulesets/generic/equilibrium.py Following Copilot suggestion Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
8b3b014
to
92aba5f
Compare
The cocos.py file was reviewed for deploying the lines in the rule function, and I think calling the compute_COCOS module within the validation rule is preferable to embedding the algorithm directly in the rule function. |
Approach with Ideally the validator information shall help finding the source of the issue. |
I repeat what I said in one of our development meetings, I think we should be checking the consistency of the filled data with our definitions, not trying to compute the COCOS number and seeing if it matches. E.g. In DD/4: |
Note that you can limit validation rules to certain DD versions, see https://imas-validator.readthedocs.io/en/stable/courses/basic/write.html#exercise-6 |
I hope the new commit 4eae751 improves and meets with the reviewer's comments. Regarding the check on the sign of poloidal flux function, I think it is not general enough since Psi is arbitrary to an additive constant which may be chosen for convenience (e.g. for B.C.). @maarten-ic , thank you for your advice telling the way to have rule functions for different DDs. |
The DD/4 definition of poloidal flux is not arbitrary up to the addition of a contant. It has an exact definition in terms of integrating the magnetic field through a loop encircling the axis of symmetry (R=0). |
assert np.sign(time_slice.profiles_1d.f) == b0sign | ||
|
||
if time_slice.profiles_1d.phi.has_value: | ||
# phi at center found as zero in DINA, CORSICA and etc. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The toroidal flux at the magnetic axis is zero by definition. We should therefore remove this comment and test that the toroidal flux is zero at the magnetic axis and has the same sign as b0sign
at larger radii.
Since this rule does not depend on DD version, can we avoid having to code it up twice and have a generic set of equilibrium validation rules?
assert np.sign(psi_boundary - psi_axis) == ipsign | ||
|
||
if time_slice.global_quantities.q_95.has_value: | ||
assert np.sign(time_slice.global_quantities.q_95) == ipsign * b0sign |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Formally this should be b0sign / ipsign
but since we're only dealing with signs, I guess what's written here works.
assert np.sign(time_slice.profiles_1d.f) == b0sign | ||
|
||
if time_slice.profiles_1d.phi.has_value: | ||
# phi at center found as zero in DINA, CORSICA and etc. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comment above.
assert np.sign(psi_boundary - psi_axis) == -ipsign | ||
|
||
if time_slice.global_quantities.q_95.has_value: | ||
assert np.sign(time_slice.global_quantities.q_95) == ipsign * b0sign |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comment above.
# | ||
|
||
if time_slice.profiles_1d.f.has_value: | ||
assert np.sign(time_slice.profiles_1d.f) == b0sign |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why no tests for f_df_dpsi
, pressure
, and dpressure_dpsi
?
pressure
should be greater than, or equal to, zero, whilst the derivatives would have to be calculated from f
and p
an approximate comparison made. (Is this possible?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The rules for f, pressure and dpressure_dpsi have been added.
- Would you please tell how f_df_dpsi could be validated?
- FYI, multiple cases from DINA-IMAS, CORSICA and etc fail for the rule on dpressure_dpsi.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since p
, f
and psi
are know, the relevant derivatives could be calculated and and compared within some tolerance with dpressure_dpsi
and f_df_dpsi
. However, maybe this is now going to far and we should skip such testing for the moment and reconsider later if it's really needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, calculation of derived quantities is out of scope here (of possible interest: (https://github.com/ProjectTorreyPines/IMASdd.jl#expressions)), let's get the simple cases in good shape and available rather than trying to be exhaustive.
psi_axis = time_slice.global_quantities.psi_axis | ||
psi_boundary = time_slice.global_quantities.psi_boundary | ||
if psi_axis.has_value and psi_boundary.has_value: | ||
assert np.sign(psi_boundary - psi_axis) == -ipsign |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is the only line that differs from the DD v3 validation rules above so maybe we can find a way to cut down on duplication / maintenance?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could have the two validation rules as current, and make a third function that does all of the checking. E.g.
@validator("equilibrium", version="<4.0.0")
def validate_sign_DD3(ids):
validate_sign_common(ids, is_dd3=True)
@validator("equilibrium", version=">=4.0.0")
def validate_sign_DD4(ids):
validate_sign_common(ids, is_dd3=False)
def validate_sign_common(ids, is_dd3):
... # put all validation here, you can use the `is_dd3` boolean to differentiate where needed
This should work, but let me know if you encounter difficulties 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your advises about this point. Please check 1637221.
The rule has been drafted in 1637221 although, found the IDS/equilibrium of multiple METIS cases fails for this rule. For those cases, both psi_axis and psi_boundary are negative where psi_axis > psi_boundary. |
|
||
|
||
@validator("equilibrium", version="<4.0.0") | ||
def validate_sign_DD3(ids): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we avoid having a rule that contains the DD version in its name? User should not have to choose which one to apply. Plus the code is redundant except for the last two lines in the assert.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we avoid having a rule that contains the DD version in its name? User should not have to choose which one to apply.
Those names are for internal use of IMAS validator which automatically selects the functions based on the DD used in the ids in its design, not for user interface as far as I understand.
Plus the code is redundant except for the last two lines in the assert.
The redundancy has been taken for not using cocos.py
and following the tech advice from @maarten-ic. It is possible to recover e.g. #14-15 of the previous commit although, we need some cocos properties more or less in my view when processing multiple DD versions to validate EM data with one function. Is it ok to import cocos.py
or any other idea (copying some lines from the module to equilibrium.py
)?
1e8f2fd merges two functions into one which uses minimum number of cocos properties. Also, I'd like to propose to skip the rule for |
I'm not sure I fully understand your comment but since we generally test that |
Following Olivier's comment, the two rule functions have been merged into one function and adding docstring for the function |
This PR is for addin cocos validation rule in IMAS-Validator. The rule checks AoS
time_slice[itime].profiles_2d[i1]
and compare the COCOS computed and IDS_COCOS which is from DD. While found there was an issue for reporting in IMAS validator, the current reporting in txt format works and does not block this PR (HTML reporting does not work).