示例#1
0
def test_workon(database):
    """Test scenario having a configured experiment already setup."""
    try:
        Database(of_type='MongoDB',
                 name='orion_test',
                 username='******',
                 password='******')
    except (TypeError, ValueError):
        pass
    experiment = Experiment('voila_voici')
    config = experiment.configuration
    config['algorithms'] = {'gradient_descent': {'learning_rate': 0.1}}
    config['pool_size'] = 1
    config['max_trials'] = 100
    config['metadata']['user_script'] = os.path.abspath(
        os.path.join(os.path.dirname(__file__), "black_box.py"))
    config['metadata']['user_args'] = ["-x~uniform(-50, 50)"]
    experiment.configure(config)

    workon(experiment)

    exp = list(database.experiments.find({'name': 'voila_voici'}))
    assert len(exp) == 1
    exp = exp[0]
    assert '_id' in exp
    exp_id = exp['_id']
    assert exp['name'] == 'voila_voici'
    assert exp['pool_size'] == 1
    assert exp['max_trials'] == 100
    assert exp['algorithms'] == {
        'gradient_descent': {
            'learning_rate': 0.1,
            'dx_tolerance': 1e-7
        }
    }
    assert 'user' in exp['metadata']
    assert 'datetime' 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 = list(database.trials.find({'experiment': exp_id}))
    assert len(trials) <= 15
    trials = list(sorted(trials, key=lambda trial: trial['submit_time']))
    assert trials[-1]['status'] == 'completed'
    for result in trials[-1]['results']:
        assert result['type'] != 'constraint'
        if result['type'] == 'objective':
            assert abs(result['value'] - 23.4) < 1e-6
            assert result['name'] == 'example_objective'
        elif result['type'] == 'gradient':
            res = numpy.asarray(result['value'])
            assert 0.1 * numpy.sqrt(res.dot(res)) < 1e-7
            assert result['name'] == 'example_gradient'
    params = trials[-1]['params']
    assert len(params) == 1
    assert params[0]['name'] == '/x'
    assert params[0]['type'] == 'real'
    assert (params[0]['value'] - 34.56789) < 1e-5
示例#2
0
def main(args):
    """Build experiment and execute hunt command"""
    args['root'] = None
    args['leafs'] = []
    # TODO: simplify when parameter parsing is refactored
    worker_trials = ExperimentBuilder().fetch_full_config(args)['worker_trials']
    experiment = EVCBuilder().build_from(args)
    workon(experiment, worker_trials)
示例#3
0
def test_workon():
    """Test scenario having a configured experiment already setup."""
    name = "voici_voila"
    config = {"name": name}
    config["algorithms"] = {"gradient_descent": {"learning_rate": 0.1}}
    config["pool_size"] = 1
    config["max_trials"] = 100
    config["exp_max_broken"] = 5
    config["user_args"] = [
        os.path.abspath(os.path.join(os.path.dirname(__file__),
                                     "black_box.py")),
        "-x~uniform(-50, 50, precision=None)",
    ]

    with OrionState():
        experiment = experiment_builder.build_from_args(config)

        workon(experiment, 100, 100, 100, 100, 100)

        storage = get_storage()

        exp = list(storage.fetch_experiments({"name": name}))
        assert len(exp) == 1
        exp = exp[0]
        assert "_id" in exp
        assert exp["name"] == name
        assert exp["pool_size"] == 1
        assert exp["max_trials"] == 100
        assert exp["max_broken"] == 5
        assert exp["algorithms"] == {
            "gradient_descent": {
                "learning_rate": 0.1,
                "dx_tolerance": 1e-7
            }
        }
        assert "user" in exp["metadata"]
        assert "datetime" in exp["metadata"]
        assert "user_script" in exp["metadata"]
        assert exp["metadata"]["user_args"] == config["user_args"]

        trials = list(storage.fetch_trials(experiment))
        assert len(trials) <= 15
        trials = list(sorted(trials, key=lambda trial: trial.submit_time))
        assert trials[-1].status == "completed"
        for result in trials[-1].results:
            assert result.type != "constraint"
            if result.type == "objective":
                assert abs(result.value - 23.4) < 1e-6
                assert result.name == "example_objective"
            elif result.type == "gradient":
                res = numpy.asarray(result.value)
                assert 0.1 * numpy.sqrt(res.dot(res)) < 1e-7
                assert result.name == "example_gradient"
        params = trials[-1].params
        assert len(params) == 1
        px = params["/x"]
        assert isinstance(px, float)
        assert (px - 34.56789) < 1e-5
