Skip to content

Commit

Permalink
Add default_value to fidelity
Browse files Browse the repository at this point in the history
Why:

The EVC is using the default_value to build adapters. Also this default
value can be used as a fall-back if the algorithms does not support
multi-fidelity optimization. This is handy is we want to try different
algorithms with the same experiment configuration.
  • Loading branch information
bouthilx committed Aug 29, 2019
1 parent ee327e5 commit 434926d
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 6 deletions.
9 changes: 8 additions & 1 deletion src/orion/algo/space.py
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,8 @@ class Fidelity(Dimension):
----------
name : str
Name of the dimension
default_value: int
Maximum of the fidelity interval.
"""

Expand All @@ -688,6 +690,11 @@ def __init__(self, name, low, high, base=2):
self.prior = None
self._prior_name = 'None'

@property
def default_value(self):
"""Return `high`"""
return self.high

def get_prior_string(self):
"""Build the string corresponding to current prior"""
return 'fidelity({}, {}, {})'.format(self.low, self.high, self.base)
Expand All @@ -698,7 +705,7 @@ def validate(self):

def sample(self, n_samples=1, seed=None):
"""Do not do anything."""
return ['fidelity']
return [self.high]

def interval(self, alpha=1.0):
"""Do not do anything."""
Expand Down
19 changes: 16 additions & 3 deletions tests/functional/branching/test_branching.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,9 +454,22 @@ def test_auto_resolution_does_resolve(init_full_x_full_y, monkeypatch):
orion.core.cli.main(
("init_only -n {name} --branch {branch} ./black_box_with_y.py "
"-x~uniform(0,10) "
"-w~choices(['a','b'],default_value='a')").format(name=name, branch=branch).split(" "))
orion.core.cli.main("insert -n {name} script -x=2 -w=b".format(name=branch).split(" "))
orion.core.cli.main("insert -n {name} script -x=1".format(name=branch).split(" "))
"-w~choices(['a','b'])").format(name=name, branch=branch).split(" "))


def test_auto_resolution_with_fidelity(init_full_x_full_y, monkeypatch):
"""Test that auto-resolution does resolve all conflicts including new fidelity"""
# Patch cmdloop to avoid autoresolution's prompt
monkeypatch.setattr('sys.__stdin__.isatty', lambda: True)

name = "full_x_full_y"
branch = "half_x_no_y_new_w"
# If autoresolution was not succesfull, this to fail with a sys.exit without registering the
# experiment
orion.core.cli.main(
("init_only -n {name} --branch {branch} ./black_box_with_y.py "
"-x~uniform(0,10) "
"-w~fidelity(1,10)").format(name=name, branch=branch).split(" "))


def test_init_w_version_from_parent_w_children(clean_db, monkeypatch):
Expand Down
12 changes: 10 additions & 2 deletions tests/unittests/algo/test_space.py
Original file line number Diff line number Diff line change
Expand Up @@ -528,10 +528,18 @@ def test_base(self):
assert "Base should be greater than 1" == str(exc.value)

def test_sampling(self):
"""Make sure Fidelity simply returns `fidelity`"""
"""Make sure Fidelity simply returns `high`"""
dim = Fidelity('epoch', 1, 2)
assert dim.sample() == [2]
dim = Fidelity('epoch', 1, 5)
assert dim.sample() == [5]

assert dim.sample() == ['fidelity']
def test_default_value(self):
"""Make sure Fidelity simply returns `high`"""
dim = Fidelity('epoch', 1, 2)
assert dim.default_value == 2
dim = Fidelity('epoch', 1, 5)
assert dim.default_value == 5

def test_contains(self):
"""Make sure fidelity.__contains__ tests based on (min, max)"""
Expand Down

0 comments on commit 434926d

Please sign in to comment.