-
Notifications
You must be signed in to change notification settings - Fork 16
[Fix]: Removing race condition within DiagManagerMonitor testing
#459
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
Changes from 48 commits
2be42de
544fc4a
0551484
319320b
9e05a01
c67041a
7a15106
0521b8a
fc4b13d
c410f22
6cd2d28
0131b97
7715c0c
98c4804
4238aae
c2a34c9
2b83d84
531828c
26eeaad
31adac8
5186f80
0e2e124
b6933b0
6681da9
b403498
f546b28
ea986fc
bd5a5b9
c3a1baa
0cf5946
d6cf6c0
ab22f58
528f21f
877fd63
e6c365f
af1d2a5
225ccbc
d18e647
424760d
62b21c0
ac125d1
9d85b34
cb49a53
dae4094
ae26ded
08c5573
8c5107b
8a77760
098c3c6
b6631f8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -19,7 +19,18 @@ jobs: | |||||||||
| strategy: | ||||||||||
| matrix: | ||||||||||
| python-version: ['3.11', '3.12', '3.13'] | ||||||||||
| name: Python ${{ matrix.python-version }} | ||||||||||
| extra: ['test,zarr'] | ||||||||||
| marker-serial: ['not parallel and not gpu and not pyfms'] | ||||||||||
| marker-parallel: ['parallel and not gpu and not pyfms'] | ||||||||||
| include: | ||||||||||
| # add pyfms tests for 3.12 | ||||||||||
| - extra: 'test,pyfms' | ||||||||||
| marker-serial: 'pyfms and not parallel' | ||||||||||
| marker-parallel: 'pyfms and parallel' | ||||||||||
| python-version: '3.12' | ||||||||||
| # don't cancel other jobs if one fails | ||||||||||
| fail-fast: false | ||||||||||
| name: Python ${{ matrix.python-version }}${{ contains(matrix.extra, 'pyfms') && ' (pyFMS)' || '' }} | ||||||||||
| steps: | ||||||||||
| - name: Checkout repository | ||||||||||
| uses: actions/checkout@v6 | ||||||||||
|
|
@@ -31,17 +42,26 @@ jobs: | |||||||||
| with: | ||||||||||
| python-version: ${{ matrix.python-version }} | ||||||||||
|
|
||||||||||
| - name: Install mpi (MPICH flavor) | ||||||||||
| run: pip3 install mpich | ||||||||||
| - name: Install MPI | ||||||||||
| if: ${{!contains(matrix.extra, 'pyfms')}} | ||||||||||
| run: pip3 install openmpi | ||||||||||
|
|
||||||||||
| - name: Install pyFMS dependencies (includes system MPI) | ||||||||||
| if: contains(matrix.extra, 'pyfms') | ||||||||||
| run: | | ||||||||||
| sudo apt-get update | ||||||||||
| sudo apt-get install libopenmpi-dev netcdf-bin libnetcdf-dev libnetcdff-dev nco libyaml-dev diffutils | ||||||||||
|
|
||||||||||
| - name: Install Python packages | ||||||||||
| run: pip3 install .[test,zarr] | ||||||||||
| run: | | ||||||||||
| pip3 install .[${{matrix.extra}}] | ||||||||||
| pip3 list | ||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please remove debug
Suggested change
|
||||||||||
|
|
||||||||||
| - name: Run serial cpu tests | ||||||||||
| run: coverage run --rcfile=pyproject.toml -m pytest -m "not parallel and not gpu" tests | ||||||||||
| run: coverage run --rcfile=pyproject.toml -m pytest -m "${{matrix.marker-serial}}" tests | ||||||||||
|
|
||||||||||
| - name: Run parallel cpu tests | ||||||||||
| run: mpiexec -np 6 coverage run --rcfile=pyproject.toml -m mpi4py -m pytest -m "parallel and not gpu" tests | ||||||||||
| run: mpiexec -np 6 --oversubscribe coverage run --rcfile=pyproject.toml -m mpi4py -m pytest -m "${{matrix.marker-parallel}}" tests | ||||||||||
|
|
||||||||||
| - name: Output code coverage | ||||||||||
| run: | | ||||||||||
|
|
||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| # diag_manager_monitor | ||
|
|
||
| ::: monitor.diag_manager_monitor |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,8 +9,8 @@ | |
| import cftime | ||
| import numpy as np | ||
| import pytest | ||
| import xarray as xr | ||
| import yaml | ||
| from netCDF4 import Dataset, num2date | ||
|
|
||
| from ndsl import ( | ||
| DiagManagerMonitor, | ||
|
|
@@ -22,12 +22,10 @@ | |
| ) | ||
| from ndsl.config import Backend | ||
| from ndsl.initialization import SubtileGridSizer | ||
| from ndsl.optional_imports import pyfms | ||
|
|
||
|
|
||
| pyfms = pytest.importorskip("pyfms") | ||
|
|
||
|
|
||
| def _create_input(reduction: str = "none"): | ||
| def _create_input() -> None: | ||
| diag_config = { | ||
| "title": "ndsl_diag_manager_test", | ||
| "base_date": "2 1 1 1 1 1", | ||
|
|
@@ -63,10 +61,10 @@ def _create_input(reduction: str = "none"): | |
| f.write(text_content) | ||
|
|
||
|
|
||
| def test_dm_monitor_single_tile(): | ||
| @pytest.mark.pyfms | ||
| def test_dm_monitor_single_tile() -> None: | ||
| # mpi info | ||
| npes = MPIComm()._comm.Get_size() | ||
| pe = MPIComm()._comm.Get_rank() | ||
| # tile parameters for quantities/domains | ||
| nx = 8 | ||
| ny = 8 | ||
|
|
@@ -220,30 +218,30 @@ def test_dm_monitor_single_tile(): | |
|
|
||
| # check output! | ||
| assert Path("diag_manager_single_tile.nc").exists() | ||
| ds = xr.open_mfdataset("diag_manager_single_tile.nc", decode_times=True) | ||
| assert "var_2d" in ds | ||
| np.testing.assert_array_equal(ds["var_2d"].shape, (ntimesteps, nx, ny)) | ||
| assert ds["var_2d"].dims == ("time", "y", "x") | ||
| assert ds["var_2d"].attrs["units"] == "muntin" | ||
| assert ds["var_3d"].dims == ("time", "z", "y", "x") | ||
| assert ds["var_3d"].attrs["units"] == "muntin" | ||
| assert ds["time"].shape == (ntimesteps,) | ||
| assert ds["time"].dims == ("time",) | ||
| assert ds["time"].values[0] == cftime.DatetimeNoLeap(2, 1, 1, 2, 1, 1) | ||
| assert ds["time"].values[1] == cftime.DatetimeNoLeap(2, 1, 1, 3, 1, 1) | ||
| assert ds["time"].values[2] == cftime.DatetimeNoLeap(2, 1, 1, 4, 1, 1) | ||
| np.testing.assert_array_equal(ds["var_2d"].values[0, :, :], var2_global.transpose()) | ||
| np.testing.assert_array_equal(ds["var_2d"].values[1, :, :], var2_global.transpose()) | ||
| np.testing.assert_array_equal(ds["var_2d"].values[2, :, :], var2_global.transpose()) | ||
| ds = Dataset("diag_manager_single_tile.nc") | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just out of curiosity: did you figure out what the issue with
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It invoked some multi-threading methods that were creating some race conditions. I didn't dig into what was specifically happening within the call, and instead looked into other ways to access the data in the files and came across using the netcdf package directly, which seemingly does not use threading. |
||
| assert "var_2d" in ds.variables | ||
| assert "time" in ds.variables | ||
| assert "var_3d" in ds.variables | ||
| var2_ds = ds.variables["var_2d"] | ||
| time_var = ds.variables["time"] | ||
| var3_ds = ds.variables["var_3d"] | ||
| np.testing.assert_array_equal(var2_ds.shape, (ntimesteps, nx, ny)) | ||
| assert var2_ds.dimensions == ("time", "y", "x") | ||
| assert var2_ds.units == "muntin" | ||
| assert var3_ds.dimensions == ("time", "z", "y", "x") | ||
| assert var3_ds.units == "muntin" | ||
| assert time_var.shape == (ntimesteps,) | ||
| assert time_var.dimensions == ("time",) | ||
| dates = num2date(time_var[:], units=time_var.units, calendar=time_var.calendar) | ||
| assert dates[0] == cftime.DatetimeNoLeap(2, 1, 1, 2, 1, 1) | ||
| assert dates[1] == cftime.DatetimeNoLeap(2, 1, 1, 3, 1, 1) | ||
| assert dates[2] == cftime.DatetimeNoLeap(2, 1, 1, 4, 1, 1) | ||
| np.testing.assert_array_equal(var2_ds[0, :, :], var2_global.transpose()) | ||
| np.testing.assert_array_equal(var2_ds[1, :, :], var2_global.transpose()) | ||
| np.testing.assert_array_equal(var2_ds[2, :, :], var2_global.transpose()) | ||
| # data is transposed when passed into fortran | ||
| np.testing.assert_array_equal( | ||
| ds["var_3d"].values[0, :, :, :], var3_global.transpose() | ||
| ) | ||
| np.testing.assert_array_equal( | ||
| ds["var_3d"].values[1, :, :, :], var3_global.transpose() | ||
| ) | ||
| np.testing.assert_array_equal( | ||
| ds["var_3d"].values[2, :, :, :], var3_global.transpose() | ||
| ) | ||
| np.testing.assert_array_equal(var3_ds[0, :, :, :], var3_global.transpose()) | ||
| np.testing.assert_array_equal(var3_ds[1, :, :, :], var3_global.transpose()) | ||
| np.testing.assert_array_equal(var3_ds[2, :, :, :], var3_global.transpose()) | ||
|
|
||
| pyfms.fms.end() | ||
Uh oh!
There was an error while loading. Please reload this page.