示例#4
0
def test_workon():
    """Test scenario having a configured experiment already setup."""
    name = 'voici_voila'
    config = {'name': name}
    config['algorithms'] = {
        'gradient_descent': {
            'learning_rate': 0.1
            }
        }
    config['pool_size'] = 1
    config['max_trials'] = 100
    config['user_args'] = [
        os.path.abspath(os.path.join(os.path.dirname(__file__), "black_box.py")),
        "-x~uniform(-50, 50, precision=None)"]

    with OrionState():
        experiment = experiment_builder.build_from_args(config)

        workon(experiment, 100, 100, 100, 100, 100)

        storage = get_storage()

        exp = list(storage.fetch_experiments({'name': name}))
        assert len(exp) == 1
        exp = exp[0]
        assert '_id' in exp
        assert exp['name'] == name
        assert exp['pool_size'] == 1
        assert exp['max_trials'] == 100
        assert exp['algorithms'] == {'gradient_descent': {'learning_rate': 0.1,
                                                          'dx_tolerance': 1e-7}}
        assert 'user' in exp['metadata']
        assert 'datetime' in exp['metadata']
        assert 'user_script' in exp['metadata']
        assert exp['metadata']['user_args'] == config['user_args']

        trials = list(storage.fetch_trials(experiment))
        assert len(trials) <= 15
        trials = list(sorted(trials, key=lambda trial: trial.submit_time))
        assert trials[-1].status == 'completed'
        for result in trials[-1].results:
            assert result.type != 'constraint'
            if result.type == 'objective':
                assert abs(result.value - 23.4) < 1e-6
                assert result.name == 'example_objective'
            elif result.type == 'gradient':
                res = numpy.asarray(result.value)
                assert 0.1 * numpy.sqrt(res.dot(res)) < 1e-7
                assert result.name == 'example_gradient'
        params = trials[-1]._params
        assert len(params) == 1
        assert params[0].name == '/x'
        assert params[0].type == 'real'
        assert (params[0].value - 34.56789) < 1e-5
示例#5
0
def main(args):
    """Build experiment and execute hunt command"""
    args['root'] = None
    args['leafs'] = []
    # TODO: simplify when parameter parsing is refactored
    experiment = experiment_builder.build_from_args(args)
    config = experiment_builder.get_cmd_config(args)
    worker_config = orion.core.config.worker.to_dict()
    if config.get('worker'):
        worker_config.update(config.get('worker'))

    workon(experiment, **worker_config)
示例#6
0
def main(args):
    """Build experiment and execute hunt command"""
    args["root"] = None
    args["leafs"] = []
    # TODO: simplify when parameter parsing is refactored
    experiment = experiment_builder.build_from_args(args)

    if args["init_only"]:
        return

    config = experiment_builder.get_cmd_config(args)
    worker_config = orion.core.config.worker.to_dict()
    if config.get("worker"):
        worker_config.update(config.get("worker"))

    workon(experiment,
           ignore_code_changes=config["branching"].get("ignore_code_changes"),
           **worker_config)
示例#7
0
def main():
    """Entry point for `orion.core` functionality."""
    experiment = infer_experiment()
    workon(experiment)
    return 0
示例#8
0
def main(args):
    """Build experiment and execute hunt command"""
    args['root'] = None
    args['leafs'] = []
    experiment = EVCBuilder().build_from(args)
    workon(experiment)
示例#9
0
def _execute(cmdargs, cmdconfig):
    experiment = _infer_experiment(cmdargs, cmdconfig)
    workon(experiment)