Skip to content
15 changes: 15 additions & 0 deletions python/ray/tune/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ def _get_experiment_state(experiment_path, exit_on_fail=False):

def list_trials(experiment_path,
sort=None,
output=None,
info_keys=DEFAULT_EXPERIMENT_INFO_KEYS,
result_keys=DEFAULT_RESULT_KEYS):
"""Lists trials in the directory subtree starting at the given path.
Expand All @@ -122,6 +123,7 @@ def list_trials(experiment_path,
experiment_path (str): Directory where trials are located.
Corresponds to Experiment.local_dir/Experiment.name.
sort (str): Key to sort by.
output (str): Name of pickle file where output is saved.
info_keys (list): Keys that are displayed.
result_keys (list): Keys of last result that are displayed.
"""
Expand Down Expand Up @@ -160,16 +162,24 @@ def list_trials(experiment_path,

print_format_output(checkpoints_df)

if output:
experiment_path = os.path.expanduser(experiment_path)
output_filepath = os.path.join(experiment_path, output + ".pkl")
Comment thread
andrewztan marked this conversation as resolved.
Outdated
checkpoints_df.to_pickle(output_filepath)
print("Output saved at:", output_filepath)


def list_experiments(project_path,
sort=None,
output=None,
info_keys=DEFAULT_PROJECT_INFO_KEYS):
"""Lists experiments in the directory subtree.

Args:
project_path (str): Directory where experiments are located.
Corresponds to Experiment.local_dir.
sort (str): Key to sort by.
output (str): Name of pickle file where output is saved.
info_keys (list): Keys that are displayed.
"""
_check_tabulate()
Expand Down Expand Up @@ -230,3 +240,8 @@ def list_experiments(project_path,
info_df = info_df.sort_values(by=sort)

print_format_output(info_df)

if output:
output_filepath = os.path.join(base, output + ".pkl")
info_df.to_pickle(output_filepath)
print("Output saved at:", output_filepath)
20 changes: 16 additions & 4 deletions python/ray/tune/scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,30 @@ def cli():
@click.argument("experiment_path", required=True, type=str)
@click.option(
'--sort', default=None, type=str, help='Select which column to sort on.')
def list_trials(experiment_path, sort):
@click.option(
'--output',
'-o',
default=None,
type=str,
help='Output information to a pickle file.')
def list_trials(experiment_path, sort, output):
"""Lists trials in the directory subtree starting at the given path."""
commands.list_trials(experiment_path, sort)
commands.list_trials(experiment_path, sort, output)


@cli.command()
@click.argument("project_path", required=True, type=str)
@click.option(
'--sort', default=None, type=str, help='Select which column to sort on.')
def list_experiments(project_path, sort):
@click.option(
'--output',
'-o',
default=None,
type=str,
help='Output information to a pickle file.')
def list_experiments(project_path, sort, output):
"""Lists experiments in the directory subtree."""
commands.list_experiments(project_path, sort)
commands.list_experiments(project_path, sort, output)


cli.add_command(list_trials, name="ls")
Expand Down