예제 #1
0
def test_prolog_and_epilog_is_run(mv_kwargs):
    """Test that the prolog and epilog are always run"""
    # NOTE Ensure that information on parallel execution is logged
    mv_kwargs['parameter_space'] = dict(log_levels=dict(model='debug'))

    # Run with default settings and check log message
    mv = Multiverse(**mv_kwargs)
    mv.run()
    log = mv.wm.tasks[0].streams['out']['log']
    assert any(("Prolog finished." in line for line in log))
    assert any(("Epilog finished." in line for line in log))

    # The "Invoking epilog ..." message should _not_ be there in *this* case,
    # because it denotes that the simulation stopped after receiving a signal
    assert not any(("Invoking epilog ..." in line for line in log))

    # Now perform a longer simulation with a timeout
    mv_kwargs['parameter_space']['num_steps'] = int(1e9)
    mv_kwargs['parameter_space']['write_every'] = int(1e6)
    mv_kwargs['run_kwargs'] = dict(timeout=1.)
    mv_kwargs['paths']['model_note'] = "with_timeout"
    mv = Multiverse(**mv_kwargs)
    mv.run()
    log = mv.wm.tasks[0].streams['out']['log']
    assert any(("Prolog finished." in line for line in log))
    assert any(("Invoking epilog ..." in line for line in log))
    assert any(("Epilog finished." in line for line in log))
예제 #2
0
def test_parallel_init(mv_kwargs):
    """Test enabling parallel execution through the config"""
    # NOTE Ensure that information on parallel execution is logged
    mv_kwargs['parameter_space'] = dict(log_levels=dict(core='debug'))

    # Run with default settings and check log message
    mv_kwargs['paths']['model_note'] = "pexec_disabled"
    mv = Multiverse(**mv_kwargs)
    mv.run()
    log = mv.wm.tasks[0].streams['out']['log']
    assert any(("Parallel execution disabled" in line for line in log))

    # Now override default setting
    mv_kwargs['parameter_space']['parallel_execution'] = dict(enabled=True)
    mv_kwargs['paths']['model_note'] = "pexec_enabled"
    mv = Multiverse(**mv_kwargs)
    mv.run()
    log = mv.wm.tasks[0].streams['out']['log']
    assert any(("Parallel execution enabled" in line for line in log))
예제 #3
0
def test_run_sweep(mv_kwargs):
    """Tests a run with a single simulation"""
    # Adjust the defaults to use the sweep configuration for run configuration
    mv_kwargs['run_cfg_path'] = SWEEP_CFG_PATH
    mv = Multiverse(**mv_kwargs)

    # Run the sweep
    mv.run()

    # There should now be four directories in the data directory
    assert len(os.listdir(mv.dirs['data'])) == 4

    # With a parameter space without volume, i.e. without any sweeps added,
    # the sweep should not be possible
    mv_kwargs['run_cfg_path'] = RUN_CFG_PATH
    mv_kwargs['paths']['model_note'] = "_invalid_cfg"
    mv = Multiverse(**mv_kwargs)

    with pytest.raises(ValueError, match="The parameter space has no sweeps"):
        mv.run_sweep()