Exemplo n.º 1
0
def test_get_artifact_uri_appends_to_uri_path_component_correctly(
        artifact_location, expected_uri_format):
    client = MlflowClient()
    client.create_experiment("get-artifact-uri-test", artifact_location=artifact_location)
    mlflow.set_experiment("get-artifact-uri-test")
    with mlflow.start_run():
        run_id = mlflow.active_run().info.run_id
        for artifact_path in ["path/to/artifact", "/artifact/path", "arty.txt"]:
            artifact_uri = mlflow.get_artifact_uri(artifact_path)
            assert artifact_uri == tracking.artifact_utils.get_artifact_uri(run_id, artifact_path)
            assert artifact_uri == expected_uri_format.format(
                run_id=run_id, path=artifact_path.lstrip("/"))
Exemplo n.º 2
0
def set_experiment(experiment_name):
    """
    Set given experiment as active experiment. If experiment does not exist, create an experiment
    with provided name.

    :param experiment_name: Name of experiment to be activated.
    """
    client = MlflowClient()
    experiment = client.get_experiment_by_name(experiment_name)
    exp_id = experiment.experiment_id if experiment else None
    if exp_id is None:  # id can be 0
        print("INFO: '{}' does not exist. Creating a new experiment".format(experiment_name))
        exp_id = client.create_experiment(experiment_name)
    global _active_experiment_id
    _active_experiment_id = exp_id
Exemplo n.º 3
0
def set_experiment(experiment_name):
    """
    Set given experiment as active experiment. If experiment does not exist, create an experiment
    with provided name.

    :param experiment_name: Case sensitive name of an experiment to be activated.

    .. code-block:: python
        :caption: Example

        import mlflow

        # Set an experiment name, which must be unique and case sensitive.
        mlflow.set_experiment("Social NLP Experiments")

        # Get Experiment Details
        experiment = mlflow.get_experiment_by_name("Social NLP Experiments")

        # Print the contents of Experiment data
        print("Experiment_id: {}".format(experiment.experiment_id))
        print("Artifact Location: {}".format(experiment.artifact_location))
        print("Tags: {}".format(experiment.tags))
        print("Lifecycle_stage: {}".format(experiment.lifecycle_stage))

    .. code-block:: text
        :caption: Output

        Experiment_id: 1
        Artifact Location: file:///.../mlruns/1
        Tags: {}
        Lifecycle_stage: active
    """
    client = MlflowClient()
    experiment = client.get_experiment_by_name(experiment_name)
    exp_id = experiment.experiment_id if experiment else None
    if exp_id is None:  # id can be 0
        print("INFO: '{}' does not exist. Creating a new experiment".format(
            experiment_name))
        exp_id = client.create_experiment(experiment_name)
    elif experiment.lifecycle_stage == LifecycleStage.DELETED:
        raise MlflowException(
            "Cannot set a deleted experiment '%s' as the active experiment."
            " You can restore the experiment, or permanently delete the "
            " experiment to create a new one." % experiment.name)
    global _active_experiment_id
    _active_experiment_id = exp_id
Exemplo n.º 4
0
def set_experiment(experiment_name):
    """
    Set given experiment as active experiment. If experiment does not exist, create an experiment
    with provided name.

    :param experiment_name: Name of experiment to be activated.
    """
    client = MlflowClient()
    experiment = client.get_experiment_by_name(experiment_name)
    exp_id = experiment.experiment_id if experiment else None
    if exp_id is None:  # id can be 0
        print("INFO: '{}' does not exist. Creating a new experiment".format(experiment_name))
        exp_id = client.create_experiment(experiment_name)
    elif experiment.lifecycle_stage == LifecycleStage.DELETED:
        raise MlflowException(
            "Cannot set a deleted experiment '%s' as the active experiment."
            " You can restore the experiment, or permanently delete the "
            " experiment to create a new one." % experiment.name)
    global _active_experiment_id
    _active_experiment_id = exp_id
Exemplo n.º 5
0
import mlflow
from mlflow.tracking.client import MlflowClient

client = MlflowClient()
exp_name = "artifact_test_experiment"
if client.get_experiment_by_name(exp_name) is None:
    client.create_experiment(exp_name,
                             artifact_location="sqlite:///testartifactdb")
mlflow.set_experiment(exp_name)

fpath = "test.txt"
with open(fpath, "w") as f:
    f.write("TEST")

with mlflow.start_run():
    mlflow.log_artifact(fpath, "")
import mlflow
from mlflow.tracking.client import MlflowClient

client = MlflowClient()
exp_name = "artifact_test_experiment_sql"
if client.get_experiment_by_name(exp_name) is None:
    client.create_experiment(exp_name, artifact_location="mssql+pyodbc://sqluser:Mlflow2019@[email protected]:1433/mlflow_test?driver=ODBC+Driver+17+for+SQL+Server")
mlflow.set_experiment(exp_name)

fpath = "test.txt"
with open(fpath, "w") as f:
    f.write("TEST")

with mlflow.start_run():
    mlflow.log_artifact(fpath, "")
Exemplo n.º 7
0
from mlflow.tracking.client import MlflowClient

from datetime import datetime, timedelta
import math
import random

random.seed(42)
client = MlflowClient()

mock_experiment_file = f'/tmp/mock_experiment'
# Delete experiment if it already exists
if client.get_experiment_by_name(mock_experiment_file):
    client.delete_experiment(
        client.get_experiment_by_name(mock_experiment_file).experiment_id)
mock_experiment_id = client.create_experiment(mock_experiment_file)


def simulate_runs(dt, eid, mae, num_runs=1):
    '''
  Simulates a run(s) with a specified datetime, experiment, and mae.
  
  :param dt: Timestamp used for both run start_time and log_metric time.
  :param eid: Experiment id to log this run under.
  :param mae: Mean absolute error metric to log.
  :param num_runs: Number of runs to store.
  
  '''
    ts = int(dt.timestamp() * 1000)
    for _ in range(num_runs):
        run = client.create_run(experiment_id=eid, start_time=ts)