Skip to content

Rename --debug flag to --verbose, add new debugging capability to detect array size mismatches, pretty-print auto-generated caps#404

Merged
climbfuji merged 1 commit into
NCAR:mainfrom
climbfuji:debug-array-alloc-ccpp-caps
Oct 25, 2021
Merged

Rename --debug flag to --verbose, add new debugging capability to detect array size mismatches, pretty-print auto-generated caps#404
climbfuji merged 1 commit into
NCAR:mainfrom
climbfuji:debug-array-alloc-ccpp-caps

Conversation

@climbfuji
Copy link
Copy Markdown
Collaborator

@climbfuji climbfuji commented Oct 4, 2021

Description

This PR renames the existing --debug flag for ccpp_prebuild.py to --verbose, because this is what it does (enable verbose output from the script).

It then repurposes the --debug flag to assist debugging efforts with array size comparisons in the auto-generated caps. These comparisons are based on the actual size of the arrays versus the dimensions specified in the CCPP metadata. The comparisons are skipped for arrays whose active attribute evaluates to .false., and altogether if the command line argument --debug is not specified.

Also: Updates to formatting of auto-generated caps (no code changes) so that they look "nicer".

Fixes #405

Associated PRs:

NCAR/ccpp-physics#749
#404
https://github.com/NOAA-EMC/fv3atm/pull/407/files
NOAA-PSL/stochastic_physics#48
ufs-community/ufs-weather-model#850

For regression testing, see

ufs-community/ufs-weather-model#850

…ew --debug capability to add array size comparisons in auto-generated caps. Updates to formatting of auto-generated caps (no code changes)
Copy link
Copy Markdown
Collaborator

@gold2718 gold2718 left a comment

Choose a reason for hiding this comment

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

Looks okay although I think there are some extra calls to lower() which could be cleaned up.

Comment thread scripts/mkstatic.py
dim0 = int(dims[0])
dim0 = dims[0]
except ValueError:
if not dims[0].lower() in metadata_define.keys():
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Isn't dims[0] already lowercase based on call to lower() on line 1170? If so, this applies to the lower() calls below.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

You are correct, I will clean this up before the regression testing starts (I think next week, after my PTO).

Comment thread scripts/mkstatic.py
array_size.append('({last}-{first}+1)'.format(last=dim1, first=dim0))
var_size_expected = '({})'.format('*'.join(array_size))
assign_test = ''' ! Check if variable {var_name} is associated/allocated and has the correct size
if (size({var_name})/={var_size_expected}) then
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

If {var_name} is not allocated, won't size({var_name}) crash?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

That is why it is inside the condition (created based on the active attribute). And that is exactly one of the things this PR/change should do - crash if an array isn't allocated even though the framework is told it should be.

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.

Framework should provide a debugging feature to compare array dimensions in ccpp_prebuild.py

3 participants