From 2359448bd3cab9c777e1a8ef6d1a16036da823a1 Mon Sep 17 00:00:00 2001 From: Nicholas Hannah Date: Wed, 14 Jun 2017 14:52:23 +1000 Subject: [PATCH 1/7] Add test for domain transformation. See https://github.com/NOAA-GFDL/MOM6/issues/391 --- tools/tests/experiment.py | 35 ++++++++++ tools/tests/test_domain_transform.py | 95 ++++++++++++++++++++++++++++ 2 files changed, 130 insertions(+) create mode 100644 tools/tests/test_domain_transform.py diff --git a/tools/tests/experiment.py b/tools/tests/experiment.py index 5cb5c21794..fc1d995ad8 100644 --- a/tools/tests/experiment.py +++ b/tools/tests/experiment.py @@ -8,6 +8,7 @@ import random import subprocess as sp import run_config as rc +import fileinput from model import Model # Only support Python version >= 2.7 @@ -237,6 +238,40 @@ def get_unfinished_diags(self): """ return self.unfinished_diags + def set_mom_input_option(self, option, value): + """ + Set an option in the MOM_input file. + """ + + fname = os.path.join(self.path, 'MOM_input') + self.set_input_option(fname, option, value) + + def set_sis_input_option(self, option, value): + """ + Set an option in the SIS_input file. + """ + + fname = os.path.join(self.path, 'SIS_input') + self.set_input_option(fname, option, value) + + def set_input_option(fname, option, value): + + found = False + optstr = option + ' = ' + value + '\n' + + fname = os.path.join(self.path, 'MOM_input') + with fileinput.FileInput(fname, inplace=True) as f: + for line in f: + if line.startswith(option): + print(optstr, end='') + found = True + else: + print(line, end='') + + if not found: + with open(fname, 'a') as f: + f.write(optstr) + def create_experiments(platform='raijin'): """ diff --git a/tools/tests/test_domain_transform.py b/tools/tests/test_domain_transform.py new file mode 100644 index 0000000000..5b28a29503 --- /dev/null +++ b/tools/tests/test_domain_transform.py @@ -0,0 +1,95 @@ + +from __future__ import print_function + +import pytest +import os +import f90nml +from experiment import Experiment + +def modify_input_nml(exp, set_ensemble_size=True, set_short_runtime=False): + + if set_ensemble_size or set_short_runtime: + nml = f90nml.read(os.path.join(exp.path, 'input.nml')) + if set_ensemble_size: + nml['ensemble_nml'] = f90nml.namelist.Namelist() + nml['ensemble_nml']['ensemble_size'] = 2 + if set_short_runtime: + nml['coupler_nml']['days'] = 1 + + f90nml.write(nml, os.path.join(exp.path, 'input.nml'), force=True) + + +class TestDomainTransform: + """ + This test runs two test MOM6/SIS2 cases side-by-side. These cases are the + same except that one of them has it's domain transformed. The + transformation can be either a transpose or a rotation. As they run the + side-by-side test cases compare key fields. If these fields differ in any + way then the test fails. + + The test catches a large class of indexing errors, as well any differences + in code between the i and j directions. + """ + + def test_baltic_transpose(self): + """ + Test that the Baltic tests case gives identical results with a + transposed domain. + """ + + exp = Experiment('ice_ocean_SIS2/Baltic') + + # Setup MOM_input for the test. + exp.set_mom_input_option('DEBUG', 'True') + exp.set_mom_input_option('TRANSFORM_TEST', 'True') + exp.set_mom_input_option('DIFFUSE_ML_TO_INTERIOR', 'False') + exp.set_mom_input_option('RESTORE_SALINITY', 'False') + exp.set_sis_input_option('TRANSFORM_TEST', 'True') + + modify_input_nml(exp, set_short_runtime=True) + + # FIXME: empty the diag_table. + + # Run test. + ret = exp.force_run() + assert ret == 0 + + + @pytest.mark.skip + def test_baltic_rotate90(self): + pass + + @pytest.mark.skip + def test_baltic_rotate180(self): + pass + + @pytest.mark.skip + def test_double_gyre_transpose(self): + """ + Test that the double gyre case gives identical results with a + transposed domain. + """ + + exp = Experiment('ocean_only/double_gyre') + + # Setup MOM_input for the test. + exp.set_mom_input_option('DEBUG', 'True') + exp.set_mom_input_option('TRANSFORM_TEST', 'True') + exp.set_mom_input_option('DAYMAX', '1.0') + exp.set_mom_input_option('NIGLOBAL', '40') + + modify_input_nml(exp) + + # Run test. + ret = exp.force_run() + assert ret == 0 + + + @pytest.mark.skip + def test_double_gyre_rotate90(self): + pass + + @pytest.mark.skip + def test_double_gyre_rotate180(self): + pass + From feb22d61787f40d4db8946b53297e612328f8de0 Mon Sep 17 00:00:00 2001 From: Nicholas Hannah Date: Wed, 14 Jun 2017 14:59:22 +1000 Subject: [PATCH 2/7] Update submodule for #391. --- .gitmodules | 4 ++-- src/FMS | 2 +- src/MOM6 | 2 +- src/SIS2 | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.gitmodules b/.gitmodules index f64487ad56..f16e8c325d 100644 --- a/.gitmodules +++ b/.gitmodules @@ -3,7 +3,7 @@ url = https://github.com/NOAA-GFDL/FMS.git [submodule "src/MOM6"] path = src/MOM6 - url = https://github.com/NOAA-GFDL/MOM6.git + url = git@github.com:nicjhan/MOM6.git [submodule "src/SIS2"] path = src/SIS2 url = https://github.com/NOAA-GFDL/SIS2.git @@ -27,7 +27,7 @@ url = https://github.com/NOAA-GFDL/land_null.git [submodule "src/mkmf"] path = src/mkmf - url = https://github.com/NOAA-GFDL/mkmf.git + url = https://github.com/NOAA-GFDL/mkmf.git [submodule "tools/analysis/mpl-cmocean"] path = tools/analysis/mpl-cmocean url = https://github.com/matplotlib/cmocean.git diff --git a/src/FMS b/src/FMS index 32a792370d..f97fba758f 160000 --- a/src/FMS +++ b/src/FMS @@ -1 +1 @@ -Subproject commit 32a792370d1ee4254b3cf6ab93c769076c5c447c +Subproject commit f97fba758f656871193e9ca33891f45c536a7e6c diff --git a/src/MOM6 b/src/MOM6 index 07a30e642d..e848ab7ca5 160000 --- a/src/MOM6 +++ b/src/MOM6 @@ -1 +1 @@ -Subproject commit 07a30e642d05b020cdad92c811a89edf13d5a9d6 +Subproject commit e848ab7ca5e668d04610f08a10bbdd02485af95d diff --git a/src/SIS2 b/src/SIS2 index 65b1d23f2f..5f2a55d268 160000 --- a/src/SIS2 +++ b/src/SIS2 @@ -1 +1 @@ -Subproject commit 65b1d23f2f3e3a25f1e8665a36b970ea84e726ea +Subproject commit 5f2a55d268a7aa1975d62ee68acf43dfc0f31ee0 From f64ad1b45ff89bd0a11ad9d3ae861f908927f631 Mon Sep 17 00:00:00 2001 From: Nicholas Hannah Date: Sat, 17 Jun 2017 13:30:03 +1000 Subject: [PATCH 3/7] Use nicjhan submodules for now. #391. --- .gitmodules | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitmodules b/.gitmodules index f16e8c325d..6ad405b403 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,12 +1,12 @@ [submodule "src/FMS"] path = src/FMS - url = https://github.com/NOAA-GFDL/FMS.git + url = https://github.com/nicjhan/FMS.git [submodule "src/MOM6"] path = src/MOM6 url = git@github.com:nicjhan/MOM6.git [submodule "src/SIS2"] path = src/SIS2 - url = https://github.com/NOAA-GFDL/SIS2.git + url = https://github.com/nicjhan/SIS2.git [submodule "tools/matlab/gtools"] path = tools/matlab/gtools url = https://github.com/Adcroft/gtools.git From 00398787b039097246757b83a3af068430b82065 Mon Sep 17 00:00:00 2001 From: Nicholas Hannah Date: Sat, 17 Jun 2017 21:46:19 +1000 Subject: [PATCH 4/7] Enable double_gyre transform tests. #391 --- tools/tests/experiment.py | 3 +-- tools/tests/test_domain_transform.py | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/tools/tests/experiment.py b/tools/tests/experiment.py index fc1d995ad8..456742027e 100644 --- a/tools/tests/experiment.py +++ b/tools/tests/experiment.py @@ -254,12 +254,11 @@ def set_sis_input_option(self, option, value): fname = os.path.join(self.path, 'SIS_input') self.set_input_option(fname, option, value) - def set_input_option(fname, option, value): + def set_input_option(self, fname, option, value): found = False optstr = option + ' = ' + value + '\n' - fname = os.path.join(self.path, 'MOM_input') with fileinput.FileInput(fname, inplace=True) as f: for line in f: if line.startswith(option): diff --git a/tools/tests/test_domain_transform.py b/tools/tests/test_domain_transform.py index 5b28a29503..05fc2633cd 100644 --- a/tools/tests/test_domain_transform.py +++ b/tools/tests/test_domain_transform.py @@ -44,6 +44,8 @@ def test_baltic_transpose(self): exp.set_mom_input_option('TRANSFORM_TEST', 'True') exp.set_mom_input_option('DIFFUSE_ML_TO_INTERIOR', 'False') exp.set_mom_input_option('RESTORE_SALINITY', 'False') + + exp.set_sis_input_option('DEBUG', 'True') exp.set_sis_input_option('TRANSFORM_TEST', 'True') modify_input_nml(exp, set_short_runtime=True) @@ -63,7 +65,6 @@ def test_baltic_rotate90(self): def test_baltic_rotate180(self): pass - @pytest.mark.skip def test_double_gyre_transpose(self): """ Test that the double gyre case gives identical results with a @@ -76,7 +77,6 @@ def test_double_gyre_transpose(self): exp.set_mom_input_option('DEBUG', 'True') exp.set_mom_input_option('TRANSFORM_TEST', 'True') exp.set_mom_input_option('DAYMAX', '1.0') - exp.set_mom_input_option('NIGLOBAL', '40') modify_input_nml(exp) From 23af932df1fbbc506680bc79cef59598359596f9 Mon Sep 17 00:00:00 2001 From: Nicholas Hannah Date: Sat, 5 Aug 2017 15:39:53 +1000 Subject: [PATCH 5/7] Update transform tests. Fix memory type in SIS2 build by tests. #391 --- tools/tests/model.py | 2 +- tools/tests/test_domain_transform.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tools/tests/model.py b/tools/tests/model.py index caaa28f105..4fc4430b7d 100644 --- a/tools/tests/model.py +++ b/tools/tests/model.py @@ -21,7 +21,7 @@ _build_ocean_ice_script = """ pwd && -../../../../../mkmf/bin/list_paths ./ ../../../../../src/MOM6/config_src/{{{memory_type},coupled_driver}} ../../../../../src/MOM6/src/{{*,*/*}}/ ../../../../../src/{{atmos_null,coupler,land_null,SIS2,ice_ocean_extras,icebergs,FMS/coupler,FMS/include}} && +../../../../../mkmf/bin/list_paths ./ ../../../../../src/MOM6/config_src/{{{memory_type},coupled_driver}} ../../../../../src/MOM6/src/{{*,*/*}}/ ../../../../../src/SIS2/config_src/{memory_type} ../../../../../src/SIS2/src ../../../../../src/{{atmos_null,coupler,land_null,ice_ocean_extras,icebergs,FMS/coupler,FMS/include}} && ../../../../../mkmf/bin/mkmf -t ../../../../../mkmf/templates/{platform}-{compiler}.mk -o '-I../../../shared/{build}' -p 'MOM6 -L../../../shared/{build} -lfms' -c '-Duse_libMPI -Duse_netCDF -DSPMD -DUSE_LOG_DIAG_FIELD_INFO -Duse_AM3_physics -D_USE_LEGACY_LAND_' path_names && source ../../../../../mkmf/env/{platform}-{compiler}.env && make NETCDF=3 {build}=1 MOM6 -j """ diff --git a/tools/tests/test_domain_transform.py b/tools/tests/test_domain_transform.py index 05fc2633cd..0a4a12dcaa 100644 --- a/tools/tests/test_domain_transform.py +++ b/tools/tests/test_domain_transform.py @@ -41,12 +41,12 @@ def test_baltic_transpose(self): # Setup MOM_input for the test. exp.set_mom_input_option('DEBUG', 'True') - exp.set_mom_input_option('TRANSFORM_TEST', 'True') + exp.set_mom_input_option('TRANSFORM_TEST', 'TRANSPOSE') exp.set_mom_input_option('DIFFUSE_ML_TO_INTERIOR', 'False') exp.set_mom_input_option('RESTORE_SALINITY', 'False') exp.set_sis_input_option('DEBUG', 'True') - exp.set_sis_input_option('TRANSFORM_TEST', 'True') + exp.set_sis_input_option('TRANSFORM_TEST', 'TRANSPOSE') modify_input_nml(exp, set_short_runtime=True) @@ -75,7 +75,7 @@ def test_double_gyre_transpose(self): # Setup MOM_input for the test. exp.set_mom_input_option('DEBUG', 'True') - exp.set_mom_input_option('TRANSFORM_TEST', 'True') + exp.set_mom_input_option('TRANSFORM_TEST', 'TRANSPOSE') exp.set_mom_input_option('DAYMAX', '1.0') modify_input_nml(exp) From a16761f8570ab7f008d34e167fefe60ddaea99f7 Mon Sep 17 00:00:00 2001 From: Nicholas Hannah Date: Sat, 5 Aug 2017 15:49:54 +1000 Subject: [PATCH 6/7] Update SIS2 with merge for #391. --- src/SIS2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SIS2 b/src/SIS2 index 5f2a55d268..55aa961b7b 160000 --- a/src/SIS2 +++ b/src/SIS2 @@ -1 +1 @@ -Subproject commit 5f2a55d268a7aa1975d62ee68acf43dfc0f31ee0 +Subproject commit 55aa961b7b162573dc83968226ccb68a8c7c9bf5 From e52fd394e9853cef269d678b1aecab632c538159 Mon Sep 17 00:00:00 2001 From: Nicholas Hannah Date: Sun, 6 Aug 2017 00:11:55 +1000 Subject: [PATCH 7/7] Update SIS2 submodule. #391 --- src/SIS2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SIS2 b/src/SIS2 index 55aa961b7b..f4a50ec67e 160000 --- a/src/SIS2 +++ b/src/SIS2 @@ -1 +1 @@ -Subproject commit 55aa961b7b162573dc83968226ccb68a8c7c9bf5 +Subproject commit f4a50ec67e5f065e7ff488640b1bd3ab92cf98a6