Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Aerosol (and a few trace-gas) components for GEOS. On this line the aerosol comp
- Resource files (`*.yaml`, and the `*.rc` that remain beside them) are installed to `etc/`; the instance `*.yaml` files are the ones read on this line (`ESMF/GOCART2G_GridComp/GOCART2G_GridCompMod.F90`, `add_children__`). The `*.rc` files beside them are MAPL2 leftovers that the ported code does not read.
- `CCPP/GOCART_CCPP.F90` and `ESMF/NUOPC/NUOPC_Cap.F90` are empty files; the UFS cap is in `ESMF/UFS`, not built on this line.
- `ESMF/GOCART2G_GridComp/SU2G_GridComp/mapl3-porting-notes.md` records the SU2G port steps and what is left after it.
- Error handling in code you write or touch uses the MAPL3 macros (`@MAPL/include/MAPL_ErrLog.h`): `_RC` on calls, `_STAT` on `allocate`, `_ASSERT(cond, msg)` with a message, and `_RETURN(_SUCCESS)` at every successful exit. Convert `RC=STATUS`/`VERIFY_`/`ASSERT_`/`RETURN_` in any routine you change. `_RC` expands to two statements (`rc=status);_VERIFY(status`), so it cannot end a one-line `if`; use a block `if`. Do not add decorative `!----` separator lines.

