Skip to content

Set custom run ID#

When working with pipelines or multiple scripts, you may need to access the same run in multiple places. You can achieve this by specifying a custom identifier for the run. When you use the same ID for different run instances, you ensure that all metadata is logged to the same run.

To automatically make the ID unique for each new run, you may wish to compose it from components such as hash and time.

Good to know

  • The maximum length of the ID is 36 characters.
  • The custom ID is stored in the system namespace (sys/custom_run_id) field of the run.
  • It's not possible to use a custom run ID in offline mode.

Setting custom ID through environment variable#

When a run is initialized, Neptune automatically picks up the custom ID from the environment variable NEPTUNE_CUSTOM_RUN_ID.

To ensure a unique ID for every run, you can use the following example:

export NEPTUNE_CUSTOM_RUN_ID=`date +"%Y%m%d%H%M%s%N" | md5sum`
export NEPTUNE_CUSTOM_RUN_ID=`date +"%Y%m%d%H%M%s%N" | md5`
set NEPTUNE_CUSTOM_RUN_ID=`date +"%Y%m%d%H%M%s%N"`

Setting custom ID through init_run() argument#

You can set the ID through the custom_run_id argument of the init_run() function when initializing the run.

To ensure a unique ID for every run, you can use the following example:

Example
import hashlib
import time

run = neptune.init_run(
    custom_run_id=hashlib.md5(str(time.time()).encode()).hexdigest(),
)

Resuming a run with a custom ID#

If you supply a custom run ID that already exists, Neptune resumes that run instead of creating a new one.

If you're not using the NEPTUNE_CUSTOM_RUN_ID environment variable, you can pass the ID to the custom_run_id argument at initialization:

run = neptune.init_run(
    # Run with custom ID "astute-barracuda" already exists
    custom_run_id="astute-barracuda",
)

run["new_field"] = some_new_value  # You can add new fields

run["metric"].append(new_value)  # If the field exists, you can append more values

run["existing_field"].assign(something_of_a_different_type)
# Error: You need to overwrite the field more deliberately, by deleting it first

For details, see Resume a run.