예제 #1
0
def test_set_experiment():
    with pytest.raises(TypeError):
        mlflow.set_experiment()

    with pytest.raises(Exception):
        mlflow.set_experiment(None)

    with pytest.raises(Exception):
        mlflow.set_experiment("")

    try:
        with TempDir() as tracking_uri:
            tracking.set_tracking_uri(tracking_uri.path())
            name = "random_exp"
            exp_id = mlflow.create_experiment(name)
            mlflow.set_experiment(name)
            run = start_run()
            assert run.info.experiment_id == exp_id
            end_run()

            another_name = "another_experiment"
            mlflow.set_experiment(another_name)
            exp_id2 = mlflow.tracking.MlflowClient().get_experiment_by_name(
                another_name)
            another_run = start_run()
            assert another_run.info.experiment_id == exp_id2.experiment_id
            end_run()
    finally:
        # Need to do this to clear active experiment to restore state
        mlflow.tracking.fluent._active_experiment_id = None
예제 #2
0
def test_start_and_end_run(tracking_uri_mock):
    # Use the start_run() and end_run() APIs without a `with` block, verify they work.
    active_run = start_run()
    mlflow.log_metric("name_1", 25)
    end_run()
    finished_run = tracking.MlflowClient().get_run(active_run.info.run_uuid)
    # Validate metrics
    assert len(finished_run.data.metrics) == 1
    assert finished_run.data.metrics["name_1"] == 25
예제 #3
0
def test_set_experiment_with_deleted_experiment_name(tracking_uri_mock):
    name = "dead_exp"
    mlflow.set_experiment(name)
    run = start_run()
    end_run()
    exp_id = run.info.experiment_id

    tracking.MlflowClient().delete_experiment(exp_id)

    with pytest.raises(MlflowException):
        mlflow.set_experiment(name)
예제 #4
0
def test_start_and_end_run(tracking_uri_mock):
    # Use the start_run() and end_run() APIs without a `with` block, verify they work.
    active_run = start_run()
    mlflow.log_metric("name_1", 25)
    end_run()
    finished_run = tracking.MlflowClient().get_run(active_run.info.run_uuid)
    # Validate metrics
    assert len(finished_run.data.metrics) == 1
    expected_pairs = {"name_1": 25}
    for metric in finished_run.data.metrics:
        assert expected_pairs[metric.key] == metric.value
예제 #5
0
def test_start_and_end_run():
    try:
        tracking.set_tracking_uri(tempfile.mkdtemp())
        # Use the start_run() and end_run() APIs without a `with` block, verify they work.
        active_run = start_run()
        mlflow.log_metric("name_1", 25)
        end_run()
        finished_run = tracking.get_service().get_run(active_run.info.run_uuid)
        # Validate metrics
        assert len(finished_run.data.metrics) == 1
        expected_pairs = {"name_1": 25}
        for metric in finished_run.data.metrics:
            assert expected_pairs[metric.key] == metric.value
    finally:
        tracking.set_tracking_uri(None)
예제 #6
0
def test_set_experiment(tracking_uri_mock, reset_active_experiment):
    with pytest.raises(TypeError):
        mlflow.set_experiment()

    with pytest.raises(Exception):
        mlflow.set_experiment(None)

    with pytest.raises(Exception):
        mlflow.set_experiment("")

    name = "random_exp"
    exp_id = mlflow.create_experiment(name)
    mlflow.set_experiment(name)
    run = start_run()
    assert run.info.experiment_id == exp_id
    end_run()

    another_name = "another_experiment"
    mlflow.set_experiment(another_name)
    exp_id2 = mlflow.tracking.MlflowClient().get_experiment_by_name(another_name)
    another_run = start_run()
    assert another_run.info.experiment_id == exp_id2.experiment_id
    end_run()