Skip to content

Commit

Permalink
Merge pull request #5 from NOAA-GFDL/feature/init_standard
Browse files Browse the repository at this point in the history
Standardizing module import method for pyFV3
  • Loading branch information
fmalatino authored Feb 21, 2024
2 parents 757874c + 6190a40 commit 1deb6c6
Show file tree
Hide file tree
Showing 36 changed files with 144 additions and 57 deletions.
4 changes: 1 addition & 3 deletions examples/standalone/runfile/acoustics.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@
from ndsl.dsl.dace.orchestration import DaceConfig
from ndsl.dsl.stencil import CompilationConfig
from ndsl.stencils.testing.grid import Grid
from pyFV3._config import DynamicalCoreConfig
from pyFV3.stencils.dyn_core import AcousticDynamics
from pyFV3.testing import TranslateDynCore
from pyFV3 import AcousticDynamics, DynamicalCoreConfig, TranslateDynCore


try:
Expand Down
2 changes: 1 addition & 1 deletion examples/standalone/runfile/compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

import ndsl.dsl.stencil # noqa: F401
from ndsl.comm.null_comm import NullComm
from pyFV3._config import DynamicalCoreConfig
from pyFV3 import DynamicalCoreConfig


try:
Expand Down
6 changes: 2 additions & 4 deletions examples/standalone/runfile/dynamics.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,8 @@
from ndsl.grid import DampingCoefficients, GridData, MetricTerms
from ndsl.stencils.testing import dataset_to_dict
from ndsl.stencils.testing.grid import Grid
from pyFV3 import DynamicalCore, DynamicalCoreConfig
from pyFV3.dycore_state import DycoreState
from pyFV3.initialization.baroclinic import init_baroclinic_state
from pyFV3.testing import TranslateFVDynamics
from pyFV3 import DycoreState, DynamicalCore, DynamicalCoreConfig, TranslateFVDynamics
from pyFV3.initialization.test_cases import init_baroclinic_state


def parse_args() -> Namespace:
Expand Down
12 changes: 9 additions & 3 deletions pyFV3/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
from ._config import DynamicalCoreConfig
from .dycore_state import DycoreState
from .stencils.fv_dynamics import DynamicalCore
from .stencils.fv_subgridz import DryConvectiveAdjustment
from .wrappers.geos_wrapper import GeosDycoreWrapper
from .stencils import DryConvectiveAdjustment, DynamicalCore


"""
DynamicalCoreConfig: Configuration for the FV3 dynamical core
DycoreState: Dataclass containing state of the dynamical core
DryConvectiveAdjustment: Sub-grid dry convective adjustment
DynamicalCore: The FV3 dynamical core
GeosDycoreWrapper: Interface to the dycore for the GEOS model
"""

__version__ = "0.2.0"
5 changes: 5 additions & 0 deletions pyFV3/initialization/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
from .analytic_init import init_analytic_state


"""
init_analytic_state: Creates dycore state object out of analytic initial conditions
"""
Empty file.
65 changes: 65 additions & 0 deletions pyFV3/stencils/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
from .a2b_ord4 import AGrid2BGridFourthOrder
from .c_sw import CGridShallowWaterDynamics
from .d2a2c_vect import DGrid2AGrid2CGridVectors
from .d_sw import DGridShallowWaterLagrangianDynamics
from .del2cubed import HyperdiffusionDamping
from .delnflux import DelnFlux, DelnFluxNoSG
from .divergence_damping import DivergenceDamping
from .dyn_core import AcousticDynamics
from .fillz import FillNegativeTracerValues
from .fv_dynamics import DynamicalCore
from .fv_subgridz import DryConvectiveAdjustment
from .fvtp2d import FiniteVolumeTransport
from .fxadv import FiniteVolumeFluxPrep
from .map_single import MapSingle
from .mapn_tracer import MapNTracer
from .neg_adj3 import AdjustNegativeTracerMixingRatio
from .nh_p_grad import NonHydrostaticPressureGradient
from .pk3_halo import PK3Halo
from .ray_fast import RayleighDamping
from .remap_profile import RemapProfile
from .remapping import LagrangianToEulerian
from .riem_solver3 import NonhydrostaticVerticalSolver
from .riem_solver_c import NonhydrostaticVerticalSolverCGrid
from .saturation_adjustment import SatAdjust3d
from .sim1_solver import Sim1Solver
from .tracer_2d_1l import TracerAdvection
from .updatedzc import UpdateGeopotentialHeightOnCGrid
from .updatedzd import UpdateHeightOnDGrid
from .xppm import XPiecewiseParabolic
from .yppm import YPiecewiseParabolic