## Build and test
- Not built standalone in the GEOSgcm fixture: built as part of GEOSgcm (`CMakeLists.txt`, `esma_add_subdirectories`; `CHANGELOG.md` records that standalone builds were removed). Libraries built: `Chem_Shared2G`, `Process_Library`, `GOCART2G_GridComp` with `GA_Environment`, `DU2G`, `SS2G`, `SU2G`.
Expand Down
48 changes: 41 additions & 7 deletions ESMF/GOCART2G_GridComp/SU2G_GridComp/mapl3-porting-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@ Left after the port (none blocks it):
AGCM and Physics are ported (SUPERDYN/`TRADV` -> PHYS/`TRADV`, drop
Physics' MAPL2 `TRADV` export). Then check that the DU/SS bins are
advected (step 4).
- Diffusion and convection: need MAPL3 turbulence and moist service
providers (step 4).
- Convection: subscribe SU, DU and SS to Moist's `MTR` service, which
Moist now provides (GEOSgcm_GridComp#1566, merged on
`release/MAPL-v3`) (step 4).
- Diffusion: subscribe SU, DU and SS to `TRDIFF` once Turbulence is
ported and provides it (step 4).
- NI2G's `SO4` import from SU, plus DU->NI and SS->NI (step 10).
- Fixed but not run-tested: DU2G `DustEmissionK14` undef and point-emission
indices (no case uses them); GOCART2G `get_monochromatic_aop` (no caller).
Expand Down Expand Up @@ -232,8 +235,36 @@ Rewritten after DU/SS:
`service_items=['DMS','SO2','SO4','MSA']` (`MAPL_GridCompAddSpec`
argument; `items:` in YAML). DynCore/AdvCore already provide
`TRADV`, and Superdyn re-exports it; no component subscribes yet.
- Turbulence and moist have no MAPL3 service providers yet; subscribe
once they exist.
- Service mapping, one subscription per MAPL2 friendly target, each
with the same `service_items` (the `advected_tracers` vector can be
reused) and for the computational instance only:

| MAPL2 `FRIENDLYTO` | MAPL3 service | Provider | Status |
|---|---|---|---|
| `DYNAMICS` | `TRADV` (`advected_quantities`) | FV3 DynCore/AdvCore | DONE |
| `MOIST` | `MTR` (`tracers_for_moist`) | Moist | TODO |
| `TURBULENCE` | `TRDIFF` (`turbulently_diffused_quantities`) | Turbulence | Blocked |

Tracers per child (MAPL2 `*_StateSpecs.rc`, all three targets on
each): SU2G `DMS`, `SO2`, `SO4`, `MSA`; DU2G `DU` and SS2G `SS`
(each one field with 5 ungridded bins). Not yet ported, same three
subscriptions later: CA2G `<inst>phobic`, `<inst>philic`; NI2G
`NH3`, `NH4a`, `NO3an1`-`NO3an3`. Data-driven instances had no
friendlies (their `friendlyto=` lines are commented out), so they
subscribe to nothing. No other MAPL2 friendly targets (`ANALYSIS`,
`CHEMISTRY`) appear in GOCART2G, so no other services.
- Moist (`GEOS_MoistGridComp.F90`, GEOSgcm_GridComp#1566, merged on
`release/MAPL-v3`) provides `MTR` as an export
service; it replaces MAPL2's `MTR` import that Physics filled with
the `FRIENDLYTO=MOIST` fields. GF reads `ScavengingFractionPerKm`
and `SetofHenryLawCts` from each field's ESMF Info
(`Process_Library.F90`); SU, DU and SS still set them on their
internals. Not yet checked how Physics connects GOCART's `MTR`
imports to Moist's export.
- Turbulence is not ported. `TRDIFF` is the name Moist uses for its
own subscription (replacing MAPL2's `TR` bundle); treat it as a
placeholder and rename both together when Turbulence settles the
provider.
- Check whether the subscription belongs in SU or in a GOCART2G/PHYS
ancestor, and do the same for DU and SS.
- DONE: SetServices subscribes to `TRADV` with `service_items`
Expand Down Expand Up @@ -265,7 +296,7 @@ Rewritten after DU/SS:
SUPERDYN/`TRADV` -> PHYS/`TRADV` and drop Physics' MAPL2 `TRADV`
export. Until then the subscriptions are unused.
- Open, for the first coupled run:
- duplicate names when several instances (e.g. two SU) subscribe;
- duplicate names when several instances (e.g. two SU) subscribe; code checked 2026-11-06, see the Self-subscription section of the GEOSmoist_GridComp `mapl3-porting-notes.md` (MAPL accepts duplicates, Moist's `CNV_Tracers_Init` looks fields up by name, and subscribed fields lose their short names in the bundle, as DynCore's `get_short_name` works around for `TRADV`);
- `DU` and `SS` are single fields with 5 ungridded bins, while SU's
are plain 3-D fields: check that the service and DynCore/AdvCore
advect fields with an ungridded dimension (every bin), or split
Expand Down Expand Up @@ -607,5 +638,8 @@ Items 1-4 were checked at run time with the step-0 baseline (step 9).
GOCART2G/CHEM/PHYS. Inactive until the AGCM connects SUPERDYN/`TRADV`
-> PHYS/`TRADV` (needs the AGCM and Physics ports). Untested in a
coupled run, including whether the ungridded DU/SS bins are advected.
- Diffusion and convection: not addressed; turbulence and moist have no
MAPL3 service providers yet.
- Convection: SU, DU and SS should subscribe to Moist's `MTR` with the
same items as `TRADV`; Moist provides it (GEOSgcm_GridComp#1566,
merged on `release/MAPL-v3`). Not yet subscribed.
- Diffusion: subscribe to `TRDIFF` (placeholder name) once Turbulence
is ported and provides it.
235 changes: 235 additions & 0 deletions ESMF/GOCART2G_GridComp/regression/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,235 @@
# GOCART2G MAPL3 regression tests

Each test runs a single run phase of a GOCART2G component for one 20-minute
time step, starting from state captured in a MAPL2 GEOSgcm run, and compares
the resulting MAPL3 checkpoint against a stored baseline.

## Running

`CMakeLists.txt` registers one ctest per line of `cases.txt`, all with the
label `REGRESSION`:

```
ctest -L REGRESSION # all regression tests
ctest -R 'dust-sa/run1' # a single case
```

Every case depends on the `gocart2g/sync_data` fixture, which syncs
regression data from
`s3://gmao-usw2-si-team/regression-data/GEOSagcm_GridComp/GEOSphysics_GridComp/GEOSchem_GridComp/GOCART2G_GridComp`
into `$LOCAL_REGRESSION_DATA_DIR/<same path>`.

## What a test does

`run_case.cmake` runs the following steps for a case `<case>/runN`:

1. Copies the config directory `<case>/runN/` into a temporary experiment
directory.
2. Copies the restarts `<data>/<case>/runN/checkpoints/2000-04-14T21:20:00/`
into `checkpoints/` and symlinks `<data>/ExtData` as `ExtData`.
3. Runs `GEOS.x mapl.yaml` on 6 processes. The clock starts at
`2000-04-14T21:20:00` (from `cap_restart.yaml`), and `dt` and
`segment_duration` are both `PT20M`, so exactly one step runs.
4. On IntelLLVM builds only, compares every `*.nc` file in
`<data>/<case>/runN/checkpoints/last/` against the new
`checkpoints/last/` with `nccmp` (or `cmp` if `nccmp` is not found).
NaNs compare equal, and `lons`, `lats`, `corner_lons` and `corner_lats`
are ignored.
5. Deletes the experiment directory.

### Common setup

All cases share the following settings:

- **Grid:** C12 cubed sphere with 181 model levels, where `PLE` gives the
pressure (set in `root.yaml`).
- **Root component:** `configurable_gridcomp`, which runs each child's
`run_phases` from `root.yaml`/`fake-gocart.yaml` in order.
- **`DataFor<XX>` component:** a `configurable_gridcomp` whose *internal*
state holds every import the component under test needs. Its restart
file, `DataFor<XX>_internal.nc`, is the MAPL2 import state captured
before the run phase. `root.yaml` connects each of those internal fields
to the matching import of the component under test.
- **Checkpoints:** the component under test sets
`activate_all_exports: true` and checkpoints its import, internal and
export states. These are the files compared in step 4.
- **Logging:** `mapl.yaml` loads `logging.yaml` (`pflogger: logging.yaml`), which logs to the console only, sets the `MAPL` logger to ERROR and keeps `MAPL.profiler` at INFO on the root rank. The cases have no field dictionary, so MAPL warns once per variable spec per rank, and its default logging writes each warning to `warnings_and_errors.log` under an MPI lock, which serializes the ranks.

### `run1` vs `run2`

Each case has a `run1` and a `run2` directory, each testing one GOCART2G
run phase:

- **Run1:** emissions and sources (in `DU2G_GridCompMod.F90`, "Computes
emissions/sources for Dust").
- **Run2:** settling, dry deposition, wet removal, chemistry (SU) and
diagnostics.

The two directories differ only in the selected phase and, because the
phases read different fields, in the imports that `DataFor<XX>` provides.

## Cases

### Standalone (`*-sa`) cases

In these cases one aerosol component runs on its own:

```
Root
├── DataFor<XX>
└── FakeGOCART (configurable_gridcomp)
└── <XX> (lib<XX>2G_GridComp.so, run_phases: [RunN])
```

`FakeGOCART` stands in for the real GOCART2G parent, so that
`fake-gocart.yaml` can select a single run phase of the aerosol component.
Because MAPL connections can only target a component's direct children,
`root.yaml` connects to `FakeGOCART`. MAPL passes the aerosol component's
unsatisfied imports up to `FakeGOCART`, and that is how the connections
reach the aerosol component.

| Case | Component | Instance config | Imports |
|---|---|---|---|
| `dust-sa` | DU2G (`DU`) | `DU_instance_DU.yaml` | `data-for-du.yaml` |
| `seasalt-sa` | SS2G (`SS`) | `SS_instance_SS.yaml` | `data-for-ss.yaml` |
| `sulfate-sa` | SU2G (`SU`) | `SU_instance_SU.yaml` | `data-for-su.yaml` |
| `nitrate-sa` | NI2G (`NI`) | `NI_instance_NI.yaml` | `data-for-ni.yaml` |

The restarts are `DataFor<XX>_internal.nc` and `<XX>_internal.nc`. The
baseline consists of `<XX>_{import,internal,export}.nc`.

`nitrate-sa` has one more child, `DuSsStub` (`../DuSsStub_GridComp`, built only for this case):

```
Root
├── DataForNI
├── DuSsStub (libDuSsStub_GridComp.so)
└── FakeGOCART (configurable_gridcomp)
└── NI (libNI2G_GridComp.so, run_phases: [RunN])
```

NI2G's Initialize reads the `radius` and `fnum` ESMF Info attributes from its `DU` and `SS` imports. Only DU2G's and SS2G's own Initialize set them, and a `configurable_gridcomp` cannot. `DuSsStub` imports `DU` and `SS` from `DataForNI`, sets the attributes as DU2G and SS2G do, and exports them; `root.yaml` connects those exports to `FakeGOCART`.

### `gocart+seasalt+dust+sulfate`

This case runs the real GOCART2G parent with its DU, SS and SU children:

```
Root
├── DataForGOCART2G (run_phases: [run])
└── GOCART2G (libGOCART2G_GridComp.so, run_phases: [RunN])
├── DU
├── SS
└── SU
```

- **Configs:** `GOCART2G_GridComp.yaml`, plus `DU_instance_DU.yaml`,
`SS_instance_SS.yaml` and `SU_instance_SU.yaml`.
- **Imports:** `data-for-gocart2g.yaml` holds the combined imports of all
three aerosols.
- **Restarts:** `DataForGOCART2G_internal.nc`, `DU_internal.nc`,
`SS_internal.nc` and `SU_internal.nc`.
- **Baseline:** `{DU,SS,SU}_{import,internal,export}.nc` and
`GOCART2G_{import,export}.nc`.

### `gocart+seasalt+dust+sulfate+nitrate`

The same as `gocart+seasalt+dust+sulfate`, with an NI child added:

- **Configs:** `GOCART2G_GridComp.yaml` lists `NI: [NI]` (an empty list in the case above); `NI_instance_NI.yaml` is added.
- **Imports:** `data-for-gocart2g.yaml` and `root.yaml` add NI's imports, such as the ammonia emissions `EMI_NH3_AG`, `EMI_NH3_BB` and `EMI_NH3_EN`.
- **Restarts:** adds `NI_internal.nc`.
- **Baseline:** adds `NI_{import,internal,export}.nc`.

## Creating a case from MAPL2 captures

The input data comes from a MAPL2 run instrumented to dump each
component's states before and after each run phase. The dumps are then
converted to the new cubed-sphere layout with
`GEOS_Restart_Utilities/convertOldCStoNewCS.py`.

### Baseline GEOSgcm

The captures come from GEOSgcm `v11.11.0` (MAPL `v2.71.0`), built with ifx
rather than the default ifort, with these main components:

| Component | Version |
|---|---|
| GEOSgcm | `v11.11.0` |
| MAPL | `v2.71.0` |
| env | `v5.26.0`, with `g5_modules` edited for ifx (see below) |
| cmake | `v4.51.0` |
| ecbuild | `geos/v3.15.2` |
| GEOSgcm_GridComp | `v3.1.0` |
| GEOSchem_GridComp | `v2.1.0` |
| GOCART | `fd894af`, plus local changes kept in a stash |
| FVdycoreCubed_GridComp / fvdycore | `v3.1.0` / `geos/v3.1.0` |
| GEOSradiation_GridComp | `develop` at `0b402f6`, with a local edit to `GEOS_SolarGridComp.F90` (see below) |
| RRTMGP | `geos/v1.8+1.0.0` |
| GMAO_Shared | `v3.0.3` |
| GEOS_Util | `v3.0.4` |
| NCEP_Shared | `v1.5.0` |
| GEOSgcm_App | `v3.1.0` |

All other components were at the tags pinned by GEOSgcm `v11.11.0`.

The run was on discover (NCCS), where the `g5_modules` edit switches from
ifort 2021.13 / Intel MPI 2021.13 to ifx 2025.3.0 / Intel MPI 2021.17:

```
basedir = /discover/swdev/gmao_SIteam/Baselibs/ESMA-Baselibs-8.33.0/x86_64-pc-linux-gnu/ifx_2025.3.0-intelmpi_2021.17
comp/gcc/12.3.0
comp/intel/2025.3.0
mpi/impi/2021.17
other/jemalloc/5.3.0
other/ISSM/geos/1.0.3/ifx_2025.3.0-intelmpi_2021.17
```

The local edit to `GEOSsolar_GridComp/GEOS_SolarGridComp.F90` applies fix 1
from
[GEOSradiation_GridComp#110](https://github.com/GEOS-ESM/GEOSradiation_GridComp/issues/110):
it deletes the two `have_rrtmgp_wavenums = .true.` lines. Without the fix,
`UPDATE_EXPORT` reads the RRTMGP band limits uninitialized on every call
after the first. With it, the limits are reloaded on every call.

### Mapping captures to case files

For component `<XX>` and phase `N`, the converted files go into a case as
follows:

| MAPL2 capture | Destination |
|---|---|
| `<XX>_import_before_runPhaseN.nc` | `runN/checkpoints/2000-04-14T21:20:00/DataFor<XX>_internal.nc` |
| `<XX>_internal_before_runPhaseN.nc` | `runN/checkpoints/2000-04-14T21:20:00/<XX>_internal.nc` |
| `<XX>_*_after_runPhaseN.nc` | `baseline/` (for `cmpchk.py`) |

The ctest baseline in `checkpoints/last/` is not the MAPL2 capture but a
MAPL3 checkpoint from a known-good IntelLLVM run.

The aerosol optics tables go under
`ExtData/chemistry/AerosolOptics/v2.x.x/x/`, where `aerosol_*_optics_file`
in each instance yaml points.

## Comparing against MAPL2 by hand (`cmpchk.py`)

Each run directory has a `cmpchk.py`, not used by the ctest, that compares
a MAPL3 checkpoint with the MAPL2 states captured *after* the same run
phase. Run it from the experiment directory, which must contain:

- `baseline/<XX>_<state>_after_runPhaseN.nc`: the MAPL2 captures.
- `checkpoints/last/<XX>_<state>.nc`: the MAPL3 checkpoint.

For each of the import, internal and export states, it prints the min, max
and norm of the difference for every variable present in both files.

### Validating a case before updating regression-data

Before a new or changed case goes into regression-data, check it against
MAPL2:

1. Copy the MAPL2 "before" captures, renamed as in the mapping table
above, into `checkpoints/2000-04-14T21:20:00/` and run the case by hand.
2. Copy the MAPL2 "after" captures into `baseline/` and run `cmpchk.py`.
3. If every difference is zero, add the renamed MAPL2 inputs to
regression-data as `runN/checkpoints/2000-04-14T21:20:00/`, and the
MAPL3 outputs as `runN/checkpoints/last/`.
35 changes: 35 additions & 0 deletions ESMF/GOCART2G_GridComp/regression/dust-sa/run1/logging.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
schema_version: 1

# MAPL's default logging writes every rank's warnings to warnings_and_errors.log
# under an MPI lock. Without a field dictionary in the run directory, MAPL warns
# once per variable spec per rank, and the lock serializes the ranks (about 6 s
# of a 17 s Moist case). This config logs to the console only and sets the MAPL
# logger to ERROR; MAPL.profiler keeps the timing tables on rank 0.

formatters:
basic:
class: Formatter
format: '%(name)a15~: %(message)a'

handlers:
console:
class: streamhandler
formatter: basic
unit: OUTPUT_UNIT
level: DEBUG

root:
handlers: [console]
level: WARNING
root_level: INFO

loggers:
MAPL:
level: ERROR
root_level: ERROR

MAPL.profiler:
handlers: [console]
propagate: FALSE
level: WARNING
root_level: INFO
1 change: 1 addition & 0 deletions ESMF/GOCART2G_GridComp/regression/dust-sa/run1/mapl.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ esmf:
logAppendFlag: false

app_petcount: 6
pflogger: logging.yaml
35 changes: 35 additions & 0 deletions ESMF/GOCART2G_GridComp/regression/dust-sa/run2/logging.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
schema_version: 1

# MAPL's default logging writes every rank's warnings to warnings_and_errors.log
# under an MPI lock. Without a field dictionary in the run directory, MAPL warns
# once per variable spec per rank, and the lock serializes the ranks (about 6 s
# of a 17 s Moist case). This config logs to the console only and sets the MAPL
# logger to ERROR; MAPL.profiler keeps the timing tables on rank 0.

formatters:
basic:
class: Formatter
format: '%(name)a15~: %(message)a'

handlers:
console:
class: streamhandler
formatter: basic
unit: OUTPUT_UNIT
level: DEBUG

root:
handlers: [console]
level: WARNING
root_level: INFO

loggers:
MAPL:
level: ERROR
root_level: ERROR

MAPL.profiler:
handlers: [console]
propagate: FALSE
level: WARNING
root_level: INFO
1 change: 1 addition & 0 deletions ESMF/GOCART2G_GridComp/regression/dust-sa/run2/mapl.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ esmf:
logAppendFlag: false

app_petcount: 6
pflogger: logging.yaml
Loading
Loading