Skip to content

Eos class#2

Closed
adcroft wants to merge 2 commits into
dev/gfdlfrom
eos-class
Closed

Eos class#2
adcroft wants to merge 2 commits into
dev/gfdlfrom
eos-class

Conversation

@adcroft
Copy link
Copy Markdown
Owner

@adcroft adcroft commented Nov 15, 2023

Testing GH workflow

- Added a base class in MOM_EOS_base_type.F90
- All EOS modules now extend this base class
  - This reduces replicated code between the EOS modules
- All existing APIs in MOM_EOS now avoid branching for the type of
  EOS and ultimately pass through to a low-level elemental function
  implementation of the actual EOS
- Added a new elemental function exposed by MOM_EOS
  (currently not used in the main model)
- There is a speed up over the previous form of EOS due to the
  reduced branching
  - For some functions, a local implementation of the base class member is
    needed to gain performance. I deliberately did not implement this
    optimization for UNESCO or Jackett06 so that the generic implementation
    of the base class is utilized and we have code coverage.
@codecov
Copy link
Copy Markdown

codecov Bot commented Nov 15, 2023

Codecov Report

Attention: 95 lines in your changes are missing coverage. Please review.

Comparison is base (cce4b3d) 37.45% compared to head (d752193) 37.49%.

Files Patch % Lines
src/equation_of_state/MOM_EOS.F90 38.09% 45 Missing and 7 partials ⚠️
src/equation_of_state/MOM_EOS_base_type.F90 54.09% 27 Missing and 1 partial ⚠️
src/equation_of_state/MOM_EOS_Roquet_SpV.F90 97.61% 2 Missing and 1 partial ⚠️
src/equation_of_state/MOM_EOS_Roquet_rho.F90 97.34% 2 Missing and 1 partial ⚠️
src/equation_of_state/MOM_EOS_TEOS10.F90 90.90% 3 Missing ⚠️
src/equation_of_state/MOM_EOS_Wright_full.F90 96.51% 2 Missing and 1 partial ⚠️
src/equation_of_state/MOM_EOS_Wright_red.F90 96.47% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##           dev/gfdl       #2      +/-   ##
============================================
+ Coverage     37.45%   37.49%   +0.03%     
============================================
  Files           270      271       +1     
  Lines         79763    79533     -230     
  Branches      14830    14816      -14     
============================================
- Hits          29879    29819      -60     
+ Misses        44349    44175     -174     
- Partials       5535     5539       +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

- Added rules to .testing/Makefile to invoke build.timing, run.timing for the
  "target" code checked out for regression tests
- Appended to existing GH "perfmon" workflow
@adcroft adcroft closed this Nov 15, 2023
adcroft pushed a commit that referenced this pull request Apr 29, 2025
Blank commit after squash/rebase was handled on command line
adcroft pushed a commit that referenced this pull request May 13, 2025
Blank commit after squash/rebase was handled on command line
adcroft added a commit that referenced this pull request Sep 29, 2025
* Add MOM_ANN module

* Mesoscale momentum parameterization with ANN

- 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
```

* Mesoscale momentum parameterization with ANN (#2)

Blank commit after squash/rebase was handled on command line

* Moved MOM_ANN.F90 to src/framework/

* Minor refactor of MOM_ANN

- 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

* Adds unit tests and timing test to MOM_ANN

- 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

* Adding multiple forms of 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

* Renamed ANN variants and added some module documentation

- 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

* Removed alternative variants of ANN in favor of optimized

- Deleted variants of ANN that did not perform as well as the two
  versions that remain.

* Apply array_sio function in ANN inference for momentum fluxes (#5)

* Apply array_sio ANN inference for computation of momentum fluxes

* remove trailing space

* Initial commit

* address Robert Hallberg code review

* Restore deafult value of ZB_SCALING coefficient

---------

Co-authored-by: Alistair Adcroft <Alistair.Adcroft@noaa.gov>
Co-authored-by: Alistair Adcroft <adcroft@users.noreply.github.com>
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.

1 participant