Example #1
0
def test_ray_engine_tune():
    import ray
    from ray import tune

    ray.init(ignore_reinit_error=True)
    ml.execute(
        ml.Experiment().components("tunemodel").tune(
            stop={"acc": 0.5}, config={"lr": tune.grid_search([0.001, 0.01])}),
        engine="ray",
        storage="./_test_data/tune",
        project="./test_project",
    )
def test_hidden_mixins():
    sys.path.insert(0, os.path.join(os.getcwd(), "test_project"))

    # hidden mixins that are only part of the imported project but not referenced in the project that imports them
    assert (
        ml.execute(
            ml.Experiment().components("inherited_mixin"), project="./test_project"
        ).failures
        == 0
    )
    assert (
        ml.execute(
            ml.Experiment().components("direct_mixin_inheritance"),
            project="./test_project",
        ).failures
        == 0
    )
def test_execution_resolvers():
    execution = execute(
        "@/test_project/_machinable/experiments",
        engine="@/test_project/_machinable/engines",
        project="./test_project",
    )
    assert (execution.experiment.specification["name"] ==
            "test_project._machinable.experiments")
def test_exception_handling():
    sys.path.insert(0, os.path.join(os.getcwd(), "test_project"))
    from test_project.failure.exceptions import ExceptionsComponent

    ex = ExceptionsComponent()
    status = ex.dispatch([], {"components": "12345"})
    assert isinstance(status, ml.core.exceptions.ExecutionException)

    ml.execute(
        ml.Experiment().components("failure.exceptions"), project="./test_project"
    )

    # a failure does not crash others
    import ray

    ray.init(ignore_reinit_error=True)
    ml.execute(
        ml.Experiment()
        .components("failure.exceptions")
        .components("thenode")
        .repeat(2),
        project="./test_project",
    )
Example #5
0
def test_project_code_backup(helpers):
    # create symlinks
    p = "./test_project/code_backup"
    os.makedirs(p + "/project/catch_me", exist_ok=True)
    with open(p + "/project/catch_me/if-you-can.txt", "w") as f:
        f.write("test")
    with open(p + "/extern/ignore_me.txt", "w") as f:
        f.write("please")
    try:
        os.symlink(
            os.path.abspath(p + "/project/catch_me"),
            p + "/project/link",
            target_is_directory=True,
        )
    except FileExistsError:
        pass
    try:
        os.symlink(
            os.path.abspath(p + "/extern"),
            p + "/project/external_link",
            target_is_directory=True,
        )
    except FileExistsError:
        pass

    # test backup
    helpers.tmp_directory("code_backup")
    target_file = "./_test_data/code_backup/code.zip"
    if os.path.isfile(target_file):
        os.remove(target_file)
    project = Project(p + "/project")
    # manual
    assert project.backup_source_code(target_file) is True
    archive = ZipFile(target_file)
    assert set(map(lambda f: f.filename, archive.filelist)) == {
        "machinable.yaml",
        "main.py",
        "dummy.py",
        "link/",
        "link/if-you-can.txt",
        "external_link/",
        "external_link/ignore_me.txt",
        "external_link/come-find-me.txt",
    }
    # during execution
    e = execute("dummy",
                storage="./_test_data/code_backup/symlinks",
                project=project)
    assert os.path.isfile(e.storage.get_local_directory("code.zip"))
Example #6
0
def pytest_sessionstart(session):
    if "DISABLE_STORAGE_GENERATION" in os.environ:
        return

    # setup storage test data
    path = Helpers.tmp_directory("storage")

    assert (ml.execute(
        ml.Experiment().components(("nodes.observations", {
            "id": 1
        })).repeat(3),
        path,
        project="./test_project",
    ).failures == 0)
    assert (ml.execute(
        ml.Experiment().components(("nodes.observations", {
            "id": 2
        }), "thechildren").repeat(2),
        path,
        project="./test_project",
    ).failures == 0)

    assert (ml.execute(
        ml.Experiment().components(("nodes.observations", {
            "id": 3,
            "test": True
        })).repeat(4),
        path,
        seed="tttttt",
        project="./test_project",
    ).failures == 0)

    # sub-experiments
    assert (ml.execute(
        ml.Experiment().component("nodes.observations"),
        {
            "url": os.path.join(path, "tttttt"),
            "directory": "subexperiment"
        },
        seed="SUBEXP",
        project="./test_project",
    ).failures == 0)
    assert (ml.execute(
        ml.Experiment().component("nodes.observations"),
        {
            "url": os.path.join(path, "tttttt"),
            "directory": "sub/test"
        },
        project="./test_project",
    ).failures == 0)

    assert (ml.execute(
        ml.Experiment().components(("nodes.observations", {
            "id": 4
        })),
        os.path.join(path, "subdirectory"),
        seed="TTTTTT",
        project="./test_project",
    ).failures == 0)

    assert (ml.execute(
        ml.Experiment().components(("nodes.observations", {
            "id": 4,
            "corrupt": True
        })),
        path,
        seed="corupt",
        project="./test_project",
    ).failures == 0)

    # corrupt some data
    shutil.rmtree(os.path.join(path, "corupt"), ignore_errors=True)
Example #7
0
def test_default_component():
    test_project = Project("./test_project")
    t = ml.Experiment().component("uses_default_module")
    ml.execute(t, project=test_project)
def test_interaction():
    ml.execute(
        ml.Experiment().components("thenode", "workers.interactive"),
        project="./test_project",
    )
def test_core_config_method():
    assert ml.execute("configmethods", project="./test_project").failures == 0
Example #10
0
def test_native_engine_multiprocessing():
    t = ml.Experiment().components("thenode", "thechildren").repeat(5)
    ml.execute(t, engine="native:1", project="./test_project")
    # failure
    t = ml.Experiment().components("failure.exceptions").repeat(5)
    ml.execute(t, engine="native:1", project="./test_project")
Example #11
0
def test_native_engine():
    t = ml.Experiment().components("thenode", "thechildren").repeat(2)
    ml.execute(t, engine=None, project="./test_project")
Example #12
0
from machinable import execute

execute("dummy", storage="../../../_test_data/code_backup/symlinks")
Example #13
0
def test_records_timing():
    assert (execute(Experiment().components("timings"),
                    project="./test_project").failures == 0)
Example #14
0
import machinable as ml

assert ml.execute("thenode").failures == 0