Skip to content

Commit

Permalink
Merge 5e495c9 into b78d020
Browse files Browse the repository at this point in the history
  • Loading branch information
aidanheerdegen committed May 8, 2020
2 parents b78d020 + 5e495c9 commit 5dc2299
Show file tree
Hide file tree
Showing 9 changed files with 573 additions and 35 deletions.
23 changes: 15 additions & 8 deletions payu/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,20 @@
def parse():
"""Parse the command line inputs and execute the subcommand."""

parser = generate_parser()

# Display help if no arguments are provided
if len(sys.argv) == 1:
parser.print_help()
else:
args = vars(parser.parse_args())
run_cmd = args.pop('run_cmd')
run_cmd(**args)


def generate_parser():
"""Parse the command line inputs generate and return parser."""

# Build the list of subcommand modules
modnames = [mod for (_, mod, _)
in pkgutil.iter_modules(payu.subcommands.__path__,
Expand All @@ -52,14 +66,7 @@ def parse():
for arg in cmd.arguments:
cmd_parser.add_argument(*arg['flags'], **arg['parameters'])

# Display help if no arguments are provided
if len(sys.argv) == 1:
parser.print_help()
else:
args = vars(parser.parse_args())
run_cmd = args.pop('run_cmd')
run_cmd(**args)

return parser

def get_model_type(model_type, config):
"""Determine and validate the active model type."""
Expand Down
19 changes: 12 additions & 7 deletions payu/experiment.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"""payu.experiment
===============
"""payu.experiment ===============
Interface to an individual experiment managed by payu
Expand Down Expand Up @@ -45,8 +44,9 @@

class Experiment(object):

def __init__(self, lab, reproduce=None):
def __init__(self, lab, reproduce=False, force=False):
self.lab = lab
self.force = force

self.start_time = datetime.datetime.now()

Expand Down Expand Up @@ -87,7 +87,7 @@ def __init__(self, lab, reproduce=None):

self.set_output_paths()

if reproduce is None:
if not reproduce:
# check environment for reproduce flag under PBS
reproduce = os.environ.get('PAYU_REPRODUCE', False)

Expand Down Expand Up @@ -379,9 +379,14 @@ def setup(self, force_archive=False):

# Confirm that no work path already exists
if os.path.exists(self.work_path):
sys.exit('payu: error: work path already exists: {path}.\n'
' payu sweep and then payu run'
.format(path=self.work_path))
if self.force:
print('payu: work path already exists.\n'
' Sweeping as --force option is True.')
self.sweep()
else:
sys.exit('payu: error: work path already exists: {path}.\n'
' payu sweep and then payu run'
.format(path=self.work_path))

mkdir_p(self.work_path)

Expand Down
14 changes: 13 additions & 1 deletion payu/subcommands/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,19 @@
'parameters': {
'action': 'store_true',
'dest': 'reproduce',
'default': None,
'default': False,
'help': 'Only run if manifests are correct',
}
}


# Force run to proceed despite existing directories
force = {
'flags': ('--force', '-f'),
'parameters': {
'action': 'store_true',
'dest': 'force',
'default': False,
'help': 'Force run to proceed, overwriting existing directories',
}
}
16 changes: 9 additions & 7 deletions payu/subcommands/collate_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
title = 'collate'
parameters = {'description': 'Collate tiled output into single output files'}

arguments = [args.model, args.config, args.initial, args.nruns,
args.laboratory, args.dir_path]
arguments = [args.model, args.config, args.initial, args.laboratory,
args.dir_path]


def runcmd(model_type, config_path, init_run, n_runs, lab_path, dir_path):
def runcmd(model_type, config_path, init_run, lab_path, dir_path):

pbs_config = fsops.read_config(config_path)
pbs_vars = cli.set_env_vars(init_run, n_runs, lab_path, dir_path)
pbs_vars = cli.set_env_vars(init_run, lab_path, dir_path)

collate_config = pbs_config.get('collate', {})

Expand Down Expand Up @@ -95,13 +95,15 @@ def runscript():

run_args = parser.parse_args()

pbs_vars = cli.set_env_vars(run_args.init_run, run_args.n_runs,
run_args.lab_path, run_args.dir_path)
pbs_vars = cli.set_env_vars(run_args.init_run,
run_args.lab_path,
run_args.dir_path)

for var in pbs_vars:
os.environ[var] = str(pbs_vars[var])

lab = Laboratory(run_args.model_type, run_args.config_path,
lab = Laboratory(run_args.model_type,
run_args.config_path,
run_args.lab_path)
expt = Experiment(lab)
expt.collate()
Expand Down
7 changes: 4 additions & 3 deletions payu/subcommands/run_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@
parameters = {'description': 'Run the model experiment'}

arguments = [args.model, args.config, args.initial, args.nruns,
args.laboratory, args.reproduce]
args.laboratory, args.reproduce, args.force]


def runcmd(model_type, config_path, init_run, n_runs, lab_path, reproduce):
def runcmd(model_type, config_path, init_run, n_runs, lab_path,
reproduce=False, force=False):

# Get job submission configuration
pbs_config = fsops.read_config(config_path)
Expand Down Expand Up @@ -114,7 +115,7 @@ def runscript():

lab = Laboratory(run_args.model_type, run_args.config_path,
run_args.lab_path)
expt = Experiment(lab, reproduce=run_args.reproduce)
expt = Experiment(lab, reproduce=run_args.reproduce, force=run_args.force)

n_runs_per_submit = expt.config.get('runspersub', 1)
subrun = 1
Expand Down
8 changes: 5 additions & 3 deletions payu/subcommands/setup_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@
args.config,
args.laboratory,
args.force_archive,
args.reproduce
args.reproduce,
args.force
]


def runcmd(model_type, config_path, lab_path, force_archive, reproduce):
def runcmd(model_type, config_path, lab_path, force_archive,
reproduce=False, force=False):

lab = Laboratory(model_type, config_path, lab_path)
expt = Experiment(lab, reproduce=reproduce)
expt = Experiment(lab, reproduce=reproduce, force=force)

expt.setup(force_archive=force_archive)

Expand Down
16 changes: 10 additions & 6 deletions test/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,21 +90,25 @@ def payu_setup(model_type=None,
config_path=None,
lab_path=None,
force_archive=None,
reproduce=None):
reproduce=None,
sweep=True,
force=False):
"""
Wrapper around original setup command to provide default arguments
and run in ctrldir
"""
with cd(ctrldir):
payu_sweep(model_type=None,
config_path=None,
hard_sweep=False,
lab_path=str(labdir))
if sweep:
payu_sweep(model_type=None,
config_path=None,
hard_sweep=False,
lab_path=str(labdir))
payu_setup_orignal(model_type,
config_path,
lab_path,
force_archive,
reproduce)
reproduce,
force)


def write_config(config):
Expand Down

0 comments on commit 5dc2299

Please sign in to comment.