Skip to content

Commit

Permalink
updating json namelists and starting refactor of conftest
Browse files Browse the repository at this point in the history
  • Loading branch information
jmills-ncar committed Jul 23, 2018
1 parent ce39843 commit a674c96
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 190 deletions.
168 changes: 63 additions & 105 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import json
import pathlib
import pytest
import sys
import warnings
from wrfhydropy import *


Expand Down Expand Up @@ -53,145 +49,107 @@ def pytest_addoption(parser):
default='gfort',
required=False,
action='store',
help='compiler key from config'
help='compiler, options are intel or gfort'
)

parser.addoption(
'--job_default',
default=None,
'--ncores',
default='2',
required=False,
action='store',
help='candidate job'
help='Number of cores to use for testing'
)

parser.addoption(
'--job_ncores',
'--scheduler',
default=None,
required=False,
action='store',
help='ncores job'
)
help='Scheduler to use for testing, options are PBSCheyenne or do not specify for no '
'scheduler')

parser.addoption(
'--scheduler',
default=None,
'--account',
default='NRAL0017',
required=False,
action='store',
help='scheduler for all jobs')


def pytest_generate_tests(metafunc):
if 'configuration' in metafunc.fixturenames:
metafunc.parametrize(
"configuration",
metafunc.config.option.config,
scope="session"
)


@pytest.fixture(scope="session")
def candidate_setup(request, configuration):

domain_dir = request.config.getoption("--domain_dir")
candidate_dir = request.config.getoption("--candidate_dir")

help='Account number to use if using a scheduler.')

