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

Isolate stencil tests #281

Merged
merged 35 commits into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
5e5ac07
- move stencil tests to their own module
halungge Sep 27, 2023
e8e148a
(fix) fix test: use explicit numpy cast for numpy slicing.
halungge Sep 27, 2023
29a457f
(fix) pre-commit
halungge Sep 27, 2023
eadf66f
Merge branch 'isolate_stencil_tests' of github.com:C2SM/icon4py into …
halungge Sep 27, 2023
6e22e82
icon4pytools:
halungge Sep 27, 2023
77c78ad
move interpolation stencil tests to tests/stencil_test module
halungge Sep 27, 2023
9f6a6d8
(fix) pre-commit for icon4pytools
halungge Sep 27, 2023
e937faa
clean up test hierarchy in diffusion
halungge Sep 27, 2023
0144da5
disentangle test structure in model/common
halungge Sep 27, 2023
2d5fbd7
(fix) pre-commit
halungge Sep 27, 2023
971c5d9
update README.md s
halungge Sep 28, 2023
bf7f9e5
remove TEST section in isort config of model/atmosphere diffusion
halungge Sep 28, 2023
3c390d7
- remove tox.ini from root folder
halungge Sep 28, 2023
3276afd
merge main
halungge Oct 3, 2023
b228baa
clean up leftovers from merge
halungge Oct 3, 2023
0c7b0d6
move stencil tests in advection to stencil_tests folder
halungge Oct 3, 2023
74d819e
update README.md
halungge Oct 4, 2023
210f009
add pytest config to pytest.ini
halungge Oct 6, 2023
10d1e7e
Revert "add pytest config to pytest.ini"
halungge Oct 6, 2023
5814803
merge from main
halungge Oct 9, 2023
6905ccf
merge from main (nh_solve)
halungge Oct 9, 2023
a2201d4
add pytest.ini for spack build in spack jenkins folder
halungge Oct 9, 2023
b326cb7
re organize tests in dycore
halungge Oct 9, 2023
1f79aa3
add conftest.py in diffusion/tests
halungge Oct 9, 2023
cd7dd27
split conftest in dycore tests
halungge Oct 9, 2023
427449a
pre-commit fixes
halungge Oct 9, 2023
b051ae1
port test_compute_airmass.py to StencilTest
halungge Oct 10, 2023
117b98c
port test_velocity_advection_stencil_20.py to StencilTest
halungge Oct 10, 2023
eab6d52
port test_velocity_advection_stencil_19.py to StencilTest
halungge Oct 10, 2023
a1b5aa4
port test_truly_horizontal_diffusion_nabla_of_theta_over_steep_points…
halungge Oct 10, 2023
b565792
port test_mo_velocity_advection_stencil_16.py to StencilTest
halungge Oct 10, 2023
063e20c
port test_mo_solve_nonhydro_stencil_21.py to StencilTest
halungge Oct 10, 2023
5c87c36
port test_mo_solve_nonhydro_stencil_20.py to StencilTest
halungge Oct 10, 2023
771ecad
port test_mo_solve_nonhydro_stencil_51.py to StencilTest
halungge Oct 10, 2023
8e191c7
Merge branch 'main' into isolate_stencil_tests
halungge Oct 11, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion model/atmosphere/advection/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ warn_unused_ignores = true

[tool.pytest.ini_options]
markers = 'slow_tests: marks tests as slow'
testpaths = ['tests', 'advection_tests']
testpaths = ['tests']

[tool.setuptools.dynamic]
version = {attr = 'icon4py.model.atmosphere.advection.__init__.__version__'}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,11 @@
# distribution for a copy of the license or check <https://www.gnu.org/licenses/>.
#
# SPDX-License-Identifier: GPL-3.0-or-later
import pytest
from gt4py.next.program_processors.runners.roundtrip import executor

from icon4py.model.common.test_utils.simple_mesh import SimpleMesh


BACKENDS = {"embedded": executor}
MESHES = {"simple_mesh": SimpleMesh()}


@pytest.fixture(
ids=MESHES.keys(),
params=MESHES.values(),
from icon4py.model.common.test_utils.helpers import backend, mesh # noqa F401
from icon4py.model.common.test_utils.pytest_config import ( # noqa: F401
pytest_addoption,
pytest_configure,
pytest_generate_tests,
pytest_runtest_setup,
)
def mesh(request):
return request.param


@pytest.fixture(ids=BACKENDS.keys(), params=BACKENDS.values())
def backend(request):
return request.param
8 changes: 3 additions & 5 deletions model/atmosphere/diffusion/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ target-version = ['py310']
[tool.coverage]

[tool.coverage.html]
directory = 'diffusion_tests/_reports/coverage_html'
directory = 'tests/_reports/coverage_html'

[tool.coverage.paths]
source = ['src/icon4py/model/']
Expand Down Expand Up @@ -109,10 +109,8 @@ warn_unused_ignores = true
[tool.pytest]

[tool.pytest.ini_options]
markers = [
"datatest: test depending on serialized data generated by a full model run"
]
testpaths = ['tests', 'diffusion_tests']
markers = ['datatest: test that use serialized data']
testpaths = ['tests']

[tool.setuptools.dynamic]
version = {attr = 'icon4py.model.atmosphere.diffusion.__init__.__version__'}
Expand Down
3 changes: 2 additions & 1 deletion model/atmosphere/diffusion/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
Workaround for pytest not discovering those configuration function, when they are added to the
diffusion_test/conftest.py folder
"""
from icon4py.model.common.test_utils.pytest_config import ( # noqa: F401
from icon4py.model.common.test_utils.helpers import backend, mesh # noqa: F401 # fixtures
from icon4py.model.common.test_utils.pytest_config import ( # noqa: F401 # pytest config
pytest_addoption,
pytest_configure,
pytest_generate_tests,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
import pytest

from icon4py.model.atmosphere.diffusion.diffusion import DiffusionConfig, DiffusionType
from icon4py.model.common.test_utils.fixtures import ( # noqa: F401 # import fixtures from test_utils package
backend,
from icon4py.model.common.test_utils.datatest_helpers import ( # noqa: F401 # import fixtures from test_utils package
damping_height,
data_provider,
datapath,
Expand All @@ -25,7 +24,6 @@
icon_grid,
interpolation_savepoint,
linit,
mesh,
metrics_savepoint,
ndyn_substeps,
processor_props,
Expand All @@ -43,7 +41,7 @@

@pytest.fixture
def r04b09_diffusion_config(
ndyn_substeps, # noqa: F811 # imported `ndyn_substeps` fxiture
ndyn_substeps, # noqa: F811 # imported `ndyn_substeps` fixture
) -> DiffusionConfig:
"""
Create DiffusionConfig matching MCH_CH_r04b09_dsl.
Expand Down
14 changes: 1 addition & 13 deletions model/atmosphere/dycore/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,7 @@
# SPDX-License-Identifier: GPL-3.0-or-later


from icon4py.model.common.test_utils.fixtures import ( # noqa F401
backend,
damping_height,
data_provider,
datapath,
download_ser_data,
grid_savepoint,
icon_grid,
linit,
mesh,
step_date_exit,
step_date_init,
)
from icon4py.model.common.test_utils.helpers import backend, mesh # noqa F401
from icon4py.model.common.test_utils.pytest_config import ( # noqa: F401
pytest_addoption,
pytest_configure,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,12 @@ def download_ser_data(request, processor_props, ranked_data_path, pytestconfig):

Session scoped fixture which is a prerequisite of all the other fixtures in this file.
"""
if not pytestconfig.getoption("datatest"):
pytest.skip("not running datatest marked tests")
try:
has_data_marker = any(map(lambda i: i.iter_markers(name="datatest"), request.node.items))
if not has_data_marker or not request.config.getoption("datatest"):
pytest.skip("not running datatest marked tests")
except ValueError:
pass

try:
uri = data_uris[processor_props.comm_size]
Expand Down
16 changes: 16 additions & 0 deletions model/common/src/icon4py/model/common/test_utils/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,22 @@
from .simple_mesh import SimpleMesh


MESHES = {"simple_mesh": SimpleMesh()}


@pytest.fixture(
ids=MESHES.keys(),
params=MESHES.values(),
)
def mesh(request):
return request.param


@pytest.fixture
def backend(request):
return request.param


def _shape(
mesh,
*dims: gt_common.Dimension,
Expand Down
55 changes: 8 additions & 47 deletions model/common/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,56 +10,17 @@
# distribution for a copy of the license or check <https://www.gnu.org/licenses/>.
#
# SPDX-License-Identifier: GPL-3.0-or-later
import pytest

from icon4py.model.common.test_utils.data_handling import download_and_extract
from icon4py.model.common.test_utils.fixtures import ( # noqa: F401
backend,
base_path,
damping_height,
data_provider,
datapath,
decomposition_info,
download_ser_data,
grid_savepoint,
icon_grid,
interpolation_savepoint,
mesh,
processor_props,
ranked_data_path,
)
from icon4py.model.common.test_utils.pytest_config import ( # noqa: F401
"""
Initialize pytest.

Workaround for pytest not discovering those configuration function, when they are added to the
diffusion_test/conftest.py folder
"""
from icon4py.model.common.test_utils.helpers import backend, mesh # noqa: F401 # fixtures
from icon4py.model.common.test_utils.pytest_config import ( # noqa: F401 # pytest config
pytest_addoption,
pytest_configure,
pytest_generate_tests,
pytest_runtest_setup,
)


grids_path = base_path.joinpath("grids")
r04b09_dsl_grid_path = grids_path.joinpath("mch_ch_r04b09_dsl")
r04b09_dsl_data_file = r04b09_dsl_grid_path.joinpath("mch_ch_r04b09_dsl_grids_v1.tar.gz").name
r02b04_global_grid_path = grids_path.joinpath("r02b04_global")
r02b04_global_data_file = r02b04_global_grid_path.joinpath("icon_grid_0013_R02B04_G.tar.gz").name


mch_ch_r04b09_dsl_grid_uri = "https://polybox.ethz.ch/index.php/s/hD232znfEPBh4Oh/download"
r02b04_global_grid_uri = "https://polybox.ethz.ch/index.php/s/0EM8O8U53GKGsst/download"


@pytest.fixture()
def r04b09_dsl_gridfile(get_grid_files):
return r04b09_dsl_grid_path.joinpath("grid.nc")


@pytest.fixture(scope="session")
def get_grid_files(pytestconfig):
"""
Get the grid files used for testing.

Session scoped fixture which is a prerequisite of all the other fixtures in this file.
"""
if not pytestconfig.getoption("datatest"):
pytest.skip("not running datatest marked tests")
download_and_extract(mch_ch_r04b09_dsl_grid_uri, r04b09_dsl_grid_path, r04b09_dsl_data_file)
download_and_extract(r02b04_global_grid_uri, r02b04_global_grid_path, r02b04_global_data_file)
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@
SingleNodeExchange,
create_exchange,
)
from icon4py.model.common.test_utils.datatest_helpers import ( # noqa: F401 # import fixtures form test_utils
processor_props,
)


def test_create_single_node_runtime_without_mpi(processor_props):
def test_create_single_node_runtime_without_mpi(processor_props): # noqa: F811 # fixture
decomposition_info = DecompositionInfo(klevels=10)
exchange = create_exchange(processor_props, decomposition_info)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@
)
from icon4py.model.common.decomposition.mpi_decomposition import GHexMultiNodeExchange
from icon4py.model.common.dimension import CellDim, EdgeDim, VertexDim
from icon4py.model.common.test_utils.datatest_helpers import ( # noqa: F401 # import fixtures from test_utils
data_provider,
datapath,
decomposition_info,
download_ser_data,
grid_savepoint,
icon_grid,
ranked_data_path,
)
from icon4py.model.common.test_utils.parallel_helpers import ( # noqa: F401 # import fixtures from test_utils package
check_comm_size,
processor_props,
Expand Down Expand Up @@ -66,9 +75,9 @@ def test_decomposition_info_masked(
owned,
total,
caplog,
download_ser_data,
decomposition_info,
processor_props, # noqa: F811 # fixture
download_ser_data, # noqa: F811 # fixture
decomposition_info, # noqa: F811 # fixture
processor_props, # noqa: F811 # fixture
):
check_comm_size(processor_props, sizes=[2])
my_rank = processor_props.rank
Expand All @@ -85,7 +94,6 @@ def test_decomposition_info_masked(
_assert_index_partitioning(all_indices, halo_indices, owned_indices)


# @pytest.mark.skipif(props.comm_size != 2, reason="runs on 2 nodes only")
def _assert_index_partitioning(all_indices, halo_indices, owned_indices):
owned_list = owned_indices.tolist()
halos_list = halo_indices.tolist()
Expand All @@ -112,8 +120,9 @@ def test_decomposition_info_local_index(
owned,
total,
caplog,
decomposition_info,
processor_props, # noqa: F811 # fixture
download_ser_data, # noqa: F811 #fixture
decomposition_info, # noqa: F811 #fixture
processor_props, # noqa: F811 #fixture
):
check_comm_size(processor_props, sizes=[2])
my_rank = processor_props.rank
Expand Down Expand Up @@ -162,10 +171,10 @@ def test_domain_descriptor_id_are_globally_unique(num, processor_props): # noqa
@pytest.mark.datatest
def test_decomposition_info_matches_gridsize(
caplog,
download_ser_data,
decomposition_info,
icon_grid,
processor_props, # noqa: F811 # fixture
download_ser_data, # noqa: F811 #fixture
decomposition_info, # noqa: F811 #fixture
icon_grid, # noqa: F811 #fixture
processor_props, # noqa: F811 #fixture
):
check_comm_size(processor_props)
assert (
Expand Down Expand Up @@ -195,3 +204,13 @@ def test_create_multi_node_runtime_with_mpi(
assert isinstance(exchange, GHexMultiNodeExchange)
else:
assert isinstance(exchange, SingleNodeExchange)


@pytest.mark.parametrize("processor_props", [False], indirect=True)
def test_create_single_node_runtime_without_mpi(
processor_props, decomposition_info # noqa: F811 # fixture
):
props = processor_props
exchange = create_exchange(props, decomposition_info)

assert isinstance(exchange, SingleNodeExchange)
57 changes: 57 additions & 0 deletions model/common/tests/grid_tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# ICON4Py - ICON inspired code in Python and GT4Py
#
# Copyright (c) 2022, ETH Zurich and MeteoSwiss
# All rights reserved.
#
# This file is free software: you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the
# Free Software Foundation, either version 3 of the License, or any later
# version. See the LICENSE.txt file at the top-level directory of this
# distribution for a copy of the license or check <https://www.gnu.org/licenses/>.
#
# SPDX-License-Identifier: GPL-3.0-or-later
import pytest

from icon4py.model.common.test_utils.data_handling import download_and_extract
from icon4py.model.common.test_utils.datatest_helpers import ( # noqa: F401
base_path,
damping_height,
data_provider,
datapath,
decomposition_info,
download_ser_data,
grid_savepoint,
icon_grid,
interpolation_savepoint,
processor_props,
ranked_data_path,
)


grids_path = base_path.joinpath("grids")
r04b09_dsl_grid_path = grids_path.joinpath("mch_ch_r04b09_dsl")
r04b09_dsl_data_file = r04b09_dsl_grid_path.joinpath("mch_ch_r04b09_dsl_grids_v1.tar.gz").name
r02b04_global_grid_path = grids_path.joinpath("r02b04_global")
r02b04_global_data_file = r02b04_global_grid_path.joinpath("icon_grid_0013_R02B04_G.tar.gz").name


mch_ch_r04b09_dsl_grid_uri = "https://polybox.ethz.ch/index.php/s/hD232znfEPBh4Oh/download"
r02b04_global_grid_uri = "https://polybox.ethz.ch/index.php/s/0EM8O8U53GKGsst/download"


@pytest.fixture()
def r04b09_dsl_gridfile(get_grid_files):
return r04b09_dsl_grid_path.joinpath("grid.nc")


@pytest.fixture(scope="session")
def get_grid_files(pytestconfig):
"""
Get the grid files used for testing.

Session scoped fixture which is a prerequisite of all the other fixtures in this file.
"""
if not pytestconfig.getoption("datatest"):
pytest.skip("not running datatest marked tests")
download_and_extract(mch_ch_r04b09_dsl_grid_uri, r04b09_dsl_grid_path, r04b09_dsl_data_file)
download_and_extract(r02b04_global_grid_uri, r02b04_global_grid_path, r02b04_global_data_file)
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,22 @@
from icon4py.model.common.dimension import EdgeDim
from icon4py.model.common.grid.horizontal import HorizontalMarkerIndex
from icon4py.model.common.interpolation.interpolation_fields import compute_c_lin_e
from icon4py.model.common.test_utils.datatest_helpers import ( # noqa: F401 # import fixtures from test_utils package
data_provider,
datapath,
download_ser_data,
grid_savepoint,
icon_grid,
interpolation_savepoint,
processor_props,
ranked_data_path,
)


@pytest.mark.datatest
def test_compute_c_lin_e(grid_savepoint, interpolation_savepoint, icon_grid):
def test_compute_c_lin_e(
grid_savepoint, interpolation_savepoint, icon_grid # noqa: F811 # fixture
):
inv_dual_edge_length = grid_savepoint.inv_dual_edge_length()
edge_cell_length = grid_savepoint.edge_cell_length()
owner_mask = grid_savepoint.e_owner_mask()
Expand Down
Loading