Skip to content

Log to multiple objects at once#

To log to multiple runs or other Neptune objects in one script, you can initialize multiple objects.

You can then log metadata to each object separately.

Why log to multiple runs at once?#

The most obvious case for working with multiple simultaneous runs would be when you want to log each hyperparameter optimization trial as a separate run. For an example of how to do this with Optuna, see the Optuna integration guide.

A more generic reason would be better organized metadata when logging parameters and results of different methods called in the script in different runs.

Example#

In the following example, we create and log metadata to three separate runs.

import neptune

# Start 1st run
run1 = neptune.init_run(
    project="common/quickstarts",
    name="logging-to-multipe-runs",
    tags=["multiple"],
)
run1["params"] = {"lr": 0.007}

# Start 2nd run
run2 = neptune.init_run(
    project="common/quickstarts",
    name="logging-to-multipe-runs",
    tags=["multiple"],
)
run2["params"] = {"lr": 0.0034}

# Start 3rd run
run3 = neptune.init_run(
    project="common/quickstarts",
    name="logging-to-multipe-runs",
    tags=["multiple"],
)
run3["params"] = {"lr": 0.005}

# Log metric to run1
for j in range(1, 101):
    run1["train/loss"].append(0.7 / j**0.5)

# Log metric to run2
for j in range(1, 101):
    run2["train/loss"].append(0.8 / j**0.5)

# Log metric to run3
for j in range(1, 101):
    run3["train/loss"].append(0.9 / j**0.5)

# Stop tracking
run1.stop()
run2.stop()
run3.stop()