-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Why: The termination condition was wrong and would stop when the penultimate rung was filled, making it impossible to ever run the final trial with max resources.
- Loading branch information
Showing
6 changed files
with
224 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
name: demo_algo | ||
|
||
pool_size: 1 | ||
max_trials: 100 | ||
|
||
algorithms: | ||
asha: | ||
seed: 1 | ||
num_rungs: 4 | ||
num_brackets: 1 | ||
grace_period: null | ||
max_resources: null | ||
reduction_factor: null | ||
|
||
producer: | ||
strategy: StubParallelStrategy | ||
|
||
database: | ||
type: 'mongodb' | ||
name: 'orion_test' | ||
host: 'mongodb://user:pass@localhost' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
"""Simple one dimensional example with noise level for a possible user's script.""" | ||
import argparse | ||
import random | ||
|
||
from orion.client import report_results | ||
|
||
|
||
def function(x, noise): | ||
"""Evaluate partial information of a quadratic.""" | ||
z = (x - 34.56789) * random.gauss(0, noise) | ||
return 4 * z**2 + 23.4, 8 * z | ||
|
||
|
||
def execute(): | ||
"""Execute a simple pipeline as an example.""" | ||
# 1. Receive inputs as you want | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument('-x', type=float, required=True) | ||
parser.add_argument('--fidelity', type=int, default=10) | ||
inputs = parser.parse_args() | ||
|
||
assert 0 <= inputs.fidelity <= 10 | ||
|
||
noise = (1 - inputs.fidelity / 10) + 0.0001 | ||
|
||
# 2. Perform computations | ||
y, dy = function(inputs.x, noise) | ||
|
||
# 3. Gather and report results | ||
results = list() | ||
results.append(dict( | ||
name='example_objective', | ||
type='objective', | ||
value=y)) | ||
results.append(dict( | ||
name='example_gradient', | ||
type='gradient', | ||
value=[dy])) | ||
|
||
report_results(results) | ||
|
||
|
||
if __name__ == "__main__": | ||
execute() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
name: demo_algo | ||
|
||
pool_size: 1 | ||
max_trials: 100 | ||
|
||
algorithms: | ||
random: | ||
seed: 1 | ||
|
||
database: | ||
type: 'mongodb' | ||
name: 'orion_test' | ||
host: 'mongodb://user:pass@localhost' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
"""Perform a functional test for algos included with orion.""" | ||
import os | ||
|
||
import pytest | ||
import yaml | ||
|
||
import orion.core.cli | ||
from orion.storage.base import get_storage | ||
|
||
|
||
config_files = ['random_config.yaml'] | ||
fidelity_config_files = ['random_config.yaml', 'asha_config.yaml'] | ||
fidelity_only_config_files = list(set(fidelity_config_files) - set(config_files)) | ||
|
||
|
||
@pytest.mark.usefixtures("clean_db") | ||
@pytest.mark.usefixtures("null_db_instances") | ||
@pytest.mark.parametrize('config_file', fidelity_only_config_files) | ||
def test_missing_fidelity(monkeypatch, config_file): | ||
"""Test a simple usage scenario.""" | ||
monkeypatch.chdir(os.path.dirname(os.path.abspath(__file__))) | ||
|
||
with pytest.raises(RuntimeError) as exc: | ||
orion.core.cli.main(["hunt", "--config", config_file, | ||
"./black_box.py", "-x~uniform(-50, 50)"]) | ||
assert "https://orion.readthedocs.io/en/develop/user/algorithms.html" in str(exc.value) | ||
|
||
|
||
@pytest.mark.usefixtures("clean_db") | ||
@pytest.mark.usefixtures("null_db_instances") | ||
@pytest.mark.parametrize('config_file', config_files) | ||
def test_simple(monkeypatch, config_file): | ||
"""Test a simple usage scenario.""" | ||
monkeypatch.chdir(os.path.dirname(os.path.abspath(__file__))) | ||
orion.core.cli.main(["hunt", "--config", config_file, | ||
"./black_box.py", "-x~uniform(-50, 50)"]) | ||
|
||
with open(config_file, 'rb') as f: | ||
config = yaml.safe_load(f) | ||
|
||
storage = get_storage() | ||
exp = list(storage.fetch_experiments({'name': config['name']})) | ||
assert len(exp) == 1 | ||
exp = exp[0] | ||
assert '_id' in exp | ||
exp_id = exp['_id'] | ||
assert exp['name'] == config['name'] | ||
assert exp['pool_size'] == 1 | ||
assert exp['max_trials'] == 100 | ||
assert exp['algorithms'] == config['algorithms'] | ||
assert 'user' in exp['metadata'] | ||
assert 'datetime' in exp['metadata'] | ||
assert 'orion_version' in exp['metadata'] | ||
assert 'user_script' in exp['metadata'] | ||
assert os.path.isabs(exp['metadata']['user_script']) | ||
assert exp['metadata']['user_args'] == ['-x~uniform(-50, 50)'] | ||
|
||
trials = storage.fetch_trials(uid=exp_id) | ||
assert len(trials) <= config['max_trials'] | ||
assert trials[-1].status == 'completed' | ||
|
||
best_trial = next(iter(sorted(trials, key=lambda trial: trial.objective.value))) | ||
assert best_trial.objective.name == 'example_objective' | ||
assert abs(best_trial.objective.value - 23.4) < 1e-5 | ||
assert len(best_trial.params) == 1 | ||
param = best_trial.params[0] | ||
assert param.name == '/x' | ||
assert param.type == 'real' | ||
|
||
|
||
@pytest.mark.usefixtures("clean_db") | ||
@pytest.mark.usefixtures("null_db_instances") | ||
@pytest.mark.parametrize('config_file', fidelity_config_files) | ||
def test_with_fidelity(database, monkeypatch, config_file): | ||
"""Test a scenario with fidelity.""" | ||
monkeypatch.chdir(os.path.dirname(os.path.abspath(__file__))) | ||
orion.core.cli.main(["hunt", "--config", config_file, | ||
"./black_box.py", "-x~uniform(-50, 50)", "--fidelity~fidelity(1,10,4)"]) | ||
|
||
with open(config_file, 'rb') as f: | ||
config = yaml.safe_load(f) | ||
|
||
storage = get_storage() | ||
exp = list(storage.fetch_experiments({'name': config['name']})) | ||
assert len(exp) == 1 | ||
exp = exp[0] | ||
assert '_id' in exp | ||
exp_id = exp['_id'] | ||
assert exp['name'] == config['name'] | ||
assert exp['pool_size'] == 1 | ||
assert exp['max_trials'] == 100 | ||
assert exp['algorithms'] == config['algorithms'] | ||
assert 'user' in exp['metadata'] | ||
assert 'datetime' in exp['metadata'] | ||
assert 'orion_version' in exp['metadata'] | ||
assert 'user_script' in exp['metadata'] | ||
assert os.path.isabs(exp['metadata']['user_script']) | ||
assert exp['metadata']['user_args'] == ['-x~uniform(-50, 50)', "--fidelity~fidelity(1,10,4)"] | ||
|
||
trials = storage.fetch_trials(uid=exp_id) | ||
assert len(trials) <= config['max_trials'] | ||
assert trials[-1].status == 'completed' | ||
|
||
best_trial = next(iter(sorted(trials, key=lambda trial: trial.objective.value))) | ||
assert best_trial.objective.name == 'example_objective' | ||
assert abs(best_trial.objective.value - 23.4) < 1e-5 | ||
assert len(best_trial.params) == 2 | ||
fidelity = best_trial.params[0] | ||
assert fidelity.name == '/fidelity' | ||
assert fidelity.type == 'fidelity' | ||
assert fidelity.value == 10 | ||
param = best_trial.params[1] | ||
assert param.name == '/x' | ||
assert param.type == 'real' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters