Skip to content

Commit

Permalink
Checkpointer validates on C_SW and D_SW (#320)
Browse files Browse the repository at this point in the history
* fix variable mismatch

* reinitialize dycore to reset temp storages

* fix var name

* fvdynamics-out tracers in compute domain only

* update data version

* revert comment

* fix driver subset

* clean up translate test

* add comment

* Bump to 8.1.3

* add h5netcdf to requirement

* specify xarray engine

* switch to engine netcdf4

* Revert "switch to engine netcdf4"

This reverts commit 50ea453.

* Revert "specify xarray engine"

This reverts commit 42cfc9b.

* Revert "add h5netcdf to requirement"

This reverts commit 3e9d080.

Co-authored-by: Jeremy McGibbon <[email protected]>
  • Loading branch information
elynnwu and mcgibbon authored Sep 20, 2022
1 parent 75de30b commit 770da80
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 135 deletions.
2 changes: 1 addition & 1 deletion Makefile.data_download
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
REGRESSION_DATA_STORAGE_BUCKET = gs://vcm-fv3gfs-serialized-regression-data
ROOT_DIR:=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
EXPERIMENT ?=c12_6ranks_standard
FORTRAN_SERIALIZED_DATA_VERSION=8.1.1
FORTRAN_SERIALIZED_DATA_VERSION=8.1.3
TARGET ?=dycore
TEST_DATA_ROOT ?=$(ROOT_DIR)/test_data/
TEST_DATA_HOST ?=$(TEST_DATA_ROOT)/$(FORTRAN_SERIALIZED_DATA_VERSION)/$(EXPERIMENT)/$(TARGET)
Expand Down
5 changes: 3 additions & 2 deletions fv3core/pace/fv3core/stencils/dyn_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,8 @@ def _checkpoint_dsw_in(self, state: DycoreState):
ucd=state.uc,
vcd=state.vc,
wd=state.w,
delpcd=self.cgrid_shallow_water_lagrangian_dynamics.delpc,
# delpc is a temporary and not a variable in D_SW savepoint
delpcd=self._vt,
delpd=state.delp,
ud=state.u,
vd=state.v,
Expand All @@ -727,7 +728,7 @@ def _checkpoint_dsw_out(self, state: DycoreState):
ucd=state.uc,
vcd=state.vc,
wd=state.w,
delpcd=self.cgrid_shallow_water_lagrangian_dynamics.delpc,
delpcd=self._vt,
delpd=state.delp,
ud=state.u,
vd=state.v,
Expand Down
60 changes: 8 additions & 52 deletions fv3core/pace/fv3core/testing/translate_fvdynamics.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
from pace.util.grid import GridData


ADVECTED_TRACER_NAMES = utils.tracer_variables[: fv_dynamics.NQ]


class TranslateDycoreFortranData2Py(TranslateFortranData2Py):
def __init__(
self,
Expand Down Expand Up @@ -234,14 +231,14 @@ def __init__(
"v": grid.x3d_domain_dict(),
"w": {},
"delz": {},
"qvapor": {},
"qliquid": {},
"qice": {},
"qrain": {},
"qsnow": {},
"qgraupel": {},
"qo3mr": {},
"qsgs_tke": {},
"qvapor": grid.compute_dict(),
"qliquid": grid.compute_dict(),
"qice": grid.compute_dict(),
"qrain": grid.compute_dict(),
"qsnow": grid.compute_dict(),
"qgraupel": grid.compute_dict(),
"qo3mr": grid.compute_dict(),
"qsgs_tke": grid.compute_dict(),
"qcld": {},
"ps": {},
"pe": {
Expand Down Expand Up @@ -340,8 +337,6 @@ def compute_parallel(self, inputs, communicator):
)
self.dycore.step_dynamics(state, pace.util.NullTimer())
outputs = self.outputs_from_state(state)
for name, value in outputs.items():
outputs[name] = self.subset_output(name, value)
return outputs

def outputs_from_state(self, state: dict):
Expand All @@ -364,42 +359,3 @@ def compute_sequential(self, *args, **kwargs):
f"{self.__class__} only has a mpirun implementation, "
"not running in mock-parallel"
)

def subset_output(self, varname: str, output):
"""
Given an output array, return the slice of the array which we'd
like to validate against reference data
"""
if self.dycore is None:
raise RuntimeError(
"cannot call subset_output before calling compute_parallel "
"to initialize dycore"
)
if hasattr(self.dycore, "selective_names") and (
varname in self.dycore.selective_names # type: ignore
):
return_value = self.dycore.subset_output(varname, output) # type: ignore

if varname in ADVECTED_TRACER_NAMES:

def get_compute_domain_k_interfaces(
instance,
):
try:
origin = instance.grid_indexing.origin_compute()
domain = instance.grid_indexing.domain_compute(add=(0, 0, 1))
except AttributeError:
origin = instance.grid.compute_origin()
domain = instance.grid.domain_shape_compute(add=(0, 0, 1))
return origin, domain

origin, domain = get_compute_domain_k_interfaces(
self.dycore.tracer_advection
)
self._validation_slice = tuple(
slice(start, start + n) for start, n in zip(origin, domain)
)
return_value = output[self._validation_slice]
else:
return_value = output
return return_value
2 changes: 0 additions & 2 deletions physics/tests/savepoint/translate/translate_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,4 @@ def compute_parallel(self, inputs, communicator):
self.dycore = driver.dycore

outputs = self.outputs_from_state(driver.state.dycore_state)
for name, value in outputs.items():
outputs[name] = self.subset_output(name, value)
return outputs
3 changes: 3 additions & 0 deletions tests/mpi/test_checkpoints.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import dataclasses
import os
from datetime import timedelta
from typing import List, Tuple

import dacite
Expand Down Expand Up @@ -137,6 +138,7 @@ def test_fv_dynamics(
phis=state.phis,
state=state,
checkpointer=validation,
timestep=timedelta(seconds=dycore_config.dt_atmos),
)
with validation.trial():
dycore.step_dynamics(state)
Expand All @@ -162,6 +164,7 @@ def _calibrate_thresholds(
phis=state.phis,
state=state,
checkpointer=calibration,
timestep=timedelta(seconds=dycore_config.dt_atmos),
)
for i in range(n_trials):
print(f"running calibration trial {i}")
Expand Down
Loading

0 comments on commit 770da80

Please sign in to comment.