Context Specs¶
Context specs declare the data dependencies for an experiment. They provide a serializable manifest of file paths and configurations that operations can use to load their inputs.
metalab.context_spec ¶
Decorator that creates a frozen dataclass with automatic fingerprinting.
This decorator:
1. Applies @dataclass(frozen=True) to the class (unless frozen=False)
2. Adds a fingerprint property that computes a stable hash of all fields
The fingerprint is computed lazily on first access and cached.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cls
|
type[T] | None
|
The class to decorate (when used without parentheses). |
None
|
frozen
|
bool
|
Whether to make the dataclass frozen (default: True). |
True
|
Returns:
| Type | Description |
|---|---|
type[T] | Any
|
The decorated class. |
Example:
metalab.FilePath
dataclass
¶
A file path marker that implements Fingerprintable.
The hash is computed lazily at fingerprint time using file metadata (size, mtime, inode) for O(1) performance regardless of file size.
When used in a context spec, the fingerprint will include the metadata hash, ensuring runs are deduplicated based on file identity.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Path to the file. |
required |
hash_path
|
bool
|
If True, include the path in the fingerprint (default: False). When False, only file metadata is used - same file at different paths produces the same fingerprint. |
False
|
Example:
metalab.DirPath
dataclass
¶
A directory path marker that implements Fingerprintable.
The hash is computed lazily at fingerprint time using file metadata (size, mtime, inode) for O(1) performance per file.
When used in a context spec, the fingerprint will include the aggregated metadata hash of all matching files.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Path to the directory. |
required |
pattern
|
str
|
Glob pattern for files to include (default: "*"). |
'*'
|
hash_path
|
bool
|
If True, include the path in the fingerprint (default: False). |
False
|
Example: