示例#1
0
def get_tracking_uri():
    """Get the current tracking URI. This may not correspond to the tracking
    URI of the currently active run, since the tracking URI can be updated via
    ``set_tracking_uri``.

    :return: The tracking URI.
    """
    global _tracking_uri
    if _tracking_uri is not None:
        return _tracking_uri
    elif env.get_env(_TRACKING_URI_ENV_VAR) is not None:
        return env.get_env(_TRACKING_URI_ENV_VAR)
    else:
        return path_to_local_file_uri(
            os.path.abspath(DEFAULT_LOCAL_FILE_AND_ARTIFACT_PATH))
示例#2
0
def _get_experiment_id_from_env():
    """Summary.

    Returns:
        TYPE: Description
    """
    # experiment_name = env.get_env(_EXPERIMENT_NAME_ENV_VAR)
    # if experiment_name is not None:
    #     exp = MlflowClient().get_experiment_by_name(experiment_name)
    #     return exp.experiment_id if exp else None
    return env.get_env(_EXPERIMENT_ID_ENV_VAR)
示例#3
0
def start_run(run_name=None, nested=False):
    """Start a new MLflow run, setting it as the active run under which metrics
    and parameters will be logged. The return value can be used as a context
    manager within a ``with`` block; otherwise, you must call ``end_run()`` to
    terminate the current run.

    If you pass a ``run_id`` or the ``MLFLOW_RUN_ID`` environment variable is
    set, ``start_run`` attempts to resume a run with the specified run ID and
    other parameters are ignored. ``run_id`` takes precedence over
    ``MLFLOW_RUN_ID``.

    MLflow sets a variety of default tags on the run, as defined in
    :ref:`MLflow system tags <system_tags>`.


    Args:
        run_id: If specified, get the run with the specified UUID and log
            parameters and metrics under that run. The run's end time is unset
            and its status is set to running, but the run's other attributes
            (``source_version``, ``source_type``, etc.) are not changed.
        experiment_id: ID of the experiment under which to create the current
            run (applicable only when ``run_id`` is not specified). If
            ``experiment_id`` argument is unspecified, will look for valid
            experiment in the following order: activated using
            ``set_project``, ``MLFLOW_EXPERIMENT_NAME`` environment
            variable, ``MLFLOW_EXPERIMENT_ID`` environment variable,
            or the default experiment as defined by the tracking server.
        run_name: Name of new run (stored as a ``segmind_track.runName`` tag).
            Used only when ``run_id`` is unspecified.
        nested: Controls whether run is nested in parent run. ``True`` creates
            a nest run.

    Returns:
        :py:class:`segmind_track.ActiveRun`: object that acts as a context
            manager wrappings the run's state.


    Raises:
        Exception: Description
        MlflowException: Description
    """
    global _active_run_stack
    # back compat for int experiment_id

    experiment_id = str(_get_experiment_id())

    if _runid_exists():
        existing_run_id = env.get_env(_RUN_ID_ENV_VAR)
    else:
        existing_run_id = None
    if len(_active_run_stack) > 0 and not nested:
        raise Exception(
            ('Run with UUID {} is already active. To start a new run, first ' +
             'end the current run with segmind_track.end_run().' +
             ' To start a nested run, call start_run with nested=True').format(
                 _active_run_stack[0].info.run_id))

    if existing_run_id is not None:
        _validate_run_id(existing_run_id)
        active_run_obj = MlflowClient().get_run(existing_run_id)
        # Check to see if experiment_id from environment matches experiment_id
        # from set_project()
        if (_active_experiment_id is not None and
                _active_experiment_id != active_run_obj.info.experiment_id):
            raise MlflowException(
                'Cannot start run with ID {} because active run ID '
                'does not match environment run ID. Make sure '
                '--experiment-name or --experiment-id matches experiment '
                'set with set_project(), or just use command-line '
                'arguments'.format(existing_run_id))
        # Check to see if current run isn't deleted
        if active_run_obj.info.lifecycle_stage == LifecycleStage.DELETED:
            raise MlflowException(
                'Cannot start run with ID {} because it is in the '
                'deleted state.'.format(existing_run_id))

    else:
        if len(_active_run_stack) > 0:
            parent_run_id = _active_run_stack[-1].info.run_id
        else:
            parent_run_id = None

        exp_id_for_run = experiment_id

        user_specified_tags = {}
        if parent_run_id is not None:
            user_specified_tags[MLFLOW_PARENT_RUN_ID] = parent_run_id
        if run_name is not None:
            user_specified_tags[MLFLOW_RUN_NAME] = run_name

        tags = context_registry.resolve_tags(user_specified_tags)

        active_run_obj = MlflowClient().create_run(
            experiment_id=exp_id_for_run, tags=tags)

    _active_run_stack.append(ActiveRun(active_run_obj))
    return _active_run_stack[-1]
示例#4
0
def is_tracking_uri_set():
    """Returns True if the tracking URI has been set, False otherwise."""
    if _tracking_uri or env.get_env(_TRACKING_URI_ENV_VAR):
        return True
    return False
示例#5
0
def _get_run_id():
    return env.get_env(_RUN_ID_ENV_VAR)
示例#6
0
def _get_experiment_id():
    return env.get_env(_EXPERIMENT_ID_ENV_VAR)