deeplabcut.core.config.versioning
Configuration migration system for handling version upgrades and downgrades.
This module provides a versioned migration system that allows configurations to be upgraded from older versions to newer ones, or downgraded to older formats. Upgrade migrations are chained together, so any version can be upgraded to the latest by applying all intermediate migrations in sequence. Downgrade migrations can be registered for specific version pairs when backward compatibility is needed.
Functions:
| Name | Description |
|---|---|
get_config_version |
Extract the configuration version from a config dict. |
migrate_config |
Migrate a configuration to the target version. |
migrate_pose_v0_to_v1 |
Migrate PoseConfig from v0 to v1. |
migrate_pose_v1_to_v0 |
Migrate PoseConfig from v1 back to v0. |
migrate_project_v0_to_v1 |
Migrate ProjectConfig from unversioned/legacy (v0) to v1. |
migrate_project_v1_to_v0 |
Migrate ProjectConfig from v1 back to v0 (legacy format). |
register_migration |
Decorator to register a migration function for a specific config type. |
get_config_version
migrate_config
migrate_config(config: dict, config_type: str, target_version: int = CURRENT_CONFIG_VERSION) -> dict
Migrate a configuration to the target version.
Applies all necessary migrations in sequence to upgrade the config
from its current version to the target version. Only migrations registered
for config_type are applied.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
dict
|
Configuration dictionary to migrate. |
required |
|
str
|
Class name of the config being migrated (e.g. |
required |
|
int
|
Target version to migrate to (default: current). |
CURRENT_CONFIG_VERSION
|
Returns:
| Type | Description |
|---|---|
dict
|
Migrated configuration dictionary. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If migration chain is incomplete or target version is invalid. |
Source code in deeplabcut/core/config/versioning.py
migrate_pose_v0_to_v1
Migrate PoseConfig from v0 to v1.
migrate_pose_v1_to_v0
Migrate PoseConfig from v1 back to v0.
migrate_project_v0_to_v1
Migrate ProjectConfig from unversioned/legacy (v0) to v1.
Source code in deeplabcut/core/config/versioning.py
migrate_project_v1_to_v0
Migrate ProjectConfig from v1 back to v0 (legacy format).
Source code in deeplabcut/core/config/versioning.py
register_migration
Decorator to register a migration function for a specific config type.
Every migration must be scoped to a concrete DLCVersionedConfig subclass.
This keeps ProjectConfig and PoseConfig migration chains fully independent.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
int
|
The source version number (>= 0). |
required |
|
int
|
The target version number (>= 0, from_version ± 1 by convention). |
required |
|
str
|
Class name of the config this migration applies to (e.g.
|
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If version numbers are invalid or a migration for the same (config_type, from_version, to_version) triple is already registered. |
Example::
@register_migration(0, 1, config_type="ProjectConfig")
def migrate_project_v0_to_v1(config: dict) -> dict:
config["unique_bodyparts"] = config.pop("uniquebodyparts", [])
return config