Skip to content
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

Fix perfmetrics v2.8.0 #3098

Merged
merged 1 commit into from
Mar 14, 2023
Merged

Fix perfmetrics v2.8.0 #3098

merged 1 commit into from
Mar 14, 2023

Conversation

axel-lauer
Copy link
Contributor

@axel-lauer axel-lauer commented Mar 13, 2023

This PR fixes a newly surfaced issue with the perfmetrics diagnostics "zonal", "latlot" and "cycle" that resulted in the diagnostics getting stuck in an infinite loop (see also #3076).

As it turned out, the problem was local variables used in functions defined in interface_scipts/auxiliary.ncl that had the same variable name as a loop variable in the perfmetrics diagnostics mentioned above. For reasons that are still not clear to me, a call to the function ncdf_write (which then calls ncdf_define) resulted in the variable used as loop index (ii) being overwritten in the calling procedure. As a consequence, the calling diagnostic got stuck in an infinite loop.

Declaring the variables used within the shared functions (interface_scipts/auxiliary.ncl) as "local" solved this problem.

I still do not fully understand why variables used in a function would overwrite the variables with the same name in the calling procedure when not explicitly declared as "local" variables and why this problem did not emerge earlier, but this problem is fixed with this PR. With the fix, I could (again) successfully run recipe_perfmetrics_CMIP5.yml, the output looks as expected.

Checklist

It is the responsibility of the author to make sure the pull request is ready to review. The icons indicate whether the item will be subject to the 🛠 Technical or 🧪 Scientific review.

New or updated recipe/diagnostic

@valeriupredoi
Copy link
Contributor

great detective work @axel-lauer 🔍 Could this perhaps be a exposing a bug in the latest build of NCL? 6.6.2 it's ben since ages, since no development being done on it, but the latest build is about two weeks old, it may be that that's the culprit?

Copy link
Contributor

@LisaBock LisaBock left a comment

Choose a reason for hiding this comment

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

Thanks @axel-lauer !
Worked fine for me as well. But I think it would be enough to define ii as local variable in interface_scripts/auxiliary.ncl.
A reason for this problem could be that there is ii used in diag_scripts/perfmetrics/main.ncl since my PR #2856 and therefore it is defined as a global variable for all appending funtions. And this is the reason why it is now passed from interface_scripts/auxiliary.ncl to the perfmetrics diagnostics "zonal", "latlot" and "cycle". Just an idea...

@axel-lauer
Copy link
Contributor Author

Thanks @LisaBock for testing. It sounds quite possible, that the changes to main.ncl from #2856 could be the reason for this problem.
Declaring also the variables i, jj and idim explicitly as local doesn't hurt as it makes the code (in my opinion) a bit easier to read, so I would tend to leave that in.

Copy link
Contributor

@remi-kazeroni remi-kazeroni left a comment

Choose a reason for hiding this comment

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

Thanks a lot for your work on this @axel-lauer! This fix enabled me to run the 4 affected recipes successfully (recipe_perfmetrics_CMIP5_* and recipe_smip_*) 👍
This is most probably related to a previous PR that has introduced a conflict in the diagnostics, not something related to the NCL package itself. quite a few NCL diagnostics have been added or changed since the last release. Good to see these all run fine with this fix.

@valeriupredoi
Copy link
Contributor

fantastic work, guys and gals! Am merging this now 🍺

Copy link
Contributor

@valeriupredoi valeriupredoi left a comment

Choose a reason for hiding this comment

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

boom!

@valeriupredoi valeriupredoi merged commit 5ac6fc6 into main Mar 14, 2023
@valeriupredoi valeriupredoi deleted the fix_perfmetrics branch March 14, 2023 11:52
@schlunma schlunma mentioned this pull request Mar 14, 2023
7 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants