Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes towards achieving bit-for-bit reproducibility in GC-Classic upon restart #2521

Draft
wants to merge 123 commits into
base: main
Choose a base branch
from

Conversation

lizziel
Copy link
Contributor

@lizziel lizziel commented Oct 15, 2024

Name and Institution (Required)

Name: Lizzie Lundgren
Institution: Harvard University

Describe the update

This PR applies changes in GC-Classic needed to achieve bit-for-bit reproducibility when breaking up a run in time. Please note that with these updates out-of-the-box GC-Classic will still not have reproducibility upon restart due to a limitation of HEMCO. HEMCO reads inputs, including GEOS-Chem restart file variables, as single precision when most of these fields in GEOS-Chem are double precision.

Separately I implemented an update that reads the GEOS-Chem restart file locally, preserving native precision found in the file. With this PR and that update on top of it I am able to achieve bit-for-bit reproducibility in GC-Classic full chemistry benchmark simulation when breaking up the run in time. We are not going to bring in the update to read the restart file locally because we need to use HEMCO for its flexgrid capability. However, I will make that update available as a dev branch should anyone want to use it (see here). An update to HEMCO to read native precision will come later.

Updates within GEOS-Chem that change benchmark output:

  1. Fix a parallelization issue in GEOS-Chem's computation of State_Chm%DryDepNitrogen used in the HEMCO soil NOx extension and saved out to the GEOS-Chem restart file. I believe this was previously undetected because the differences are at the level of double precision numerical noise and thus were previously obscured by outputting to file as single precision. This update includes writing to the restart and diagnostic files using native precision which exposed the issue.
  2. Fix bug in Chem_ORVCsesq restart file entry in GC-Classic fullchem HEMCO_Config.rc.
  3. Register State_Met and State_Chm arrays in GC-Classic History using the native precision used in the model. Previously the precision was unspecified and outputs thus used the default of single precision.
  4. Specify REAL8 as the output precision of State_Diag%SpeciesRst which is the species concentration array written to the restart file GC-Classic. Previously it was set to REAL4.
  5. Convert species concentration units of mol/mol <-> kg/kg in main.F90. This update ensures error is not introduced due to unit conversions used for saving species to the restart file in mol/mol. Conversion to mol/mol must occur every timestep as part of updating diagnostics used for restart variables so that GEOS-Chem Classic can achieve bit-for-bit reproducibility upon breaking up runs. We still use kg/kg dry air throughout main.F90. Conversion from mol/mol to kg/kg occurs at the start of every timestep. This also means that mol/mol is not converted to kg/kg in the subroutine that retrieves restart variables from HEMCO during initialization since it will occur later.
  6. Move setting prescribed CH4 to just after emissions in GC-Classic. It is necessary to move where prescribed CH4 is set because it is dependent on PBL height and previously PBL height was not updated until after Set_CH4 was called. This introduced small differences in GC-Classic when breaking up runs. CH4 is now set using updated PBL height and is grouped with emissions where other prescribed surface VMRs are applied. It is still applied outside of emissions.

This PR also contains several no-diff updates:

  • Fix minor error in checking variables after State_Chm array allocation
  • Remove unused local variables in ucx_mod
  • Move getting restart var DELPDRY to subroutine GC_Get_Restart. This is a no diff update but now allows print of min, max, sum of restart variable Met_DELPDRY to be included with all of the other restart variables retrieved from HEMCO into GEOS-Chem for use upon startup.
  • Add GeosUtil/print_mod.F90 for specialized model print options. This module currently has one subroutine only, to print min, max, and mean of species concentrations to log. It currently only prints if root thread and does not convert units. Optional arguments allow printing one species or a consecutive sequence of species indexes. The current units are printed to the log.
  • Clean up prints in Get_GC_Restart subroutine so that all species initial concentrations are printed to log, including if background values are used (with note about that), as well as initial concentrations of other arrays in the restart file that are read into the model.
  • No diff fixes to SOIL_WETDEP and SOIL_DRYDEP subroutines used to update State_Chm%WetDepNitrogen and State_Chm%DryDepNitrogen used in the Soil NOx extension in HEMCO. Changes include removing the unused level argument and uncommenting a commented out Soil NOx extension logical used to determine whether to call SOIL_WETDEP in Do_Washout_as_Sfc.

Expected changes

This update will cause small differences in all GEOS-Chem Classic simulations.

Reference(s)

None

Related Github Issue

geoschem/HEMCO#18
#111
#2014

yuanjianz and others added 30 commits June 8, 2024 02:02
- use AerMass in OCPISOA to avoid unnecessary recalculation
- removed unnecessary OCPI reference when SVPOA is activated
- replace verbose representation of SOA and OCPI with OCPISOA
…nSVPOA

- also includes some rewrites for better readability
R4N2 was a common product of alkane, isoprene, and monoterpene oxidation
and produced organonitrate SOA but we don’t want ALK4 to produce
organonitrate SOA as discusses in #1625.
A fix from Jared Brewer is included here.

NOTE: The KPP fullchem mechanism has not been rebuilt with these fixes to
facilitate merging these updates up to the latest GEOS-Chem release. These
updates will also need to be added to the custom.eqn file.

Signed-off-by: Melissa Sulprizio <[email protected]>
run/shared/species_database.yml
run/shared/species_database_hg.yml
- Allow for KPP_AbsTol and KPP_RelTol tags.
- Set KPP_AbsTol to 1.0e25 for all dummy species, in order to prevent
  these from being considered when computing the error norm.

Headers/species_mod.F90
- Add KPP_AbsTol and KPP_RelTol to the Species derived type

Headers/species_database_mod.F90
- Add "KPP_AbsTol" and "KPP_RelTol" to the tags array
- Add code to parse KPP_AbsTol and KPP_RelTol tags
- Remove the "places" keyword and just pass the number of decimal
  places, for a consistent appearance
- Trimmed trailing whitespace
- Updated comments

Headers/state_chem_mod.F90
- Add KPP_AbsTol and KPP_RelTol 1-D arrays.  These are initialized
  at the same time as the Map_KppVar mapping array.  This will allow
  us to replace missing values at initialization, and just copy
  the values to ATOL and RTOL each timestep.  This is more efficient.

GeosCore/fullchem_mod.F90
GeosCore/mercury_mod.F90
- Replace missing values in State_Chm%KPP_AbsTol and State_Chm%KPP_RelTol
  with default values.  This preserves the absolute and relative
  tolerances for species that were specified in species_database.yml.
- Copy State_Chm%KPP_AbsTol to the KPP ATOL array
- Copy State_Chm%KPP_RelTol to the KPP RTOL array

Signed-off-by: Bob Yantosca <[email protected]>
CHANGELOG.md
- Added notes describing how we can now define KPP absolute and
  relative tolerances for species in species_database.yml

Signed-off-by: Bob Yantosca <[email protected]>
Headers/roundoff_mod.F90
- Bug fix: First cast to dble or flex.  Then round off if the places
  argument is > 0.  This allows us to just cast w/o rounding off
  if needed.

run/shared/species_database_mod.F90
- Changed 1.0e+25_8 to 1.0e+25 in for KPP_AbsTol (LBRO2H)

CHANGELOG.md
- Updated accordingly

Signed-off-by: Bob Yantosca <[email protected]>
GeosCore/fullchem_mod.F90
- Removed extraneous "<" character

Signed-off-by: Bob Yantosca <[email protected]>
This merge brings PR #2359 (Allow per-species definition of KPP absolute
and relative solver tolerances; Set absolute tolerances of dummy species
to large value, by @yantosca) into the GEOS-Chem 14.5.0 development
stream.

This PR adds structural updates to allow per-species setting of the
KPP absolute & relative tolerances.  This now allows us to assign a
large absolute tolerance (1e25) to KPP dummy species, which excludes
them from the error norm computations.  This results in a faster
simulation at the cost of numerical noise.

Signed-off-by: Bob Yantosca <[email protected]>
This merge brings the hotfix from PR #2363 (Update
setCommonRunSettings.template) on top of PR #2359.

This will allow GCHP benchmarks on the cloud to proceed.

Signed-off-by: Bob Yantosca <[email protected]
run/shared/species_database.yml
run/shared/species_database_hg.yml
- Allow for KPP_AbsTol and KPP_RelTol tags.
- Set KPP_AbsTol to 1.0e25 for all dummy species, in order to prevent
  these from being considered when computing the error norm.

Headers/species_mod.F90
- Add KPP_AbsTol and KPP_RelTol to the Species derived type

Headers/species_database_mod.F90
- Add "KPP_AbsTol" and "KPP_RelTol" to the tags array
- Add code to parse KPP_AbsTol and KPP_RelTol tags
- Remove the "places" keyword and just pass the number of decimal
  places, for a consistent appearance
- Trimmed trailing whitespace
- Updated comments

Headers/state_chem_mod.F90
- Add KPP_AbsTol and KPP_RelTol 1-D arrays.  These are initialized
  at the same time as the Map_KppVar mapping array.  This will allow
  us to replace missing values at initialization, and just copy
  the values to ATOL and RTOL each timestep.  This is more efficient.

GeosCore/fullchem_mod.F90
GeosCore/mercury_mod.F90
- Replace missing values in State_Chm%KPP_AbsTol and State_Chm%KPP_RelTol
  with default values.  This preserves the absolute and relative
  tolerances for species that were specified in species_database.yml.
