Skip to content

Commit

Permalink
Handle cmdline config with status cmd (#1094)
Browse files Browse the repository at this point in the history
The storage is not a singleton anymore and must be passed down in
functions if they all need to use the same storage. The status command
was not adjusted properly when the whole code base was refactored to
remove singletons.

Now uses ExperimentBuilder always with the same storage.

Co-authored-by: Setepenre <[email protected]>
  • Loading branch information
bouthilx and Delaunay authored Aug 10, 2023
1 parent 34ca8de commit 0b10286
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/orion/core/cli/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

from orion.core.cli import base as cli
from orion.core.io import experiment_builder
from orion.storage.base import setup_storage

log = logging.getLogger(__name__)
SHORT_DESCRIPTION = "Gives an overview of experiments' trials"
Expand Down Expand Up @@ -67,18 +66,18 @@ def add_subparser(parser):
def main(args):
"""Fetch config and status experiments"""
config = experiment_builder.get_cmd_config(args)
storage = setup_storage(config.get("storage"))
builder = experiment_builder.ExperimentBuilder(config.get("storage"))

args["all_trials"] = args.pop("all", False)

experiments = get_experiments(storage, args)
experiments = get_experiments(builder, args)

if not experiments:
print("No experiment found")
return

if args.get("name"):
print_evc([experiments[0]], **args)
print_evc([experiments[0]], builder, **args)
return

if args.get("version"):
Expand All @@ -88,12 +87,13 @@ def main(args):
"or --expand-versions."
)

print_evc(experiments, **args)
print_evc(experiments, builder, **args)


# pylint: disable=unused-argument
def print_evc(
experiments,
builder,
version=None,
all_trials=False,
collapse=False,
Expand All @@ -109,7 +109,7 @@ def print_evc(
"""
for exp in experiments:
experiment = experiment_builder.load(exp.name, version)
experiment = builder.load(exp.name, version)
if version is None:
expand_experiment = exp
else:
Expand All @@ -121,7 +121,7 @@ def print_evc(
print_status(experiment, all_trials=all_trials, collapse=True)


def get_experiments(storage, args):
def get_experiments(builder, args):
"""Return the different experiments.
Parameters
Expand All @@ -133,7 +133,7 @@ def get_experiments(storage, args):
projection = {"name": 1, "version": 1, "refers": 1}

query = {"name": args["name"]} if args.get("name") else {}
experiments = storage.fetch_experiments(query, projection)
experiments = builder.storage.fetch_experiments(query, projection)

if args["name"]:
root_experiments = experiments
Expand All @@ -145,7 +145,7 @@ def get_experiments(storage, args):
]

return [
experiment_builder.load(name=exp["name"], version=exp.get("version", 1))
builder.load(name=exp["name"], version=exp.get("version", 1))
for exp in root_experiments
]

Expand Down
39 changes: 39 additions & 0 deletions tests/functional/commands/test_status_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
import os

import pytest
import yaml

import orion.core.cli
from orion.core.io.experiment_builder import ExperimentBuilder
from orion.testing.state import OrionState


def test_no_experiments(orionstate, monkeypatch, capsys):
Expand Down Expand Up @@ -1238,3 +1241,39 @@ def test_experiment_cant_use_version(three_experiments_same_name):
orion.core.cli.main(["status", "--version", "2", "--expand-versions"])

assert "expand-versions" in str(ex.value)


def test_using_config_file(three_experiments_family_same_name, capsys, tmp_path):
"""Test status using `--config`."""
orion.core.cli.main(["status"])

captured = capsys.readouterr().out

assert "test_single_exp_child-v1" in captured

config_path = str(tmp_path / "config.yaml")

with OrionState() as cfg:
with open(config_path, "w") as f:
yaml.dump(
{
"storage": {
"database": {"type": "pickleddb", "host": cfg.storage._db.host}
}
},
f,
)

orion.core.cli.main(["status", "--config", config_path])

captured = capsys.readouterr().out

assert "test_single_exp_child-v1" not in captured

ExperimentBuilder(cfg.storage).build(name="test", space={"x": "uniform(0, 1)"})

orion.core.cli.main(["status", "--config", config_path])

captured = capsys.readouterr().out

assert captured == "test-v1\n=======\nempty\n\n\n"

0 comments on commit 0b10286

Please sign in to comment.