Beispiel #1
0
def test_experiment():
    parameter_set = ParameterSet()
    parameter_set.add_parameters(x1=range(3), x2=range(3))
    experiment = Experiment(__EXP_NAME__, parameter_set, TestComputation,
                            IntrospectStorage)
    assert_equal(len(list(experiment.yield_computations())), 9)
    # start=3 : skip 0,1,2
    assert_equal(len(list(experiment.yield_computations(start=3))), 6)
    # capacity=6 : skip 6, 7, 8
    assert_equal(len(list(experiment.yield_computations(capacity=6))), 6)
def test_session():
    parameter_set = ParameterSet()
    parameter_set.add_parameters(x1=range(3), x2=range(3))
    experiment = Experiment(__EXP_NAME__, parameter_set, TestComputation,
                            IntrospectStorage)

    env = InSituEnvironment(fail_fast=True)
    session = env.create_session(experiment)
    assert_false(session.is_open())
    assert_raises(ValueError, partial(session.run, TestComputation()))
    with session:
        for lazy_computation in experiment.yield_computations():
            session.run(lazy_computation)
        assert_equal(session.n_launch, 9)

    assert_false(session.is_open())
    assert_raises(ValueError, partial(session.run, TestComputation()))
Beispiel #3
0
def do_auto_refresh(auto_refresh):

    parameter_set = ParameterSet()
    parameter_set.add_parameters(x1=range(3), x2=range(3))
    experiment = Experiment("{}_1".format(__EXP_NAME__), parameter_set,
                            TestComputation)

    # There should be 9 computations
    assert_equal(len(experiment), 9)
    count = 0
    for i, _ in enumerate(
            experiment.yield_computations(auto_refresh=auto_refresh)):
        if i == 0:
            state = CompletedState(
                Experiment.name_computation(experiment.exp_name, 6))
            PickleStorage(experiment.exp_name).update_state(state)
        count += 1

    print("Auto refresh?", auto_refresh, "--", count)
    assert_equal(count, 8 if auto_refresh else 9)