Skip to content

ANN prarameterization of horizontal momentum eddy fluxes#944

Merged
Hallberg-NOAA merged 17 commits into
NOAA-GFDL:dev/gfdlfrom
m2lines:dev/m2lines
Sep 19, 2025
Merged

ANN prarameterization of horizontal momentum eddy fluxes#944
Hallberg-NOAA merged 17 commits into
NOAA-GFDL:dev/gfdlfrom
m2lines:dev/m2lines

Conversation

@Pperezhogin
Copy link
Copy Markdown

@Pperezhogin Pperezhogin commented Jul 23, 2025

This PR contains the implementation of the neural network parameterization of mesoscale eddy effects introduced in Perezhogin, Adcroft, Zanna 2025.

Three files implement the module of neural network. In particular, its inference:
MOM_ANN.F90
testing:
test_MOM_ANN.F90
and timing:
time_MOM_ANN.F90

A function implementing parameterization, compute_stress_ANN_collocated, was introduced in module MOM_Zanna_Bolton.F90.

Slight change in MOM_hor_visc.F90 implements alternative discretization of relative vorticity using contour integral (turned off by default).

The netCDF file with neural network weights can be found here. In order to turn on parameterization, provide path to netCDF file and switch a couple of other parameters in MOM_override:

#override USE_ZB2020 = True
#override ZB2020_USE_ANN = True
#override ZB2020_ANN_FILE_TALL = relative/or/absolute/path/to/network/parameters/Tall.nc
#override USE_CIRCULATION_IN_HORVISC = True

Pperezhogin and others added 14 commits April 28, 2025 13:15
- Computes subgrid stress using ANN in MOM_Zanna_Bolton
- Uses MOM_ANN module for ANN inference

Equivalent MOM_override for defaults
```
USE_ZB2020 = True
ZB2020_USE_ANN = True
USE_CIRCULATION_IN_HORVISC = True
ZB2020_ANN_FILE_TALL = /path/to/ocean3d/subfilter/FGR3/EXP1/model/Tall.nc
```
Blank commit after squash/rebase was handled on command line
- Removed unused modules
- Removed unused MOM_memory.h
- Added input and output means which default to 0 and
  do not need to be present in the weights file
- Gave defaults to means, norms, tests so that they do
  no need to be present in file
- Added missing array notation "(:)"
- Minor formatting
- Added ANN_allocate, set_layer, set_input_normalization, and
  set_output_normalization methods to allow reconfiguration during
  unit tests
- Added ANN_unit_tests with some simple constructed-by-code
  networks with known solutions
- Added config_src/drivers/unit_tests/test_MOM_ANN.F90 to drive
  unit tests
- Added  config_src/drivers/timing_tests/time_MOM_ANN.F90 as
  rudimentary for timing inference
- Adds inference operating on array (instead of single vector of
  features)
- Implements several different versions of inference with various
  loop orders
  - Involves storing the transpose of A in the type
  - Tested by checking inference on same inputs is identical between
    variants
    - Added randomizers to assist in unit testing
- Adds timing of variants to config_src/drivers/timing/time_MOM_ANN.F90
- Adds an interface (MOM_apply) to select preferred version of
  inference subroutine
- Added command line args to time_MOM_ANN.F90 to allow more rapid
  evaluation of performance

Variants explored, timed with gfortran (13.2) -O3 on Xeon:
- vector_v1:
  - original inference from Pavel
- vector_v2:
  - allocate work arrays just once, using widest layer
  - loop over layers in 2's to avoid pointer calculations and copies
  - speed up, x0.8 relative to v1
- vector_v3:
  - transpose loops
  - slow down, x1.54 relative to v1
- vector_v4:
  - transpose weights with same loop order as v1
  - slow down, x1.03 relative to v1
- array_v1:
  - same structure as v2, working on x(space,feature) input/outputs
  - speed up, x0.41 relative to v1
- array_v2:
  - as for array_v1 but with transposed loop order
  - apply activation function on vector of first index while in cache
  - speed up, x0.35 relative to v1
- array_v3:
  - same structure as v2, working on x(feature,space) input/outputs
  - speed up, x0.58 relative to v1
- Added module dox
- Renamed _v1, _v2 etc to labels
- Added ANN_apply_array_sio to ANN_apply interface
- Replaced "flops" with "MBps" in timing output
- Deleted variants of ANN that did not perform as well as the two
  versions that remain.
* Apply array_sio ANN inference for computation of momentum fluxes

* remove trailing space

* Initial commit
Comment thread src/framework/MOM_ANN.F90 Outdated
Comment thread src/parameterizations/lateral/MOM_hor_visc.F90 Outdated
Comment thread src/parameterizations/lateral/MOM_Zanna_Bolton.F90 Outdated
Comment thread src/parameterizations/lateral/MOM_Zanna_Bolton.F90 Outdated
@Pperezhogin
Copy link
Copy Markdown
Author

Hi @Hallberg-NOAA,

Sorry for the late reply. I modified the code according to your suggestions. Answers did not change on NYU HPC.

Best,
Pavel

Comment thread src/parameterizations/lateral/MOM_Zanna_Bolton.F90
Copy link
Copy Markdown
Member

@Hallberg-NOAA Hallberg-NOAA left a comment

Choose a reason for hiding this comment

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

Apart from restoring the default value of ZB_SCALING to its previous value so that we can follow the established MOM6 procedures for changing parameter defaults, I think that this PR is ready for acceptance.

@Pperezhogin
Copy link
Copy Markdown
Author

Pperezhogin commented Sep 18, 2025

Hi @Hallberg-NOAA

Thanks! I restored the default value. Now a default parameter list for ANN parameterization of mesoscale momentum fluxes is updated as follows:

#override USE_ZB2020 = True
#override ZB_SCALING = 1.0
#override ZB2020_USE_ANN = True
#override ZB2020_ANN_FILE_TALL = relative/or/absolute/path/to/network/parameters/Tall.nc
#override USE_CIRCULATION_IN_HORVISC = True

Copy link
Copy Markdown
Member

@Hallberg-NOAA Hallberg-NOAA left a comment

Choose a reason for hiding this comment

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

This PR now looks good to me. Thank you @Pperezhogin for this contribution of a valuable new set of capabilities.

@Hallberg-NOAA
Copy link
Copy Markdown
Member

This PR has passed pipeline testing at https://gitlab.gfdl.noaa.gov/ogrp/mom6ci/MOM6/-/pipelines/28874 with the expected warnings about a new runtime parameter.

@Hallberg-NOAA Hallberg-NOAA merged commit 1cbebf2 into NOAA-GFDL:dev/gfdl Sep 19, 2025
52 checks passed
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.

3 participants