Skip to content

Conversation

peverwhee
Copy link
Collaborator

Updates to allow for dimension variables that are set in the register phase to be used to allocate interstitial variables.

Open to feedback, of course! There's no explicit handling right now to ensure that the variable is set in the register phase, but my feeling is that you'll get a run-time error if you try to use an uninitialized variable in an allocate statement.

User interface changes?: No

Fixes:
closes #681

Testing: Added variables/logic in capgen test to confirm the dimensions are initialized and used properly

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.

Looks reasonable to me. And I agree that if the dimension isn't set, we'll get a runtime error. Do you think the auto-generated code that is added with --debug will catch it in the caps?

def add_variable_dimensions(self, var, ignore_sources, to_dict=None,
adjust_intent=False):
def add_variable_dimensions(self, var, ignore_sources, suite_type,
to_dict=None, adjust_intent=False):
"""Attempt to find a source for each dimension in <var> and add that
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you update the docstring please?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

updated!

@peverwhee
Copy link
Collaborator Author

@climbfuji good question!

I tested this by moving the setting of the dim_inter variable in the capgen test to the init phase instead of the register phase (which means the module-level interstitial variable will be allocated before its dimension is set later in the init phase). Can confirm that it does run up against the debug checks and produces an error.

physics2        : In group temp_suite_finalize before  temp_adjust_finalize: for array interstitial_var, expected size        3 but got        0

@peverwhee peverwhee requested a review from climbfuji September 12, 2025 18:37
@climbfuji
Copy link
Collaborator

@climbfuji good question!

I tested this by moving the setting of the dim_inter variable in the capgen test to the init phase instead of the register phase (which means the module-level interstitial variable will be allocated before its dimension is set later in the init phase). Can confirm that it does run up against the debug checks and produces an error.

physics2        : In group temp_suite_finalize before  temp_adjust_finalize: for array interstitial_var, expected size        3 but got        0

Great, thanks for testing!

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.

2 participants