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

Bugfix for auto transforms #604

Merged
merged 11 commits into from
Nov 7, 2024

Conversation

dustinswales
Copy link
Collaborator

@dustinswales dustinswales commented Oct 22, 2024

Description

Modifications made to handle local variables needed for variables transforms at the Scheme level. Previously the Group would manage the local variable

Fixes #594

In response to the scenarios in #594:

Scenario 1

If a variable is used in two different schemes and:

  1. The first scheme has the same units as the host variable.
  2. The second scheme has different units than the host variable.

The Error was replicated and fixed by removing a bugfix at line 941 in var_props.py.

Scenario 2

On the flip side, if:

  1. The first scheme has different units than the host variable.
  2. The second scheme has the same units as the host variable.

Output

Generated code for scenario number 2 (where the correct units are used):

! Compute reverse (pre-scheme) transforms
ps_local(:) = 1.0E-2_kind_phys*ps(:)
! Call scheme
call cld_liq_run(ncol=ncol, timestep=timestep, tcld=tcld, temp=temp, qv=qv,              &
              ps=ps_local, cld_liq_array=cld_liq_array, errmsg=errmsg, errflg=errflg)
...
! Call scheme
call cld_ice_run(ncol=ncol, timestep=timestep, temp=temp, qv=qv, ps=ps,            &
              cld_ice_array=cld_ice_array, errmsg=errmsg, errflg=errflg)

Testing

All Capgen tests pass.

Copy link
Collaborator

@climbfuji climbfuji left a comment

Choose a reason for hiding this comment

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

Can you add a test for this, please? Similar to the one I added for prebuild?

scripts/suite_objects.py Outdated Show resolved Hide resolved
# Are there any varaible transforms for this scheme?
# If so, change Var's local_name need to local dummy array containing
# transformed argument, var_trans_local.
if (sub_lname_list is not None) and len(sub_lname_list) > 0:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is sub_lname_list a somewhat ordinary list in Python? If so, then

if sub_lname_list:

is equivalent to line 165

scripts/suite_objects.py Outdated Show resolved Hide resolved
scripts/suite_objects.py Outdated Show resolved Hide resolved
scripts/suite_objects.py Show resolved Hide resolved
scripts/var_props.py Show resolved Hide resolved
scripts/var_props.py Show resolved Hide resolved
@dustinswales
Copy link
Collaborator Author

@climbfuji Thanks for the review. I will expand the var_compatibility_test to stress more of the edge cases that @peverwhee brought up.

@@ -2477,6 +2556,14 @@ def write(self, outfile, host_arglist, indent, const_mod,
self._phase_check_stmts.write(outfile, indent,
{'errcode' : errcode, 'errmsg' : errmsg,
'funcname' : self.name})
# Write any loop match calculations
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think this was a bug. This needed to be need to BEFORE the allocation.

Copy link
Collaborator

@peverwhee peverwhee left a comment

Choose a reason for hiding this comment

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

thanks for tackling this @dustinswales - this seems like it was a whole rabbit hole! 🐰

a couple small things and a testing question

scripts/suite_objects.py Outdated Show resolved Hide resolved
scripts/suite_objects.py Outdated Show resolved Hide resolved
scripts/var_props.py Show resolved Hide resolved
test/var_compatibility_test/test_host.F90 Show resolved Hide resolved
@dustinswales
Copy link
Collaborator Author

@peverwhee It turns out that the real problem was in add_variable, where it was catching an incompatibility when it was actually equivalent. All good now, and unit tests updated to reflect the distinction between VarCompatObj.compat and VarCompatObj.__equiv

Copy link
Collaborator

@peverwhee peverwhee left a comment

Choose a reason for hiding this comment

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

thanks @dustinswales !

Copy link
Collaborator

@climbfuji climbfuji left a comment

Choose a reason for hiding this comment

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

approved

@climbfuji
Copy link
Collaborator

@gold2718 Would you like to review this PR?

Copy link
Collaborator

@climbfuji climbfuji left a comment

Choose a reason for hiding this comment

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

Just typos, otherwise approved!

scripts/suite_objects.py Show resolved Hide resolved
scripts/suite_objects.py Show resolved Hide resolved
scripts/suite_objects.py Show resolved Hide resolved
scripts/suite_objects.py Outdated Show resolved Hide resolved
scripts/suite_objects.py Show resolved Hide resolved
scripts/suite_objects.py Show resolved Hide resolved
scripts/suite_objects.py Show resolved Hide resolved
scripts/suite_objects.py Show resolved Hide resolved
scripts/suite_objects.py Show resolved Hide resolved
scripts/suite_objects.py Show resolved Hide resolved
@dustinswales
Copy link
Collaborator Author

Just typos, otherwise approved!

Personally, I think it's more informative if Scheme, Group, Host, Var , etc..., which are (case sensitive) python classes, be referenced in their native form when commenting on them. Happy to change if others disagree, but "Group" is distinct from "group" in this context.

@climbfuji
Copy link
Collaborator

Just typos, otherwise approved!

Personally, I think it's more informative if Scheme, Group, Host, Var , etc..., which are (case sensitive) python classes, be referenced in their native form when commenting on them. Happy to change if others disagree, but "Group" is distinct from "group" in this context.

Ok, that's fine with me. The way I read the comments they looked like generic labels (a scheme, a group, ...) to me. Then let's just fix the type for compatibility please.

Co-authored-by: Dom Heinzeller <[email protected]>
@mkavulich
Copy link
Collaborator

@dustinswales The other two PRs have been merged, let me know when this one is updated with the latest changes.

@dustinswales
Copy link
Collaborator Author

@mkavulich Updated.

@mkavulich mkavulich merged commit 27d0486 into NCAR:develop Nov 7, 2024
19 checks passed
@gold2718
Copy link
Collaborator

gold2718 commented Nov 7, 2024

gold2718

Sorry, been out of commission. Trying to catch up.

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.

5 participants