- Copy State_Chm%KPP_AbsTol to the KPP ATOL array
- Copy State_Chm%KPP_RelTol to the KPP RTOL array

Signed-off-by: Bob Yantosca <[email protected]>
CHANGELOG.md
- Added notes describing how we can now define KPP absolute and
  relative tolerances for species in species_database.yml

Signed-off-by: Bob Yantosca <[email protected]>
Headers/roundoff_mod.F90
- Bug fix: First cast to dble or flex.  Then round off if the places
  argument is > 0.  This allows us to just cast w/o rounding off
  if needed.

run/shared/species_database_mod.F90
- Changed 1.0e+25_8 to 1.0e+25 in for KPP_AbsTol (LBRO2H)

CHANGELOG.md
- Updated accordingly

Signed-off-by: Bob Yantosca <[email protected]>
GeosCore/fullchem_mod.F90
- Removed extraneous "<" character

Signed-off-by: Bob Yantosca <[email protected]>
Fix typo for MassFlux_Entry
This merge brings PR #2315 (ix bugs in PDER, OCPISOA and TotalOC in
complexSOA, by @yuanjianz) into the GEOS-Chem 14.5.0 development stream.

This PR fixes several minor bugs in the complex SOA scheme as described
in issues #2314 and #2321.

Signed-off-by: Bob Yantosca <[email protected]>
Previously these values were zero due to an issue in ISORROPIA. With the
update to HETP we can now enable these cations.

Signed-off-by: Lizzie Lundgren <[email protected]>
This merge brings the GEOS-Chem 14.4.2 release into the GEOS-Chem
14.5.0 development stream.  14.4.2 is a zero-diff update.  The
CHANGELOG.md has been updated accordingly.

Signed-off-by: Bob Yantosca <[email protected]>
This merge brings PR #2398 (Pass non-zero Ca2, Mg, and K cations
to HETP, by @lizziel) into the GEOS-Chem 14.5.0 development stream.

This PR uncomments setting Ca2+, K+, and Mg+ cation values passed
to HETP. Previously these values were zero due to an issue in ISORROPIA.
With the update to HETP we can enable these cations.

Signed-off-by: Bob Yantosca <[email protected]>
Resolved conflicts in:
	CHANGELOG.md
	KPP/fullchem/fullchem.eqn
	KPP/fullchem/fullchem.kpp
	run/shared/species_database.yml

Signed-off-by: Melissa Sulprizio <[email protected]>
This merge brings PR #2352 (Add fixes for ALK4 and R4N2 chemistry from
Brewer et al. (2023, JGR), by @msulprizio) into the GEOS-Chem 14.5.0
development stream.

R4N2 was a common product of alkane, isoprene, and monoterpene oxidation
and produced organonitrate SOA but we don’t want ALK4 to produce
organonitrate SOA as discusses in #1625. A fix from Jared Brewer is
included here.

Signed-off-by: Bob Yantosca <[email protected]>
Due to an oversight, we had forgotten to rebuild the KPP solver files
for PR #2352.  This has now been done.  We will re-tag this PR with
14.5.0-alpha.4 to re-trigger 1-month benchmarks.

Signed-off-by: Bob Yantosca <[email protected]>
run/GCClassic/HISTORY.rc.templates/HISTORY.rc.fullchem
- Change ##'DryDep' -> #'DryDep', which will activate this collection
  in benchmark simulations.

run/GCHP/HISTORY.rc.templates/HISTORY.rc.fullchem
- Change @#'DryDep' -> #'DryDep', which will activate this collection
  in benchmark simulations.
- Also reduce the DryDep collection species to only those species
  we need for benchmark plots/tables

CHANGELOG.md
- Updated accordingly

Signed-off-by: Bob Yantosca <[email protected]>
CHANGELOG.md
- Restored missing line that was inadvertenly deleted
- Place `` around "State_Chm%CH4_EMIS"

run/GCHP/HISTORY.rc.templates/HISTORY.rc.fullchem
- Removed extra slash in comments

Signed-off-by: Bob Yantosca <[email protected]>
This merge brings all of the updates from the GEOS-Chem 14.4.3
"no-diff-to-benchmark" release back into the dev/14.5.0 branch.
We will test this merge with its own alpha benchmark.

Signed-off-by: Bob Yantosca <[email protected]>
…l NOx extension

Yi Wang updated the soil NOx algorithm in HEMCO to utilize soil
temperature as described in Yi Wang et al. (ERL, 2021). Those updates
require the addition of a new meteorology field, TSOIL1, for the soil
temperature in layer 1. This field has been added to State_Met.

