示例#1
0
def test_stop_conditions(mv_kwargs):
    """An integration test for stop conditions"""
    mv_kwargs['run_cfg_path'] = STOP_COND_CFG_PATH
    mv = Multiverse(**mv_kwargs)
    mv.run_sweep()
    time.sleep(2)
    assert len(mv.wm.tasks) == 13
    assert len(mv.wm.stopped_tasks) == 13  # all stopped
示例#2
0
def test_cluster_mode_run(mv_kwargs, cluster_env_specific):
    cluster_env = cluster_env_specific

    # Define a custom test environment
    mv_kwargs['run_cfg_path'] = CLUSTER_MODE_CFG_PATH
    mv_kwargs['cluster_params'] = dict(env=cluster_env)

    # Parameter space has 12 points
    # Five nodes are being used: node002, node003, node004, node006, node011
    # Test for first node, should perform 3 simulations
    cluster_env['TEST_NODENAME'] = "node002"
    mv_kwargs['paths']['model_note'] = "node002"

    mv = Multiverse(**mv_kwargs)
    mv.run_sweep()
    assert mv.wm.num_finished_tasks == 3
    assert [t.name for t in mv.wm.tasks] == ['uni01', 'uni06', 'uni11']
    # NOTE: simulated universes are uni01 ... uni12

    # Test for second node, should also perform 3 simulations
    cluster_env['TEST_NODENAME'] = "node003"
    mv_kwargs['paths']['model_note'] = "node003"

    mv = Multiverse(**mv_kwargs)
    mv.run_sweep()
    assert mv.wm.num_finished_tasks == 3
    assert [t.name for t in mv.wm.tasks] == ['uni02', 'uni07', 'uni12']

    # The third node should only perform 2 simulations
    cluster_env['TEST_NODENAME'] = "node004"
    mv_kwargs['paths']['model_note'] = "node004"

    mv = Multiverse(**mv_kwargs)
    mv.run_sweep()
    assert mv.wm.num_finished_tasks == 2
    assert [t.name for t in mv.wm.tasks] == ['uni03', 'uni08']

    # The fourth and fifth node should also perform only 2 simulations
    cluster_env['TEST_NODENAME'] = "node006"
    mv_kwargs['paths']['model_note'] = "node006"

    mv = Multiverse(**mv_kwargs)
    mv.run_sweep()
    assert mv.wm.num_finished_tasks == 2
    assert [t.name for t in mv.wm.tasks] == ['uni04', 'uni09']

    cluster_env['TEST_NODENAME'] = "node011"
    mv_kwargs['paths']['model_note'] = "node011"

    mv = Multiverse(**mv_kwargs)
    mv.run_sweep()
    assert mv.wm.num_finished_tasks == 2
    assert [t.name for t in mv.wm.tasks] == ['uni05', 'uni10']
示例#3
0
def dm_after_large_sweep(mv_kwargs) -> DataManager:
    """Initialises a Multiverse with a DataManager, runs a simulation with
    output going into a temporary directory, then returns the DataManager."""
    # Initialise the Multiverse
    mv_kwargs['run_cfg_path'] = LARGE_SWEEP_CFG_PATH
    mv = Multiverse(**mv_kwargs)

    # Run a sweep
    mv.run_sweep()

    # Return the data manager
    return mv.dm
示例#4
0
def test_bifurcation_diagram_2d(tmpdir):
    """Test plotting of the bifurcation diagram"""
    # Create and run simulation
    raise_exc = {'plot_manager': {'raise_exc': True}}
    mv = Multiverse(model_name='SavannaHomogeneous',
                    run_cfg_path=BIFURCATION_DIAGRAM_2D_RUN,
                    paths=dict(out_dir=str(tmpdir)),
                    **raise_exc)
    mv.run_sweep()

    # Load
    mv.dm.load_from_cfg(print_tree=False)

    # Plot the bifurcation using the last datapoint
    mv.pm.plot_from_cfg(plots_cfg=BIFURCATION_DIAGRAM_2D_PLOTS,
                        plot_only=["bifurcation_diagram_2d"])
    # Plot the bifurcation using the fixpoint
    mv.pm.plot_from_cfg(plots_cfg=BIFURCATION_DIAGRAM_2D_PLOTS,
                        plot_only=["bifurcation_diagram_2d_fixpoint_to_plot"])
示例#5
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()
示例#6
0
def test_bifurcation_diagram(tmpdir):
    """Test plotting of the bifurcation diagram"""
    # Create and run simulation
    raise_exc = {'plot_manager': {'raise_exc': True}}
    mv = Multiverse(model_name='SavannaHomogeneous',
                    run_cfg_path=BIFURCATION_DIAGRAM_RUN,
                    paths=dict(out_dir=str(tmpdir)),
                    **raise_exc)
    mv.run_sweep()

    # Load
    mv.dm.load_from_cfg(print_tree=False)

    # Plot the bifurcation using the last datapoint
    mv.pm.plot_from_cfg(plots_cfg=BIFURCATION_DIAGRAM_PLOTS,
                        plot_only=["bifurcation_endpoint"])
    # Plot the bifurcation using the fixpoint
    mv.pm.plot_from_cfg(plots_cfg=BIFURCATION_DIAGRAM_PLOTS,
                        plot_only=["bifurcation_fixpoint"])
    mv.pm.plot_from_cfg(plots_cfg=BIFURCATION_DIAGRAM_PLOTS,
                        plot_only=["bifurcation_fixpoint_to_plot"])
    # Plot the bifurcation using scatter
    mv.pm.plot_from_cfg(plots_cfg=BIFURCATION_DIAGRAM_PLOTS,
                        plot_only=["bifurcation_scatter"])
    # Plot the bifurcation using oscillation
    mv.pm.plot_from_cfg(plots_cfg=BIFURCATION_DIAGRAM_PLOTS,
                        plot_only=["bifurcation_oscillation"])

    # Redo simulation, but using several initial conditions
    mv = Multiverse(
        model_name='SavannaHomogeneous',
        run_cfg_path=BIFURCATION_DIAGRAM_RUN,
        paths=dict(out_dir=str(tmpdir)),
        **raise_exc,
        parameter_space=dict(seed=psp.ParamDim(default=0, range=[4])))
    mv.run_sweep()
    mv.dm.load_from_cfg(print_tree=False)

    # Plot the bifurcation using multistability
    mv.pm.plot_from_cfg(plots_cfg=BIFURCATION_DIAGRAM_PLOTS,
                        plot_only=["bifurcation_fixpoint"])