def _make_sim(domain_dir,
source_dir,
configuration,
ncores,
scheduler,
account):
# Candidate model
candidate_model = WrfHydroModel(
source_dir=candidate_dir,
model = Model(
source_dir=source_dir,
model_config=configuration
)

# Candidate domain
domain = WrfHydroDomain(
domain = Domain(
domain_top_dir=domain_dir,
domain_config=configuration,
model_version=candidate_model.version
)

# Candidate setup
candidate_setup = WrfHydroSetup(candidate_model, domain)

return candidate_setup

domain_config=configuration)

@pytest.fixture(scope="session")
def reference_setup(request, configuration):

domain_dir = request.config.getoption("--domain_dir")
reference_dir = request.config.getoption("--reference_dir")

# Reference model
reference_model = WrfHydroModel(
source_dir=reference_dir,
model_config=configuration
)

# Reference domain
domain = WrfHydroDomain(
domain_top_dir=domain_dir,
domain_config=configuration,
model_version=reference_model.version
)
# Job
exe_command = ('mpirun -np {0} ./wrf_hydro.exe').format(str(ncores))
job = Job(job_id='test_job',exe_cmd=exe_command)

# Reference setup
reference_setup = WrfHydroSetup(reference_model, domain)
# Candidate simulation
sim = Simulation()
sim.add(model)
sim.add(domain)
sim.add(job)

return reference_setup
if scheduler is not None and scheduler == 'pbscheyenne':
sim.add(schedulers.PBSCheyenne(account=account,nproc=int(ncores)))

return sim

@pytest.fixture(scope="session")
def compiler(request):
return request.config.getoption("--compiler")
def candidate_setup(request):

domain_dir = request.config.getoption("--domain_dir")
candidate_dir = request.config.getoption("--candidate_dir")
configuration = request.config.getoption("--config")
ncores = request.config.getoption("--ncores")
scheduler = str(request.config.getoption("--scheduler")).lower()
account = request.config.getoption("--account")

@pytest.fixture(scope="session")
def job_default(request, configuration):
job_in = request.config.getoption("--job_default")
with warnings.catch_warnings():
warnings.simplefilter("ignore")
job_dum = Job(nproc=-1)
if job_in is not None:
job_in = json.loads(job_in)
job_dum.__dict__.update(job_in)
return job_dum
candidate_sim = _make_sim(domain_dir = domain_dir,
source_dir= candidate_dir,
configuration=configuration,
ncores = ncores,
scheduler = scheduler,
account = account)

return candidate_sim

@pytest.fixture(scope="session")
def job_ncores(request, configuration):
job_in = request.config.getoption("--job_ncores")
print("job_in: ", job_in)

with warnings.catch_warnings():
warnings.simplefilter("ignore")
job_dum = Job(nproc=-1)
if job_in is not None:
job_in = json.loads(job_in)
job_dum.__dict__.update(job_in)
return job_dum
def reference_setup(request):

domain_dir = request.config.getoption("--domain_dir")
reference_dir = request.config.getoption("--reference_dir")
configuration = request.config.getoption("--config")
ncores = request.config.getoption("--ncores")
scheduler = str(request.config.getoption("--scheduler")).lower()
account = request.config.getoption("--account")

@pytest.fixture(scope="session")
def scheduler(request, configuration):
sched_in = request.config.getoption("--scheduler")
if sched_in is None or sched_in == 'null':
return None
else:
sched = json.loads(sched_in)
sched_dum = Scheduler(
job_name='default',
account='DUMDUM',
walltime='00:01:00',
queue='none',
nproc=1,
ppn=1
)
sched_dum.__dict__.update(sched)
return sched_dum
reference_sim = _make_sim(domain_dir = domain_dir,
source_dir= reference_dir,
configuration=configuration,
ncores = ncores,
scheduler = scheduler,
account = account)

return reference_sim

@pytest.fixture(scope="session")
def output_dir(request,configuration):
def output_dir(request):
configuration = request.config.getoption("--config")
output_dir = request.config.getoption("--output_dir")

output_dir = pathlib.Path(output_dir)
output_dir = output_dir / configuration
if output_dir.is_dir() is False:
Expand Down
15 changes: 6 additions & 9 deletions tests/test_1_fundamental.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import copy
import datetime as dt
import json
import pickle
import pytest
import shutil
import time
import warnings
import wrfhydropy

Expand All @@ -20,7 +17,7 @@

###Compile questions compiler,
def test_compile_candidate(
candidate_setup,
candidate_sim,
output_dir,
compiler,
capsys
Expand All @@ -31,19 +28,19 @@ def test_compile_candidate(
compile_dir = output_dir / 'compile_candidate'

# Compile the model
candidate_setup.model.compile(
candidate_sim.model.compile(
compiler=compiler,
compile_dir=compile_dir,
overwrite=True
)

# Check compilation status
assert candidate_setup.model.compile_log.returncode == 0, \
assert candidate_sim.model.compile_log.returncode == 0, \
"Candidate code did not compile correctly."


def test_compile_reference(
reference_setup,
reference_sim,
output_dir,
compiler,
capsys
Expand All @@ -54,14 +51,14 @@ def test_compile_reference(
compile_dir = output_dir / 'compile_reference'

# Compile the model
reference_setup.model.compile(
reference_sim.model.compile(
compiler=compiler,
compile_dir=compile_dir,
overwrite=True
)

# Check compilation status
assert reference_setup.model.compile_log.returncode == 0, \
assert reference_sim.model.compile_log.returncode == 0, \
"Reference code did not compile correctly"


Expand Down
8 changes: 4 additions & 4 deletions trunk/NDHMS/compile_options.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"NWM": {
"nwm": {
"WRF_HYDRO": 1,
"HYDRO_D": 0,
"SPATIAL_SOIL": 1,
Expand All @@ -8,7 +8,7 @@
"NCEP_WCOSS": 0,
"WRF_HYDRO_NUDGING": 1
},
"Gridded": {
"gridded": {
"WRF_HYDRO": 1,
"HYDRO_D": 0,
"SPATIAL_SOIL": 1,
Expand All @@ -17,7 +17,7 @@
"NCEP_WCOSS": 0,
"WRF_HYDRO_NUDGING": 0
},
"Gridded_NO_LAKES": {
"gridded_no_lakes": {
"WRF_HYDRO": 1,
"HYDRO_D": 0,
"SPATIAL_SOIL": 1,
Expand All @@ -26,7 +26,7 @@
"NCEP_WCOSS": 0,
"WRF_HYDRO_NUDGING": 0
},
"Reach": {
"reach": {
"WRF_HYDRO": 1,
"HYDRO_D": 0,
"SPATIAL_SOIL": 1,
Expand Down
34 changes: 11 additions & 23 deletions trunk/NDHMS/hrldas_namelists.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"rst_bi_in": 0,
"rst_bi_out": 0,
"runoff_option": 3,
"snow_albedo_option": 2,
"snow_albedo_option": 1,
"soil_thick_input": [0.1, 0.3, 0.6, 1.0],
"spatial_filename": "NULL_specified_in_domain.json",
"split_output_count": 1,
Expand All @@ -41,48 +41,36 @@
"forc_typ": "NULL_specified_in_domain.json"
}
},
"NWM_ana": {
"nwm_ana": {
"noahlsm_offline": {},
"wrf_hydro_offline": {}
},

"NWM_short_range" : {
"noahlsm_offline": {
"khour": 18,
"restart_frequency_hours": 600
},
"nwm_short_range" : {
"noahlsm_offline": {},
"wrf_hydro_offline": {}
},

"NWM_medium_range" : {
"noahlsm_offline": {
"khour": 240,
"output_timestep": 10800,
"restart_frequency_hours": 6000
},
"nwm_medium_range" : {
"noahlsm_offline": {},
"wrf_hydro_offline": {}
},

"NWM_long_range" : {
"noahlsm_offline": {
"forcing_timestep": 10800,
"khour": 720,
"output_timestep": 86400,
"restart_frequency_hours": 6000
},
"nwm_long_range" : {
"noahlsm_offline": {},
"wrf_hydro_offline": {}
},

"NWM_channel_only" : {
"nwm_channel_only" : {
"noahlsm_offline": {},
"wrf_hydro_offline": {}
},

"Gridded": {
"gridded": {
"noahlsm_offline": {},
"wrf_hydro_offline": {}
},
"Reach": {
"reach": {
"noahlsm_offline": {},
"wrf_hydro_offline": {}
}
Expand Down
Loading

0 comments on commit a674c96

Please sign in to comment.