Signed-off-by: Melissa Sulprizio <[email protected]>
CHANGELOG.md
- The entry for "Tropopause pressure field..." for 14.4.3 was located
  much further down than it should have been.  We have moved it back to
  to the 14.4.3 section at the top of the file.

Signed-off-by: Bob Yantosca <[email protected]>
This merge brings PR # ( , by @) into

Signed-off-by: Bob Yantosca <[email protected]>
msulprizio and others added 20 commits September 27, 2024 13:45
Fix the bug of using SALA mass to compute coarse-mode TK, TMg, and TCa. Add AlkR factor to the formulas.
The entries for 14.5.0 (unreleased) have been updated to:

- remove duplicate entries
- consistently start lines with past-tense verbs
- remove items listing fixes on updates added in this version

Signed-off-by: Melissa Sulprizio <[email protected]>
Update the description for recent changes related to Ca, K, Mg, and Na in aerosol_thermodynamics_mod.F90
Signed-off-by: Melissa Sulprizio <[email protected]>
For consistency with the literature (e.g. Travis et al, EGUsphere, 2024)
we rename ALK7 to ALK6. See further discussion in Github issue
#2459.

Signed-off-by: Melissa Sulprizio <[email protected]>
For most cases this is double precision. Previously State_Met arrays
were always saved out as single.

Signed-off-by: Lizzie Lundgren <[email protected]>
This is FP for all cases except STATE_PSC which is real4 and DryDepVel
which is always real8.

Signed-off-by: Lizzie Lundgren <[email protected]>
Previously these were written as REAL4 despite being stored in the model
as REAL8.

Signed-off-by: Lizzie Lundgren <[email protected]>
This is a no diff update but now allows print of min, max, sum of
restart variable Met_DELPDRY to be included with all of the other
restart variables retrieved from HEMCO into GEOS-Chem.

Signed-off-by: Lizzie Lundgren <[email protected]>
This module currently has one subroutine only, to print min, max, and
mean of species concentrations to log. It currently only prints if
root thread and does not convert units. Optional arguments allow printing
one species or a consecutive sequence of species indexes.

Signed-off-by: Lizzie Lundgren <[email protected]>
This update ensures error is not introduced due to unit conversions used
for saving species to the restart file in mol/mol. Conversion to
mol/mol must occur every timestep as part of updating diagnostics used for
restart variables so that GEOS-Chem Classic can achieve bit-for-bit
reproducibility upon breaking up runs. We still use kg/kg dry air
throughout main.F90. Conversion from mol/mol to kg/kg occurs at the start
of every timestep. This also means that mol/mol is not converted to kg/kg
in the subroutine that retrieves restart variables from HEMCO during
initialization since it will occur later.

Signed-off-by: Lizzie Lundgren <[email protected]>
It is necessary to move where prescribed CH4 is set because it is
dependent on PBL height and previously PBL height was not updated until
after Set_CH4 was called. This introduces small differences in GC-Classic
when breaking up runs. CH4 is now set using updated PBL height and is
grouped with emissions where other prescribed surface VMRs are applied.
It is still applied outside of emissions.

Signed-off-by: Lizzie Lundgren <[email protected]>
@lizziel lizziel added this to the 14.6.0 milestone Oct 15, 2024
@lizziel lizziel added category: Bug Fix Fixes a previously-reported bug topic: Restart Files Related to GEOS-Chem restart files labels Oct 15, 2024
@yantosca
Copy link
Contributor

yantosca commented Oct 15, 2024

@lizziel, I think I know what this may be. The N deposition code (I think GET_N_DEP) is trying to sum data into a 2-D array within a 3-D parallel loop. This might lead to numerical differences if the loop over levels (L) is parallelized.

You could get around that by declaring the variable to hold the level sum with !$OMP REDUCTION(+: varname). But it might just be more elegant to store the N deposition in a 3-D field of State_Chm which could be summed in the vertical outside of a parallel loop. I think the N deposition code pre-dated the State objects in GC v11-01.

@yantosca yantosca added the topic: Structural Modifications Related to GEOS-Chem structural modifications (as opposed to scientific updates) label Oct 15, 2024
This commit removes the level argument since it is not actually used in
the subroutines. This update also uncomments a Soil NOx extension logical
bracketed around a call to SOIL_WETDEP. The subroutine only changes
arrays used in Soil NOx extension so calling it when the extension is off
is not necessary.

Signed-off-by: Lizzie Lundgren <[email protected]>
@lizziel lizziel self-assigned this Nov 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category: Bug Fix Fixes a previously-reported bug topic: Restart Files Related to GEOS-Chem restart files topic: Structural Modifications Related to GEOS-Chem structural modifications (as opposed to scientific updates)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants