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

Avoid branching in info #277

Merged
merged 1 commit into from
Aug 30, 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
22 changes: 20 additions & 2 deletions src/orion/core/cli/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

"""
import logging
import sys

from orion.core.cli.base import get_basic_args_group
from orion.core.io.evc_builder import EVCBuilder
Expand All @@ -27,9 +28,23 @@ def add_subparser(parser):
return info_parser


# pylint: disable=protected-access
def hack_until_config_is_refactored(experiment):
"""Build the space and the algorithm"""
experiment._experiment._instantiate_config(experiment.configuration)
experiment._experiment._init_done = True


def main(args):
"""Fetch config and info experiments"""
experiment = EVCBuilder().build_from(args)
try:
experiment = EVCBuilder().build_view_from(args)
except ValueError:
print('Experiment {} not found in db.'.format(args.get('name', None)))
sys.exit(1)

hack_until_config_is_refactored(experiment)

print(format_info(experiment))


Expand Down Expand Up @@ -326,14 +341,17 @@ def format_space(experiment):
user: {experiment.metadata[user]}
datetime: {experiment.metadata[datetime]}
orion version: {experiment.metadata[orion_version]}
VCS:
{vcs}
"""


def format_metadata(experiment):
"""Render a string for metadata section"""
metadata_string = METADATA_TEMPLATE.format(
title=format_title("Meta-data"),
experiment=experiment)
experiment=experiment,
vcs=format_dict(experiment.metadata.get('VCS', {}), depth=1, width=2))

return metadata_string

Expand Down
4 changes: 3 additions & 1 deletion src/orion/storage/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,13 +247,15 @@ class ReadOnlyStorageProtocol(object):

__slots__ = ('_storage', )
valid_attributes = {
'get_trial',
'fetch_trials',
'fetch_experiments',
'count_broken_trials',
'count_completed_trials',
'fetch_noncompleted_trials',
'fetch_pending_trials',
'fetch_lost_trials'
'fetch_lost_trials',
'fetch_trial_by_status'
}

def __init__(self, protocol):
Expand Down
12 changes: 12 additions & 0 deletions tests/functional/commands/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,18 @@ def one_experiment(monkeypatch, db_instance):
return get_storage().fetch_experiments({'name': name})[0]


@pytest.fixture
def one_experiment_changed_vcs(one_experiment):
"""Create an experiment without trials."""
experiment = ExperimentBuilder().build_from({'name': one_experiment['name']})

experiment.metadata['VCS'] = {
'type': 'git', 'is_dirty': False, 'HEAD_sha': 'new', 'active_branch': 'master',
'diff_sha': None}

get_storage().update_experiment(experiment, metadata=experiment.metadata)


@pytest.fixture
def one_experiment_no_version(monkeypatch, one_experiment):
"""Create an experiment without trials."""
Expand Down
22 changes: 20 additions & 2 deletions tests/functional/commands/test_info_command.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Perform a functional test of the info command."""
import pytest

import orion.core.cli
import orion.core.io.resolve_config


def test_info_no_hit(clean_db, one_experiment, capsys):
"""Test info if no experiment with given name."""
orion.core.cli.main(['info', '--name', 'i do not exist'])
with pytest.raises(SystemExit) as exc:
orion.core.cli.main(['info', '--name', 'i do not exist'])

assert str(exc.value) == '1'

captured = capsys.readouterr().out

assert captured == 'Error: No commandline configuration found for new experiment.\n'
assert captured == 'Experiment i do not exist not found in db.\n'


def test_info_hit(clean_db, one_experiment, capsys):
Expand All @@ -29,3 +35,15 @@ def test_info_broken(clean_db, broken_refers, capsys):
captured = capsys.readouterr().out

assert '--x~uniform(0,1)' in captured


def test_info_no_branching(clean_db, one_experiment_changed_vcs, capsys):
"""Test info if config file is different

Version should not increase!
"""
orion.core.cli.main(['info', '--name', 'test_single_exp'])

captured = capsys.readouterr().out

assert '\nversion: 1\n' in captured
28 changes: 26 additions & 2 deletions tests/unittests/core/cli/test_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,13 +440,25 @@ def test_format_metadata():
experiment.metadata = dict(
user='user',
datetime='now',
orion_version='1.0.1')
orion_version='1.0.1',
VCS=dict(
HEAD_sha='sha',
active_branch='branch',
diff_sha='smt',
is_dirty=True,
type='git'))
assert format_metadata(experiment) == """\
Meta-data
=========
user: user
datetime: now
orion version: 1.0.1
VCS:
HEAD_sha: sha
active_branch: branch
diff_sha: smt
is_dirty: True
type: git
"""


Expand Down Expand Up @@ -569,7 +581,13 @@ def test_format_info(algorithm_dict, dummy_trial):
experiment.metadata.update(dict(
user='user',
datetime='now',
orion_version='1.0.1'))
orion_version='1.0.1',
VCS=dict(
HEAD_sha='sha',
active_branch='branch',
diff_sha='smt',
is_dirty=True,
type='git')))

ROOT_NAME = 'root-name'
PARENT_NAME = 'parent-name'
Expand Down Expand Up @@ -639,6 +657,12 @@ def test_format_info(algorithm_dict, dummy_trial):
user: user
datetime: now
orion version: 1.0.1
VCS:
HEAD_sha: sha
active_branch: branch
diff_sha: smt
is_dirty: True
type: git


Parent experiment
Expand Down