Esempio n. 1
0
def test_load_docker_project(tmpdir):
    tmpdir.join("MLproject").write(
        textwrap.dedent("""
    docker_env:
        image: some-image
    """))
    project = _project_spec.load_project(tmpdir.strpath)
    assert project._entry_points == {}
    assert project.conda_env_path is None
    assert project.docker_env.get("image") == "some-image"
Esempio n. 2
0
def test_load_project(tmpdir, mlproject, conda_env_path, conda_env_contents,
                      mlproject_path):
    """
    Test that we can load a project with various combinations of an MLproject / conda.yaml file
    :param mlproject: Contents of MLproject file. If None, no MLproject file will be written
    :param conda_env_path: Path to conda environment file. If None, no conda environment file will
                           be written.
    :param conda_env_contents: Contents of conda environment file (written if conda_env_path is
                               not None)
    """
    if mlproject:
        tmpdir.join(mlproject_path).write(mlproject)
    if conda_env_path:
        tmpdir.join(conda_env_path).write(conda_env_contents)
    project = _project_spec.load_project(tmpdir.strpath)
    assert project._entry_points == {}
    expected_env_path = \
        os.path.abspath(os.path.join(tmpdir.strpath, conda_env_path)) if conda_env_path else None
    assert project.conda_env_path == expected_env_path
    if conda_env_path:
        assert open(project.conda_env_path).read() == conda_env_contents
Esempio n. 3
0
def test_load_invalid_project(tmpdir, invalid_project_contents,
                              expected_error_msg):
    tmpdir.join("MLproject").write(invalid_project_contents)
    with pytest.raises(ExecutionException) as e:
        _project_spec.load_project(tmpdir.strpath)
    assert expected_error_msg in str(e.value)
Esempio n. 4
0
def _create_run(uri, experiment_id, work_dir, version, entry_point,
                parameters):
    """
    Create a ``Run`` against the current MLflow tracking server, logging metadata (e.g. the URI,
    entry point, and parameters of the project) about the run. Return an ``ActiveRun`` that can be
    used to report additional data about the run (metrics/params) to the tracking server.
    """
    if _is_local_uri(uri):
        source_name = tracking._tracking_service.utils._get_git_url_if_present(
            _expand_uri(uri))
    else:
        source_name = _expand_uri(uri)
    source_version = _get_git_commit(work_dir)
    git_diff = _get_git_diff(work_dir)
    existing_run = fluent.active_run()
    if existing_run:
        parent_run_id = existing_run.info.run_id
    else:
        parent_run_id = None

    tags = {
        MLFLOW_USER: _get_user(),
        MLFLOW_SOURCE_NAME: source_name,
        MLFLOW_SOURCE_TYPE: SourceType.to_string(SourceType.PROJECT),
        MLFLOW_PROJECT_ENTRY_POINT: entry_point
    }

    # System tags - all include a string header, thus none of them is empty
    tags[KIWI_SYSTEM_HW_CPU] = _get_cpu_info()
    tags[KIWI_SYSTEM_HW_MEMORY] = _get_mem_info()
    tags[KIWI_SYSTEM_HW_DISK] = _get_disk_info()
    tags[KIWI_SYSTEM_HW_GPU] = _get_gpu_info()
    tags[KIWI_SYSTEM_OS] = _get_os_info()

    if source_version is not None:
        tags[MLFLOW_GIT_COMMIT] = source_version
        tags[MLFLOW_GIT_DIFF] = git_diff
    if parent_run_id is not None:
        tags[MLFLOW_PARENT_RUN_ID] = parent_run_id

    repo_url = _get_git_repo_url(work_dir)
    if repo_url is not None:
        tags[MLFLOW_GIT_REPO_URL] = repo_url
        tags[LEGACY_MLFLOW_GIT_REPO_URL] = repo_url

    # Add branch name tag if a branch is specified through -version
    if _is_valid_branch_name(work_dir, version):
        tags[MLFLOW_GIT_BRANCH] = version
        tags[LEGACY_MLFLOW_GIT_BRANCH_NAME] = version
    active_run = tracking.MlflowClient().create_run(
        experiment_id=experiment_id, tags=tags)

    project = _project_spec.load_project(work_dir)
    # Consolidate parameters for logging.
    # `storage_dir` is `None` since we want to log actual path not downloaded local path
    entry_point_obj = project.get_entry_point(entry_point)
    final_params, extra_params = entry_point_obj.compute_parameters(
        parameters, storage_dir=None)
    params_list = [
        Param(key, value) for key, value in list(final_params.items()) +
        list(extra_params.items())
    ]
    tracking.MlflowClient().log_batch(active_run.info.run_id,
                                      params=params_list)
    return active_run
Esempio n. 5
0
def load_project():
    """ Loads an example project for use in tests, returning an in-memory `Project` object. """
    return _project_spec.load_project(TEST_PROJECT_DIR)
Esempio n. 6
0
def load_project(work_dir):
    return _project_spec.load_project(work_dir)
Esempio n. 7
0
def fetch_and_validate_project(uri, version, entry_point, parameters):
    parameters = parameters or {}
    work_dir = _fetch_project(uri=uri, version=version)
    project = _project_spec.load_project(work_dir)
    project.get_entry_point(entry_point)._validate_parameters(parameters)
    return work_dir
Esempio n. 8
0
def test_docker_invalid_project_backend_local():
    work_dir = "./examples/docker"
    project = _project_spec.load_project(work_dir)
    project.name = None
    with pytest.raises(ExecutionException):
        kiwi.projects._validate_docker_env(project)
Esempio n. 9
0
def test_docker_valid_project_backend_local():
    work_dir = "./examples/docker"
    project = _project_spec.load_project(work_dir)
    kiwi.projects._validate_docker_env(project)
Esempio n. 10
0
def load_project():
    return _project_spec.load_project(directory=TEST_PROJECT_DIR)