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

Add new cable 3 namelists to ESM1.6 driver #570

Merged
merged 3 commits into from
Feb 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 9 additions & 0 deletions payu/models/access_esm1p6.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,15 @@ def __init__(self, expt, name, config):
# Simulation length in seconds for new run
model.runtime_key = "runtime"

if model.model_type == 'um':
# Additional Cable 3 namelists

# Using set as this initialised twice and would otherwise
# contain duplicates
model.optional_config_files = list(
set(['pft_params.nml', 'soil.nml']) |
set(model.optional_config_files)
)

def setup(self):
if not self.top_level_model:
Expand Down
2 changes: 1 addition & 1 deletion payu/models/um.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def __init__(self, expt, name, config):
'STASHC', 'UAFILES_A', 'UAFLDS_A',
'cable.nml', 'um_env.yaml'
]
self.optional_config_files = ['input_atm.nml', 'parexe']
self.optional_config_files.extend(['input_atm.nml', 'parexe'])

self.restart = 'restart_dump.astart'

Expand Down
152 changes: 152 additions & 0 deletions test/models/test_access_esm1p6.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
import copy
import os
import shutil

import pytest

import payu

from test.common import cd, expt_workdir
from test.common import tmpdir, ctrldir, labdir, workdir, archive_dir
from test.common import config as config_orig
from test.common import write_config
from test.common import make_all_files
from test.common import config_path

verbose = True


def setup_module(module):
"""
Put any test-wide setup code in here, e.g. creating test files
"""
if verbose:
print("setup_module module:%s" % module.__name__)

# Should be taken care of by teardown, in case remnants lying around
try:
shutil.rmtree(tmpdir)
except FileNotFoundError:
pass

try:
tmpdir.mkdir()
labdir.mkdir()
ctrldir.mkdir()
archive_dir.mkdir()
make_all_files()
except Exception as e:
print(e)


def teardown_module(module):
"""
Put any test-wide teardown code in here, e.g. removing test outputs
"""
if verbose:
print("teardown_module module:%s" % module.__name__)

try:
shutil.rmtree(tmpdir)
print('removing tmp')
except Exception as e:
print(e)


@pytest.fixture(autouse=True)
def empty_workdir():
"""
Model setup tests require a clean work directory and symlink from
the control directory.
"""
expt_workdir.mkdir(parents=True)
# Symlink must exist for setup to use correct locations
workdir.symlink_to(expt_workdir)

yield expt_workdir
try:
shutil.rmtree(expt_workdir)
except FileNotFoundError:
pass
workdir.unlink()


@pytest.fixture
def esm1p6_um_only_config():
"""
Configuration for experiment with UM as a submodel
of ESM1.6
"""
config = copy.deepcopy(config_orig)
config["model"] = "access-esm1.6"
config["submodels"] = [{"name": "atmosphere",
"model": "um"}]
write_config(config)

# Run test
yield

# Teardown
os.remove(config_path)


@pytest.fixture
def um_only_ctrl_dir():
"""
Configuration for experiment with UM as standalone
model
"""
# First make a separate control directory for standalone UM experiment
um_ctrl_dir = tmpdir/"um_only_ctrl"
um_ctrl_dir.mkdir()

config = copy.deepcopy(config_orig)
config["model"] = "um"

write_config(config, path=um_ctrl_dir/"config.yaml")

# Run test
yield um_ctrl_dir

# Teardown
shutil.rmtree(um_ctrl_dir)


def test_esm1p6_patch_optional_config_files(um_only_ctrl_dir,
esm1p6_um_only_config):
"""
Test that the access-esm1.6 driver correctly updates the UM
configuration files.
"""
# Initialise standalone UM model
with cd(um_only_ctrl_dir):
um_config_path = um_only_ctrl_dir / "config.yaml"
um_lab = payu.laboratory.Laboratory(lab_path=str(labdir),
config_path=um_config_path)
um_expt = payu.experiment.Experiment(um_lab, reproduce=False)

um_standalone_model = um_expt.models[0]

# Initialise ESM1.6 with UM submodel
with cd(ctrldir):
esm1p6_lab = payu.laboratory.Laboratory(lab_path=str(labdir))
esm1p6_expt = payu.experiment.Experiment(esm1p6_lab, reproduce=False)

for model in esm1p6_expt.models:
if model.model_type == "um":
esm1p6_um_model = model

# Check there are no duplicate files from double initialisation
assert (
len(esm1p6_um_model.optional_config_files) ==
len(set(esm1p6_um_model.optional_config_files))
)

# Check that esm1p6 driver added new config files compared
# to the standalone UM.

expected_files = ["soil.nml", "pft_params.nml"]
assert (
set(esm1p6_um_model.optional_config_files) ==
set(um_standalone_model.optional_config_files).union(expected_files)
)
Loading