"""
AGrid2BGridFourthOrder: Converts field from A grid to B grid
CGridShallowWaterDynamics: C-grid shallow water solver
DGrid2AGrid2CGridVectors: Converts velocities from the D-grid to the A-grid and C-grid
DGridShallowWaterLagrangianDynamics: D-grid shallow water solver
HyperdiffusionDamping: Performs hyper diffusion filtering
DelnFlux: Computes damping fluxes and applies them to a field
DelnFluxNoSG: Only computes damping fluxes, but does not apply them
DivergenceDamping: Diffusively damps the divergence field
AcousticDynamics: Acoustic loop of the dynamical core
FillNegativeTracerValues: Fixes negative tracer values
DynamicalCore: The FV3 dynamical core
DryConvectiveAdjustment: Performs subgrid dry convective adjustment mixing
FiniteVolumeTransport: Calculates fluxes for finite volume transport
FiniteVolumeFluxPrep: Prepares fluxes for finite volume transport
MapSingle: Remaps vertical layers for one field
MapNTracer: Remaps vertical layers for all tracer species
AdjustNegativeTracerMixingRatio: Updates winds from pressure gradients
PK3Halo: Calculates pressure raised to kappa power in halos
RayleighDamping: Applies Rayleigh damping
RemapProfile: Calculates cubic spline interpolation for vertical remapping
LagrangianToEulerian: Remaps Lagrangian surfaces onto Eulerian coordinates
NonhydrostaticVerticalSolver: Calculates nonhydrostatic w and p after advection
NonhydrostaticVerticalSolverCGrid: Calculates nonhydrostatic w and p after
C-grid advection
SatAdjust3d: Fast microphysical phase changes
Sim1Solver: Semi-implict method solver
TracerAdvection: Advects tracers
UpdateGeopotentialHeightOnCGrid: Updates cell heights on C-grid
UpdateHeightOnDGrid: Updates cell heights on D-grid
XPiecewiseParabolic: Piecewise parabolic method advection in x-direction
YPiecewiseParabolic: Piecewise parabolic method advection in y-direction
"""
9 changes: 9 additions & 0 deletions pyFV3/testing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,12 @@
from .translate_dyncore import TranslateDynCore
from .translate_fvdynamics import TranslateDycoreFortranData2Py, TranslateFVDynamics
from .validation import enable_selective_validation


"""
MapSingleFactory: Pool of objects to apply vertical remapping to multiple fields
TranslateDynCore: Translate test for dynamical core
TranslateDycoreFortranData2Py: Infrastructure to format serialized fortran data for translate tests
TranslateFVDynamics: Translate test of acoustic dynamics
enable_selective_validation: Allows for selection of data for translate tests
"""
3 changes: 2 additions & 1 deletion pyFV3/testing/translate_dyncore.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
from ndsl.namelist import Namelist
from ndsl.quantity import Quantity
from ndsl.stencils.testing import ParallelTranslate2PyState
from pyFV3 import DycoreState, DynamicalCoreConfig
from pyFV3._config import DynamicalCoreConfig
from pyFV3.dycore_state import DycoreState


class TranslateDynCore(ParallelTranslate2PyState):
Expand Down
10 changes: 10 additions & 0 deletions pyFV3/wrappers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from .geos_wrapper import GeosDycoreWrapper, MemorySpace, StencilBackendCompilerOverride


"""
GeosDycoreWrapper: Main class, wrap the digest the GEOS interface call
and execute the pyFV3 numerics
MemorySpace: Flag describing the memory space for both side of the interface
StencilBackendCompilerOverride: Custom workaround to align gt backends
build with orchestrated backends
"""
Empty file added tests/__init__.py
Empty file.
Empty file added tests/mpi/__init__.py
Empty file.
9 changes: 4 additions & 5 deletions tests/mpi/test_doubly_periodic.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

import ndsl.dsl.stencil
import ndsl.stencils.testing
import pyFV3
import pyFV3._config
import pyFV3.initialization.test_cases.initialize_baroclinic as baroclinic_init
from ndsl.comm.communicator import CubedSphereCommunicator, TileCommunicator
from ndsl.comm.mpi import MPIComm
Expand All @@ -13,12 +11,13 @@
from ndsl.grid import DampingCoefficients, GridData, MetricTerms
from ndsl.initialization.allocator import QuantityFactory
from ndsl.initialization.sizer import SubtileGridSizer
from pyFV3 import DynamicalCore, DynamicalCoreConfig


