Skip to content

Suite variable tracker for Capgen. - #785

Draft
dustinswales wants to merge 1 commit into
NCAR:feature/capgen-v1from
dustinswales:feature/variable_tracker
Draft

dustinswales wants to merge 1 commit into
NCAR:feature/capgen-v1from
dustinswales:feature/variable_tracker

Conversation

@dustinswales

@dustinswales dustinswales commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

Script (from Claude) to parse the Capgen generated datatable (.xml).

The script can provide the following information:

  • List every subroutine call that touches a standard_name, in file order
  • Trace a standard_name in actual execution order for one suite
  • Trace local (Fortran) variable name used somewhere -- it will be resolved to the standard_name(s) that share it
  • List available suites/groups/schemes

User interface changes? No

Addresses #784

Testing:
test removed:
unit tests:
system tests:
manual testing:

@dustinswales
dustinswales requested review from a team as code owners September 15, 2026 17:21

@climbfuji climbfuji left a comment

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.

Quick first review, didn't try it yet.

A more general question I have is if the variable tracker should be "part" of capgen v1, i.e. live in scripts and utilize available tools to access the datatable (piggy-backing on the datatable query script). It would be a fourth entry point.

Right now, it is more like an external tool with its own datatable parser and its own directory (tools).

I am leaning towards a tigher integration, given that the script comes with the CCPP capgen v1 code.

Thoughts?

We also need CI testing for the script.

Comment thread tools/variable_tracker.py

# Same, but you only know the local (Fortran) variable name used
# somewhere -- it will be resolved to the standard_name(s) that share it
python3 variable_tracker.py trace <file.xml> gt0 --by local_name --suite MPAS_GFS

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.

What happens if two schemes use the same local name for different variables (standard names)?

Comment thread tools/variable_tracker.py
import xml.etree.ElementTree as ET
from collections import defaultdict, namedtuple

PHASES = ("init", "timestep_init", "run", "final")

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.

timestep_final is missing

also: ccpp_register, comes before init - but not sure if we should include it yet

Comment thread tools/variable_tracker.py
"""
Return the calls touching `standard_name`, ordered the way they
actually execute within `suite_name` (group order, then scheme
order within the group, then phase order init->run->final).

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.

This is incorrect. The outside loop is phase, then group, then schemes in group.

Comment thread tools/variable_tracker.py
continue
for i, (group, c) in enumerate(ordered, 1):
direction = {
"in": "reads ",

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.

Why is reads lowercase while WRITES and R/W are uppercase? Should we just use R, W, RW ?

@dustinswales

Copy link
Copy Markdown
Contributor Author

Quick first review, didn't try it yet.

A more general question I have is if the variable tracker should be "part" of capgen v1, i.e. live in scripts and utilize available tools to access the datatable (piggy-backing on the datatable query script). It would be a fourth entry point.

Right now, it is more like an external tool with its own datatable parser and its own directory (tools).

I am leaning towards a tigher integration, given that the script comes with the CCPP capgen v1 code.

Thoughts?

We also need CI testing for the script.

I like the idea of this script being an entrypoint.
I will move this to DRAFT and work on it tomorrow, along with some CI.

@dustinswales
dustinswales marked this pull request as draft September 17, 2026 15:21
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