Reimplement status command to work with combinatorial experiments
@@ -13,7 +13,9 @@ Query output files for quick status.
# MODULE IMPORTS
# =============================================================================================
-from .. import utils
+import collections
+
+from .. import experiment
# =============================================================================================
# COMMAND-LINE INTERFACE
@@ -23,16 +25,25 @@ usage = """
YANK status
Usage:
- yank status (-s=STORE | --store=STORE) [-v | --verbose]
+ yank status (-y FILEPATH | --yaml=FILEPATH) [--status=STRING] [--njobs=INTEGER] [-v | --verbose]
Description:
- Get the current status of a running or completed simulation
+ Print the current status of the experiments.
Required Arguments:
- -s=STORE, --store=STORE Storage directory for NetCDF data files.
+ -y, --yaml=FILEPATH Path to the YAML script specifying options and/or how to
+ set up and run the experiment.
General Options:
- -v, --verbose Print verbose output
+ --status=STRING Print only the jobs in a particular status. Accepted values
+ are completed, running, and pending. This works only if
+ --verbose is set.
+ --njobs=INTEGER Print the job id associated to each experiment assuming
+ njobs to be the one specified here. This works only if
+ --verbose is set.
+ -v, --verbose Print status of each experiment individually. If this is
+ not set, only a summary of the status of all experiments
+ is printed.
"""
@@ -40,9 +51,45 @@ General Options:
# COMMAND DISPATCH
# =============================================================================================
-
def dispatch(args):
- from .. import analyze
- utils.config_root_logger(args['--verbose'])
- success = analyze.print_status(args['--store'])
- return success
+ # Handle optional arguments.
+ if args['--njobs']:
+ n_jobs = int(args['--njobs'])
+ else:
+ n_jobs = None
+
+ exp_builder = experiment.ExperimentBuilder(args['--yaml'], n_jobs=n_jobs)
+
+ # Count all experiment status.
+ counter = collections.Counter()
+ for exp_status in exp_builder.status():
+ counter[exp_status.status] += 1
+
+ # Print experiment and phases details.
+ if args['--verbose']:
+ # Filter by status if requested.
+ if args['--status'] and args['--status'] != exp_status.status:
+ continue
+
+ # Print experiment information.
+ exp_description = '{}: status {}'.format(exp_status.name,
+ exp_status.status)
+ if n_jobs is not None:
+ exp_description += ', job_id {}'.format(exp_status.job_id)
+ print(exp_description)
+
+ # Print phases information.
+ for phase_name, phase_status in exp_status.phases.items():
+ if phase_status.iteration is not None:
+ iteration = ', iteration {}/{}'.format(phase_status.iteration,
+ exp_status.number_of_iterations)
+ else:
+ iteration = ''
+ print('\t{}: status{}{}'.format(phase_status.status, iteration))
+
+ # Print summary.
+ tot_n_experiments = sum(count for count in counter.values())
+ print('Total number of experiments: {} ({} completed, {} running, '
+ '{} pending)'.format(tot_n_experiments, counter['completed'],
+ counter['running'], counter['pending']))
+ return True
