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

[tune] Add --columns flag for CLI #4564

Merged
merged 8 commits into from
Apr 6, 2019
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
4 changes: 2 additions & 2 deletions doc/source/tune-usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ Tune CLI (Experimental)

Here are a few examples of command line calls.

- ``tune list-trials``: List tabular information about trials within an experiment. Empty columns will be dropped by default. Add the ``--sort`` flag to sort the output by specific columns. Add the ``--filter`` flag to filter the output in the format ``"<column> <operator> <value>"``. Add the ``--output`` flag to write the trial information to a specific file (CSV or Pickle).
- ``tune list-trials``: List tabular information about trials within an experiment. Empty columns will be dropped by default. Add the ``--sort`` flag to sort the output by specific columns. Add the ``--filter`` flag to filter the output in the format ``"<column> <operator> <value>"``. Add the ``--output`` flag to write the trial information to a specific file (CSV or Pickle). Add the ``--columns`` and ``--result-columns`` flags to select specific columns to display.

.. code-block:: bash

Expand Down Expand Up @@ -494,7 +494,7 @@ Here are a few examples of command line calls.
Dropped columns: ['status', 'last_update_time']
Please increase your terminal size to view remaining columns.

- ``tune list-experiments``: List tabular information about experiments within a project. Empty columns will be dropped by default. Add the ``--sort`` flag to sort the output by specific columns. Add the ``--filter`` flag to filter the output in the format ``"<column> <operator> <value>"``. Add the ``--output`` flag to write the trial information to a specific file (CSV or Pickle).
- ``tune list-experiments``: List tabular information about experiments within a project. Empty columns will be dropped by default. Add the ``--sort`` flag to sort the output by specific columns. Add the ``--filter`` flag to filter the output in the format ``"<column> <operator> <value>"``. Add the ``--output`` flag to write the trial information to a specific file (CSV or Pickle). Add the ``--columns`` flag to select specific columns to display.

.. code-block:: bash

Expand Down
12 changes: 9 additions & 3 deletions python/ray/tune/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ def list_trials(experiment_path,
sort=None,
output=None,
filter_op=None,
info_keys=DEFAULT_EXPERIMENT_INFO_KEYS,
result_keys=DEFAULT_RESULT_KEYS):
info_keys=None,
result_keys=None):
"""Lists trials in the directory subtree starting at the given path.

Args:
Expand All @@ -151,6 +151,10 @@ def list_trials(experiment_path,
checkpoint_dicts = [flatten_dict(g) for g in checkpoint_dicts]
checkpoints_df = pd.DataFrame(checkpoint_dicts)

if not info_keys:
info_keys = DEFAULT_EXPERIMENT_INFO_KEYS
if not result_keys:
result_keys = DEFAULT_RESULT_KEYS
result_keys = ["last_result:{}".format(k) for k in result_keys]
col_keys = [
k for k in list(info_keys) + result_keys if k in checkpoints_df
Expand Down Expand Up @@ -208,7 +212,7 @@ def list_experiments(project_path,
sort=None,
output=None,
filter_op=None,
info_keys=DEFAULT_PROJECT_INFO_KEYS):
info_keys=None):
"""Lists experiments in the directory subtree.

Args:
Expand Down Expand Up @@ -263,6 +267,8 @@ def list_experiments(project_path,
sys.exit(0)

info_df = pd.DataFrame(experiment_data_collection)
if not info_keys:
info_keys = DEFAULT_PROJECT_INFO_KEYS
richardliaw marked this conversation as resolved.
Show resolved Hide resolved
col_keys = [k for k in list(info_keys) if k in info_df]
if not col_keys:
print("None of keys {} in experiment data!".format(info_keys))
Expand Down
32 changes: 28 additions & 4 deletions python/ray/tune/scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,26 @@ def cli():
default=None,
type=str,
help="Select filter in the format '<column> <operator> <value>'.")
def list_trials(experiment_path, sort, output, filter_op):
@click.option(
"--columns",
default=None,
type=str,
help="Select columns to be displayed.")
@click.option(
"--result-columns",
"result_columns",
andrewztan marked this conversation as resolved.
Show resolved Hide resolved
default=None,
type=str,
help="Select columns of last result to be displayed.")
def list_trials(experiment_path, sort, output, filter_op, columns,
result_columns):
"""Lists trials in the directory subtree starting at the given path."""
commands.list_trials(experiment_path, sort, output, filter_op)
if columns:
columns = columns.split(',')
if result_columns:
result_columns = result_columns.split(',')
commands.list_trials(experiment_path, sort, output, filter_op, columns,
result_columns)


@cli.command()
Expand All @@ -50,9 +67,16 @@ def list_trials(experiment_path, sort, output, filter_op):
default=None,
type=str,
help="Select filter in the format '<column> <operator> <value>'.")
def list_experiments(project_path, sort, output, filter_op):
@click.option(
"--columns",
default=None,
type=str,
help="Select columns to be displayed.")
def list_experiments(project_path, sort, output, filter_op, columns):
"""Lists experiments in the directory subtree."""
commands.list_experiments(project_path, sort, output, filter_op)
if columns:
columns = columns.split(',')
commands.list_experiments(project_path, sort, output, filter_op, columns)


@cli.command()
Expand Down
13 changes: 12 additions & 1 deletion python/ray/tune/tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,18 @@ def test_ls(start_ray, tmpdir):
})

with Capturing() as output:
commands.list_trials(experiment_path, info_keys=("status", ))
commands.list_trials(
experiment_path,
info_keys=("status", ),
result_keys=(
"episode_reward_mean",
"training_iteration",
))
lines = output.captured
assert sum("TERMINATED" in line for line in lines) == num_samples
columns = ["status", "episode_reward_mean", "training_iteration"]
assert all(col in lines[1] for col in columns)
assert lines[1].count('|') == 4

with Capturing() as output:
commands.list_trials(
Expand Down Expand Up @@ -113,6 +122,8 @@ def test_lsx(start_ray, tmpdir):
commands.list_experiments(project_path, info_keys=("total_trials", ))
lines = output.captured
assert sum("1" in line for line in lines) >= num_experiments
assert "total_trials" in lines[1]
assert lines[1].count('|') == 2

with Capturing() as output:
commands.list_experiments(
Expand Down