Skip to content

Replace ccpp-prebuild and ccpp-capgen v0 with ccpp-capgen v1 - #762

Open
climbfuji wants to merge 93 commits into
developfrom
feature/capgen-v1
Open

climbfuji wants to merge 93 commits into
developfrom
feature/capgen-v1

Conversation

@climbfuji

@climbfuji climbfuji commented Jun 30, 2026 •

Copy link
Copy Markdown
Collaborator

THIS MUST BE MERGED AS A REGULAR MERGE

Description

This PR replaces the two code generators ccpp-prebuild and ccpp-capgen (version 0) with the new, unified ccpp-capgen (version 1). It supports all host models (CAM-SIMA, CCPP-SCM, NEPTUNE, UFS) and combines the features from ccpp-capgen v0 with the performance and operational robustness of ccpp-prebuild.

This pull request will be updated continuously with links to updates of the CCPP technical documentation and additional information. See also #759 for background information and further materials.

User interface changes?: Yes (see documentation)

This feature branch feature/capgen-v1 will support the three ccpp-prebuild-based models CCPP-SCM, NEPTUNE, and UFS, which will transition to ccpp-capgen v1 before CAM-SIMA. Once CAM-SIMA transitions, this PR will be merged and feature/capgen-v1 will be locked.

Todo

  • The LLM-generated documentation and materials in doc/ need to be reviewed and used to update the existing CCPP technical documentation (https://github.com/ncar/ccpp-doc). Once that process is complete, we can remove or trim down the additional documentation in doc/.
  • The LLM-generated code should be reviewed file-by-file. LLMs are known for their verbosity, and we can likely remove or trim down sizeable part sof the code. Open question: Should we do the same for the unit tests?

Issues

To check/may not be implemented yet:

Testing

See #759

climbfuji added 30 commits May 13, 2026 06:40
…gen-ng: entire constituent state now per instance
@dustinswales

Copy link
Copy Markdown
Collaborator

@gspetro-NOAA As part of 3288, we are switching to a new codebase and branch, feature/capgen-v1. So there are no reviews needed here for the overlaying UWM changes.

@gspetro-NOAA

Copy link
Copy Markdown

Testing for ufs-community/ufs-weather-model#3288 completed successfully. This PR can be merged.

@gspetro-NOAA

Copy link
Copy Markdown

@dustinswales Does this PR need to be merged if we are sticking w/the feature/capgen-v1 branch for the WM? Just trying to make sure I'm not waiting for a merge that won't happen...

@dustinswales

Copy link
Copy Markdown
Collaborator

@dustinswales Does this PR need to be merged if we are sticking w/the feature/capgen-v1 branch for the WM? Just trying to make sure I'm not waiting for a merge that won't happen...

@gspetro-NOAA No merging here.

@BrianCurtis-NOAA

Copy link
Copy Markdown

Hey @dustinswales could you help confirm and/or clarify the direction for ccpp-framework as it relates to UFS?

What I think I understand is that all development will be in feature/capgen-v1 until CAM-SIMA work is finished, which it will then be merged into develop and UFS will only be tracking feature/capgen-v1 for a minimal timeframe?

@climbfuji

Copy link
Copy Markdown
Collaborator Author

Hey @dustinswales could you help confirm and/or clarify the direction for ccpp-framework as it relates to UFS?

What I think I understand is that all development will be in feature/capgen-v1 until CAM-SIMA work is finished, which it will then be merged into develop and UFS will only be tracking feature/capgen-v1 for a minimal timeframe?

I can answer this.

Yes, the plan is to point to feature/capgen-v1 until CAM-SIMA transitions to this codebase. We anticipate this to happen around the new fiscal year. At that point, we will merge feature/capgen-v1 into develop.

@BrianCurtis-NOAA

Copy link
Copy Markdown

Hey @dustinswales could you help confirm and/or clarify the direction for ccpp-framework as it relates to UFS?
What I think I understand is that all development will be in feature/capgen-v1 until CAM-SIMA work is finished, which it will then be merged into develop and UFS will only be tracking feature/capgen-v1 for a minimal timeframe?

I can answer this.

Yes, the plan is to point to feature/capgen-v1 until CAM-SIMA transitions to this codebase. We anticipate this to happen around the new fiscal year. At that point, we will merge feature/capgen-v1 into develop.

Thanks for the quick reply @climbfuji ! This seems fair to me.

@climbfuji

climbfuji commented Aug 10, 2026 •

Copy link
Copy Markdown
Collaborator Author

To all reviewers. Not being able to update this feature branch while waiting for reviews (how long?) is causing real problems.

But since several models now point to this branch and reviewing a large set of changes is easier when the code doesn't change under the hood, should we branch off again and create feature/capgen-v1-continued-development from a6716e9 (the head of feature/capgen-v1 branch as of August 10, 2026) and then merge all update PRs (as of 08/10/2026, there are two) into the new branch feature/capgen-v1-continued-development?

If we were to do this, we could refer to that new branch when addressing change requests from the review of feature/capgen-v1, and we could do one final review of feature/capgen-v1-continued-development and update of feature/capgen-v1 before we merge the consolidated feature/capgen-v1 into develop.

@gspetro-NOAA

Copy link
Copy Markdown

To all reviewers. Not being able to update this feature branch while waiting for reviews (how long?) is causing real problems.

But since several models now point to this branch and reviewing a large set of changes is easier when the code doesn't change under the hood, should we branch off again and create feature/capgen-v1-continued-development from a6716e9 (the head of feature/capgen-v1 branch as of August 10, 2026) and then merge all update PRs (as of 08/10/2026, there are two) into the new branch feature/capgen-v1-continued-development?

If we were to do this, we could refer to that new branch when addressing change requests from the review of feature/capgen-v1, and we could do one final review of feature/capgen-v1-continued-development and update of feature/capgen-v1 before we merge the consolidated feature/capgen-v1 into develop.

I think development should be able to continue as usual on this branch because @dustinswales had specifically been using the c4b7d9a commit in PR 3288, and this PR was not going to be merged.
image (2)

@climbfuji

Copy link
Copy Markdown
Collaborator Author

To all reviewers. Not being able to update this feature branch while waiting for reviews (how long?) is causing real problems.
But since several models now point to this branch and reviewing a large set of changes is easier when the code doesn't change under the hood, should we branch off again and create feature/capgen-v1-continued-development from a6716e9 (the head of feature/capgen-v1 branch as of August 10, 2026) and then merge all update PRs (as of 08/10/2026, there are two) into the new branch feature/capgen-v1-continued-development?
If we were to do this, we could refer to that new branch when addressing change requests from the review of feature/capgen-v1, and we could do one final review of feature/capgen-v1-continued-development and update of feature/capgen-v1 before we merge the consolidated feature/capgen-v1 into develop.

I think development should be able to continue as usual on this branch because @dustinswales had specifically been using the c4b7d9a commit in PR 3288, and this PR was not going to be merged. image (2)

Correct - I am mainly thinking about the reviewers.

@climbfuji

Copy link
Copy Markdown
Collaborator Author

I found a different way.

For all reviewers. If you want to review a stable version without the latest updates, you can use this URL:

https://github.com/NCAR/ccpp-framework/pull/762/changes/BASE..c4b7d9aed935e8985309e2d974ed43cb46324e50

This compares commit c4b7d9a from the pull request branch (feature/capgen-v1) to the base branch (develop). Likewise,

https://github.com/NCAR/ccpp-framework/pull/762/changes/c4b7d9aed935e8985309e2d974ed43cb46324e50..HEAD

compares the missing commits from c4b7d9a to the head of the feature/capgen-v1 branch.

This way, you can do a first pass of your review based on the static commit c4b7d9a, and then look at the additional commits and differences added to feature/capgen-v1 in the meantime.

climbfuji and others added 2 commits August 10, 2026 12:54
…les, reorganize how Claude keeps track of future work (#773)

For feature/capgen-v1:
- Add missing check for protected variables (per metadata), mirroring the functionality in capgen v0 (capgen/generator/suite_resolver.py and capgen/metadata/metadata_table.py).
- Reorganize bookkeeping of future/deferred work in Claude so that it travels between different computers/users. Ultimately, at the time we merge feature/capgen-v1 into develop, any open work items will be converted into GitHub issues if still required (all other files).
…74 (name collision in capgen v1) (#776)

1. Fix for issue #774 - host module import name clash with control
variables passed via argument list, plus tests. Instead of implementing
some black magic, we simply bail out and instruct the user to fix the
name collision. This is easy - simply change the "local name" in the
`type = control` metadata table, which is only used as as the l.h.s. in
the explicit argument lists to the CCPP calls (`call ccpp_physics_run`
etc.) and then passed down to the suite and group caps.

2. Also: tests for issue #772 in capgen v0 (not an issue in v1, but
adding the same test to demonstrate).

---------

Co-authored-by: Courtney Peverley <courtneyp@ucar.edu>

@jimmielin jimmielin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks @climbfuji. Sharing a couple of findings from Claude for correctness bugs. I think all of them should be pretty easy to resolve.

Comment thread capgen/generator/suite_resolver.py Outdated
Comment on lines +1932 to +1953
unit_backward = ''
if needs_unit and bwd_fn is not None and intent in ('out', 'inout'):
unit_backward_expr = '{}_l'.format(local)
unit_backward = _apply_transform_formula(bwd_fn, unit_backward_expr, host_kind)
elif needs_kind and intent in ('out', 'inout'):
unit_backward = _kind_cast_expr(
scheme_var.type, '{}_l'.format(local), host_kind,
local=local, std_name=std_name, scheme_name=scheme_name,
)
elif needs_vert_flip and not needs_unit and intent in ('out', 'inout'):
unit_backward = '{}_l'.format(local)

needs_transform = needs_unit or needs_kind or needs_vert_flip

# ---- local variable names (transformation temp + pointer) ------------
# ``used_local_names`` stores the LOWERCASED names so collision
# detection is Fortran-case-insensitive (see _local_name_conflict).
temp_name = ''
ptr_name = ''
if needs_transform:
candidate = '{}_l'.format(local)
temp_name = _local_name_conflict(candidate, used_local_names)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think because unit_backward is built before _local_name_conflict checks here, there could be a bug if I declare a (rather evil) scheme local as p_hpa_l then at the same time I request a Pa -> hPa unit conversion for [p] standard_name = air_pressure this will end up reading the wrong name for unit_backward.

I would suggest moving this block to above unit_forward (which does not have this bug since it is after the local name conflict resolver).

)
pending_props[key] = val
# Try to build the MetadataTable as soon as we have name + type.
if 'name' in pending_props and 'type' in pending_props and current_table is None:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This check will cause a .meta table with a missing type (for example, a typo into typ = scheme) to be silently ignored.

I would suggest at the next header after the parse if pending_props is non-empty but no table was built to raise an error saying a key is required.

Comment on lines +1827 to +1832
if host_allocatable:
# Allocatable actual arguments must omit explicit dimension ranges:
# the callee declares the dummy as allocatable too and assumes the
# array shape from the actual.
subscript: str = ''
used_dim_std: Set[str] = set()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If host_allocatable is True and subscript = '' then _build_merged_subscript is never called, so flip_vertical=needs_vert_flip, if True, is ignored, but needs_transform is also True at this point so the temp pipeline is used.

I think if needs_vert_flip and host_allocatable is true it should error out (and maybe a xfail test be added to this case in TestVerticalFlipTransform?)

@climbfuji

Copy link
Copy Markdown
Collaborator Author

Thanks for the reports @jimmielin. I'll take a closer look next week; if you want to propose bug fixes for those, please go ahead.

@climbfuji

Copy link
Copy Markdown
Collaborator Author

Thanks @climbfuji. Sharing a couple of findings from Claude for correctness bugs. I think all of them should be pretty easy to resolve.

@jimmielin I already have fixes for these three issues. I'll submit a PR for you to review shortly.

@climbfuji

Copy link
Copy Markdown
Collaborator Author

Thanks @climbfuji. Sharing a couple of findings from Claude for correctness bugs. I think all of them should be pretty easy to resolve.

@jimmielin I already have fixes for these three issues. I'll submit a PR for you to review shortly.

See #777

climbfuji and others added 7 commits August 27, 2026 10:55
…w (@jimmielin/claude) (#777)

Fix three correctness findings from PR #762 review (@jimmielin/claude):
- suite_resolver: build the backward transform expression from the
conflict-resolved temp name, not the raw <name>_l candidate, so a scheme
local colliding with the temp no longer silently transforms the wrong
variable — including the optional+transform path (case 4), where the
pointer already targets the renamed temp.
- metadata_table: raise a clear error when a [ccpp-table-properties]
block is missing name and/or type (or the key is mistyped), instead of
silently dropping the table or failing later with a misleading "variable
outside any section" error.
- suite_resolver: reject the vertical-flip + allocatable-host
combination outright rather than silently dropping the flip and passing
vertically-reversed data.
… a constituent index (#780)

This PR fixes #779.

The prefix is now a precondition, not a classifier. Auto-provisioning requires
positive evidence that X is a constituent — some scheme flagging X or
tendency_of_X as advected/constituent/molar_mass. Without it, the name
is an ordinary variable and resolution raises the normal missing-provider
error. A suite-wide assertion re-checks the invariant after resolution so a
future path cannot reintroduce the class of bug.

No host changes required: the only intent(in)-only CAM-SIMA name is declared
in src/data/registry.xml, and the other eight have intent=out producers.

Included are updates to doc/* that are optional to review - they are used
primarily as instructions and memory for the LLM. These will be removed
or moved elsewhere when feature/capgen-v1 eventually becomes develop.
…ger if present. (#782)

Updates the `_load_metadata_files()` routine to use a host-provided
python logger, if present (otherwise it falls back to `_LOGGER`).
#786) (#787)

Intel truncates the mangled global name <module>_mp_<SUBROUTINE> at 90 characters. For UFS suite FV3_GFS_v17_coupled_p8_ugwpv1, Intel generated a global name of 94 characters, ccpp_FV3_GFS_v17_coupled_p8_ugwpv1_cap_mp_FV3_GFS_V17_COUPLED_P8_UGWPV1_PHYSICS_TIMESTEP_FINAL; UFS builds failed when WARN_AS_ERROR was enabled.

Suite cap subroutines now drop the prefix the module name already supplies:

<suite>_register / _init / _final   ->  suite_register / suite_init / suite_final
<suite>_physics_<phase>             ->  suite_physics_<phase>
<suite>_suite_state_(de)alloc       ->  suite_state_(de)alloc
@climbfuji climbfuji linked an issue Oct 15, 2026 that may be closed by this pull request
15 of 17 tasks
…oop counters (#793)

Add test for correct passing of nested subcycle loop counters to
`end-to-end-tests/nested_suite`. This is a leftover piece of work from
#792 (a bug reported for
capgen v0), see
#792 (comment).
These changes are in `end-to-end-tests/nested_suite/`.

Unrelated and included here: Update of Claude's project memory in
various `doc/*` files. As described in
https://docs.google.com/presentation/d/1-ZzWOK4bGJ3hYLXkjkOIVkShzTH2kiGH/edit?slide=id.p1#slide=id.p1
slide 18, for now all documentation and bookkeeping goes into doc/* so
that it is available to any user on any system. Once `feature/capgen-v1`
merges into `develop`, we should determine a good long-term strategy.

User interface changes?: No

Fixes: Addresses remaining comment
#792 (comment).

Testing: **all pass**
…e Fortran, warn for host Fortran (#794)

## Description

Implement option B described in
#788.

Scheme Fortran is now restricted to a line width of 132 characters; for
host Fortran, it is currently a warning - can be changed to an error in
a single place (see changed files).

Host and scheme developers are free to adopt and enforce shorter line
length using their own formatter/linter.

User interface changes?: No

Closes #788

Testing: added unit tests that check for 132 character line-length
limits; all tests pass.
…actions (#795)

Four additions, committed one after the other:

- Add memory-sanitizer end-to-end test to GitHub actions using gfortran-12. This test is expected to fail initially (fix in step 2) due to a bug in the multi-instance advection test setup. Commit e8134e6 (see below - end-to-end-test-asan fails).
- Fix the multi-instance advection test without changing the multi-instance constituents implementation in capgen v1. See Constituent registration aliases memory in both directions (host <-> framework; use-after-free bugs) #797 for a proposed change to the implementation in the future.
- Reverse the order of calling ccpp_deallocate_dynamic_constituents and ccpp_final in all tests that use constituents. With steps 2 and 3, the CI tests pass (commit 8f72632).
- Use the correct gfortran compiler in the job matrix in GitHub actions 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

7 participants