def setup_dycore() -> Tuple[pyFV3.DynamicalCore, List[Any]]:
def setup_dycore() -> Tuple[DynamicalCore, List[Any]]:
backend = "numpy"
layout = (3, 3)
config = pyFV3.DynamicalCoreConfig(
config = DynamicalCoreConfig(
layout=layout,
npx=13,
npy=13,
Expand Down Expand Up @@ -117,7 +116,7 @@ def setup_dycore() -> Tuple[pyFV3.DynamicalCore, List[Any]]:
grid_indexing=grid_indexing,
)

dycore = pyFV3.DynamicalCore(
dycore = DynamicalCore(
comm=communicator,
grid_data=grid_data,
stencil_factory=stencil_factory,
Expand Down
2 changes: 1 addition & 1 deletion tests/savepoint/translate/translate_a2b_ord4.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from ndsl.dsl.dace.orchestration import orchestrate
from ndsl.dsl.stencil import StencilFactory
from ndsl.namelist import Namelist
from pyFV3.stencils.divergence_damping import DivergenceDamping
from pyFV3.stencils import DivergenceDamping
from pyFV3.testing import TranslateDycoreFortranData2Py


Expand Down
2 changes: 1 addition & 1 deletion tests/savepoint/translate/translate_c_sw.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from ndsl.dsl.stencil import StencilFactory
from ndsl.initialization.allocator import QuantityFactory
from ndsl.namelist import Namelist
from pyFV3.stencils.c_sw import CGridShallowWaterDynamics
from pyFV3.stencils import CGridShallowWaterDynamics
from pyFV3.testing import TranslateDycoreFortranData2Py


Expand Down
2 changes: 1 addition & 1 deletion tests/savepoint/translate/translate_d2a2c_vect.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from ndsl.dsl.stencil import StencilFactory
from ndsl.namelist import Namelist
from pyFV3.stencils.d2a2c_vect import DGrid2AGrid2CGridVectors
from pyFV3.stencils import DGrid2AGrid2CGridVectors
from pyFV3.testing import TranslateDycoreFortranData2Py


Expand Down
2 changes: 1 addition & 1 deletion tests/savepoint/translate/translate_del2cubed.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from ndsl.dsl.stencil import StencilFactory
from ndsl.namelist import Namelist
from pyFV3.stencils.del2cubed import HyperdiffusionDamping
from pyFV3.stencils import HyperdiffusionDamping
from pyFV3.testing import TranslateDycoreFortranData2Py


Expand Down
2 changes: 1 addition & 1 deletion tests/savepoint/translate/translate_divergencedamping.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from ndsl.constants import Z_DIM
from ndsl.dsl.stencil import StencilFactory
from ndsl.namelist import Namelist
from pyFV3.stencils.divergence_damping import DivergenceDamping
from pyFV3.stencils import DivergenceDamping
from pyFV3.testing import TranslateDycoreFortranData2Py


Expand Down
6 changes: 3 additions & 3 deletions tests/savepoint/translate/translate_fvsubgridz.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from types import SimpleNamespace

import ndsl.dsl.gt4py_utils as utils
import pyFV3.stencils.fv_subgridz as fv_subgridz
from ndsl.constants import X_DIM, Y_DIM, Z_DIM, Z_INTERFACE_DIM
from ndsl.dsl.stencil import StencilFactory
from ndsl.namelist import Namelist
from ndsl.stencils.testing import ParallelTranslateBaseSlicing
from pyFV3 import DryConvectiveAdjustment


# NOTE, does no halo updates, does not need to be a Parallel test,
Expand Down Expand Up @@ -181,7 +181,7 @@ def __init__(

def compute_parallel(self, inputs, communicator):
state = self.state_from_inputs(inputs)
fvsubgridz = fv_subgridz.DryConvectiveAdjustment(
fvsubgridz = DryConvectiveAdjustment(
self.stencil_factory,
self.grid.quantity_factory,
self.namelist.nwat,
Expand All @@ -201,7 +201,7 @@ def compute_parallel(self, inputs, communicator):
def compute_sequential(self, inputs_list, communicator_list):
state_list = self.state_list_from_inputs_list(inputs_list)
for state in state_list:
fvsubgridz = fv_subgridz.DryConvectiveAdjustment(
fvsubgridz = DryConvectiveAdjustment(
self.stencil_factory,
self.grid.quantity_factory,
self.namelist.nwat,
Expand Down
2 changes: 1 addition & 1 deletion tests/savepoint/translate/translate_fvtp2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from ndsl.dsl.stencil import StencilFactory
from ndsl.dsl.typing import Float
from ndsl.namelist import Namelist
from pyFV3.stencils.fvtp2d import FiniteVolumeTransport
from pyFV3.stencils import FiniteVolumeTransport
from pyFV3.testing import TranslateDycoreFortranData2Py


Expand Down
2 changes: 1 addition & 1 deletion tests/savepoint/translate/translate_fxadv.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from ndsl.constants import X_DIM, Y_DIM, Z_DIM
from ndsl.dsl.stencil import StencilFactory
from ndsl.namelist import Namelist
from pyFV3.stencils.fxadv import FiniteVolumeFluxPrep
from pyFV3.stencils import FiniteVolumeFluxPrep
from pyFV3.testing import TranslateDycoreFortranData2Py
from pyFV3.utils.functional_validation import get_subset_func

Expand Down
2 changes: 1 addition & 1 deletion tests/savepoint/translate/translate_neg_adj3.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import ndsl.dsl.gt4py_utils as utils
from ndsl.dsl.stencil import StencilFactory
from ndsl.namelist import Namelist
from pyFV3.stencils.neg_adj3 import AdjustNegativeTracerMixingRatio
from pyFV3.stencils import AdjustNegativeTracerMixingRatio
from pyFV3.testing import TranslateDycoreFortranData2Py


Expand Down
2 changes: 1 addition & 1 deletion tests/savepoint/translate/translate_pk3_halo.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from ndsl.dsl.stencil import StencilFactory
from ndsl.namelist import Namelist
from pyFV3.stencils.pk3_halo import PK3Halo
from pyFV3.stencils import PK3Halo
from pyFV3.testing import TranslateDycoreFortranData2Py


Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from typing import Any, Dict

import pyFV3
from ndsl.dsl.stencil import StencilFactory
from ndsl.namelist import Namelist
from pyFV3 import DynamicalCoreConfig
from pyFV3.stencils import temperature_adjust
from pyFV3.stencils.dyn_core import get_nk_heat_dissipation
from pyFV3.testing import TranslateDycoreFortranData2Py
Expand All @@ -18,7 +18,7 @@ def __init__(
stencil_factory: StencilFactory,
):
super().__init__(grid, namelist, stencil_factory)
dycore_config = pyFV3.DynamicalCoreConfig.from_namelist(namelist)
dycore_config = DynamicalCoreConfig.from_namelist(namelist)
self.namelist = dycore_config
n_adj = get_nk_heat_dissipation(
config=dycore_config.d_grid_shallow_water,
Expand Down
2 changes: 1 addition & 1 deletion tests/savepoint/translate/translate_ray_fast.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from ndsl.dsl.stencil import StencilFactory
from ndsl.namelist import Namelist
from pyFV3.stencils.ray_fast import RayleighDamping
from pyFV3.stencils import RayleighDamping
from pyFV3.testing import TranslateDycoreFortranData2Py


Expand Down
2 changes: 1 addition & 1 deletion tests/savepoint/translate/translate_remapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from ndsl.dsl.stencil import StencilFactory
from ndsl.namelist import Namelist
from pyFV3 import DynamicalCoreConfig
from pyFV3.stencils.remapping import LagrangianToEulerian
from pyFV3.stencils import LagrangianToEulerian
from pyFV3.testing import TranslateDycoreFortranData2Py


Expand Down
2 changes: 1 addition & 1 deletion tests/savepoint/translate/translate_riem_solver3.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from ndsl.dsl.stencil import StencilFactory
from ndsl.namelist import Namelist
from pyFV3 import _config as spec
from pyFV3.stencils.riem_solver3 import NonhydrostaticVerticalSolver
from pyFV3.stencils import NonhydrostaticVerticalSolver
from pyFV3.testing import TranslateDycoreFortranData2Py


Expand Down
2 changes: 1 addition & 1 deletion tests/savepoint/translate/translate_riem_solver_c.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from ndsl.dsl.stencil import StencilFactory
from ndsl.namelist import Namelist
from pyFV3.stencils.riem_solver_c import NonhydrostaticVerticalSolverCGrid
from pyFV3.stencils import NonhydrostaticVerticalSolverCGrid
from pyFV3.testing import TranslateDycoreFortranData2Py


Expand Down
5 changes: 2 additions & 3 deletions tests/savepoint/translate/translate_satadjust3d.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import pyFV3
from ndsl.dsl.stencil import StencilFactory
from ndsl.namelist import Namelist
from pyFV3 import DynamicalCoreConfig
from pyFV3.stencils.saturation_adjustment import SatAdjust3d
from pyFV3.stencils import SatAdjust3d
from pyFV3.testing import TranslateDycoreFortranData2Py


Expand Down Expand Up @@ -61,7 +60,7 @@ def __init__(
},
"cappa": {},
}
self.namelist = pyFV3.DynamicalCoreConfig.from_namelist(namelist)
self.namelist = DynamicalCoreConfig.from_namelist(namelist)
self.stencil_factory = stencil_factory

def compute_from_storage(self, inputs):
Expand Down
Loading

0 comments on commit 1deb6c6

Please sign in to comment.