View this notebook on GitHub or run it yourself on Binder!
Log with Multiple Backends#
rubicon-ml
allows users to instantiate Rubicon
objects with multiple backends to write to/read from. These backends include local, memory, and S3 repositories. Here’s a walk through of how one might instantiate and use a Rubicon
object with multiple backends.
[1]:
from rubicon_ml import Rubicon
[2]:
#rb = Rubicon(persistence="memory")
#or
#rb = Rubicon(persistence="filesystem")
However, when we want multiple backends we utilize the composite_config
kwarg:
[3]:
#example multiple backend instantiaiton
rb = Rubicon(composite_config=[
{"persistence": "filesystem", "root_dir": "./rubicon-root/rootA"},
{"persistence": "filesystem", "root_dir": "./rubicon-root/rootB"},
])
Write Commands#
The following commands write to all insantiated backend repositories:
[4]:
project = rb.create_project("example_project")
experiment = project.log_experiment("example_experiment")
artifact = experiment.log_artifact(data_bytes=b"bytes", name="example_artifact")
import pandas as pd
dataframe = experiment.log_dataframe(pd.DataFrame([[5, 0, 0], [0, 5, 1], [0, 0, 4]], columns=["x", "y", "z"]))
feature = experiment.log_feature("year")
metric = experiment.log_metric("accuracy", .8)
parameter = experiment.log_parameter("n_estimators")
Let’s verify both of our backends have been written to:
[5]:
!ls "./rubicon-root/rootA"
print("\n")
!ls "./rubicon-root/rootA/exampleproject"
print("\n")
!ls "./rubicon-root/rootA/exampleproject/experiments"
print("\n")
!ls "./rubicon-root/rootA/exampleproject/experiments/{experiment.id}"
print("\n")
!ls "./rubicon-root/rootA/exampleproject/experiments/{experiment.id}/artifacts"
print("\n")
!ls "./rubicon-root/rootA/exampleproject/experiments/{experiment.id}/dataframes"
print("\n")
!ls "./rubicon-root/rootA/exampleproject/experiments/{experiment.id}/features"
print("\n")
!ls "./rubicon-root/rootA/exampleproject/experiments/{experiment.id}/metrics"
print("\n")
!ls "./rubicon-root/rootA/exampleproject/experiments/{experiment.id}/parameters"
exampleproject
experiments metadata.json
8661b18a-afe3-4779-8ed4-e7d2a9aba244
artifacts features metrics
dataframes metadata.json parameters
e3b53858-ae06-4a11-996b-17b077821168
8cd7f032-3206-480b-948b-44d878f6bb56
year
accuracy
nestimators
[6]:
!ls "./rubicon-root/rootB"
print("\n")
!ls "./rubicon-root/rootB/exampleproject"
print("\n")
!ls "./rubicon-root/rootB/exampleproject/experiments"
print("\n")
!ls "./rubicon-root/rootB/exampleproject/experiments/{experiment.id}"
print("\n")
!ls "./rubicon-root/rootB/exampleproject/experiments/{experiment.id}/artifacts"
print("\n")
!ls "./rubicon-root/rootB/exampleproject/experiments/{experiment.id}/dataframes"
print("\n")
!ls "./rubicon-root/rootB/exampleproject/experiments/{experiment.id}/features"
print("\n")
!ls "./rubicon-root/rootB/exampleproject/experiments/{experiment.id}/metrics"
print("\n")
!ls "./rubicon-root/rootB/exampleproject/experiments/{experiment.id}/parameters"
exampleproject
experiments metadata.json
8661b18a-afe3-4779-8ed4-e7d2a9aba244
artifacts features metrics
dataframes metadata.json parameters
e3b53858-ae06-4a11-996b-17b077821168
8cd7f032-3206-480b-948b-44d878f6bb56
year
accuracy
nestimators
Read Commands#
Now that we’ve seen both of our backends have been written to, let’s see the read commands. Read commands will iterate over all backend repositories and return from the first one they are able to read from. A RubiconException
will be raised if none of the backend repositories can be read the requested item(s).
[7]:
projects = rb.projects()
print("projects: " + str(projects))
print("\n")
experiments = project.experiments()
print("experiments: " + str(experiments))
print("\n")
artifacts = experiment.artifacts()
print("artifacts: " + str(artifacts))
print("\n")
dataframes = experiment.dataframes()
print("dataframes: " + str(dataframes))
print("\n")
features = experiment.features()
print("features: " + str(features))
print("\n")
metrics = experiment.metrics()
print("metrics: " + str(metrics))
print("\n")
parameters = experiment.parameters()
print("parameters: " + str(parameters))
print("\n")
projects: [<rubicon_ml.client.project.Project object at 0x12782ba60>]
experiments: [<rubicon_ml.client.experiment.Experiment object at 0x12792ae60>]
artifacts: [<rubicon_ml.client.artifact.Artifact object at 0x12792ae90>]
dataframes: [<rubicon_ml.client.dataframe.Dataframe object at 0x1278f1b40>]
features: [<rubicon_ml.client.feature.Feature object at 0x127978130>]
metrics: [<rubicon_ml.client.metric.Metric object at 0x1279780a0>]
parameters: [<rubicon_ml.client.parameter.Parameter object at 0x127978310>]
Additional Read Commands#
Along with the commands demonstrated above, all other “read” type rubicon commands work the same way in that they will iterate over backend repositories and return from the first one they are able to read from. These include commands which read a specific logged object like get_project()
, experiment()
, artifact()
, dataframe()
, metric()
, and parameter()
.
Cleaning up local repository folders
[8]:
rm -rf rubicon-root/rootA
[9]:
rm -rf rubicon-root/rootB