Parameters¶
Parameter sources define the space of configurations to explore. metalab supports grid search, random sampling, and manual parameter specification.
Grid Search¶
Define exhaustive combinations of parameter values.
metalab.grid ¶
GridSource: Cartesian product parameter generation.
Generates all combinations of the provided parameter values.
GridSource ¶
Parameter source that generates a Cartesian product of values.
Example:
source = GridSource(learning_rate=[0.01, 0.1], batch_size=[32, 64])
# Yields 4 cases: all combinations of learning_rate x batch_size
Initialize with parameter names mapped to lists of values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**kwargs
|
list[Any]
|
Parameter names mapped to lists of possible values. |
{}
|
__getitem__ ¶
Get parameter case by index without enumerating all cases.
Uses modular arithmetic to compute the combination for a given index. The ordering matches iter (sorted keys, Cartesian product order).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
index
|
int
|
The index of the parameter case (0-based). |
required |
Returns:
| Type | Description |
|---|---|
ParamCase
|
The ParamCase at the given index. |
Raises:
| Type | Description |
|---|---|
IndexError
|
If index is out of range. |
from_manifest_dict
classmethod
¶
Reconstruct GridSource from manifest dict.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
manifest
|
dict[str, Any]
|
Dict with "spec" containing parameter name -> values mapping. |
required |
Returns:
| Type | Description |
|---|---|
'GridSource'
|
A GridSource with the same configuration. |
to_manifest_dict ¶
Return a JSON-serializable dict representation for experiment manifests.
grid ¶
Create a GridSource for Cartesian product parameter generation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**kwargs
|
list[Any]
|
Parameter names mapped to lists of possible values. |
{}
|
Returns:
| Type | Description |
|---|---|
GridSource
|
A GridSource that yields all combinations. |
Example:
Random Search¶
Sample parameters from probability distributions.
metalab.random ¶
RandomSource: Replayable random parameter sampling.
Generates random parameter combinations using a seeded RNG, ensuring reproducibility.
Choice
dataclass
¶
Uniform choice from a list of options.
to_manifest_dict ¶
Return a JSON-serializable dict representation.
Distribution ¶
Bases: Protocol
Protocol for parameter distributions.
LogUniform
dataclass
¶
Log-uniform distribution over [low, high).
to_manifest_dict ¶
Return a JSON-serializable dict representation.
LogUniformInt
dataclass
¶
Log-uniform distribution over integers in [low, high].
to_manifest_dict ¶
Return a JSON-serializable dict representation.
RandInt
dataclass
¶
Uniform distribution over integers in [low, high].
to_manifest_dict ¶
Return a JSON-serializable dict representation.
RandomSource ¶
Parameter source that generates random samples.
Uses a seeded RNG for reproducibility. Given the same seed and space, always generates the same sequence of parameter cases.
Supports O(1) index-based access via getitem, where each index derives its own deterministic seed, enabling SLURM array submission without pre-generating all samples.
Initialize the random source.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
space
|
dict[str, Distribution]
|
Parameter names mapped to Distribution objects. |
required |
n_trials
|
int
|
Number of random samples to generate. |
required |
seed
|
int
|
Random seed for reproducibility. |
required |
__getitem__ ¶
Get parameter case by index in O(1) time.
Each index derives its own deterministic seed, so accessing source[i] always returns the same sample regardless of what other indices have been accessed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
index
|
int
|
The index of the parameter case (0-based). |
required |
Returns:
| Type | Description |
|---|---|
ParamCase
|
The ParamCase at the given index. |
Raises:
| Type | Description |
|---|---|
IndexError
|
If index is out of range. |
from_manifest_dict
classmethod
¶
Reconstruct RandomSource from manifest dict.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
manifest
|
dict[str, Any]
|
Dict with "space", "n_trials", and "seed" fields. |
required |
Returns:
| Type | Description |
|---|---|
'RandomSource'
|
A RandomSource with the same configuration. |
to_manifest_dict ¶
Return a JSON-serializable dict representation for experiment manifests.
Uniform
dataclass
¶
Uniform distribution over [low, high).
to_manifest_dict ¶
Return a JSON-serializable dict representation.
choice ¶
Create a uniform choice distribution from a list of options.
loguniform ¶
Create a log-uniform distribution over [low, high).
loguniform_int ¶
Create a log-uniform distribution over integers in [low, high].
randint ¶
Create a uniform distribution over integers in [low, high].
random ¶
Create a RandomSource for replayable random parameter sampling.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
space
|
dict[str, Distribution]
|
Parameter names mapped to Distribution objects. |
required |
n_trials
|
int
|
Number of random samples to generate. |
required |
seed
|
int
|
Random seed for reproducibility. |
required |
Returns:
| Type | Description |
|---|---|
RandomSource
|
A RandomSource that yields random parameter cases. |
uniform ¶
Create a uniform distribution over [low, high).
metalab.uniform ¶
Create a uniform distribution over [low, high).
metalab.loguniform ¶
Create a log-uniform distribution over [low, high).
metalab.choice ¶
Create a uniform choice distribution from a list of options.
Manual¶
Specify explicit parameter cases directly.
metalab.manual ¶
ManualSource: Explicit list of parameter cases.
For when you want to specify exact parameter combinations.
ManualSource ¶
Parameter source from an explicit list of parameter dictionaries.
Example:
source = ManualSource([
{"learning_rate": 0.01, "batch_size": 32},
{"learning_rate": 0.1, "batch_size": 64},
])
Initialize with a list of parameter dictionaries.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cases
|
list[dict[str, Any]]
|
List of parameter dictionaries. |
required |
tags
|
list[str] | None
|
Optional tags to apply to all cases. |
None
|
__getitem__ ¶
Get parameter case by index.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
index
|
int
|
The index of the parameter case (0-based, supports negative). |
required |
Returns:
| Type | Description |
|---|---|
ParamCase
|
The ParamCase at the given index. |
Raises:
| Type | Description |
|---|---|
IndexError
|
If index is out of range. |
from_manifest_dict
classmethod
¶
Reconstruct ManualSource from manifest dict.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
manifest
|
dict[str, Any]
|
Dict with "cases" list and optional "tags". |
required |
Returns:
| Type | Description |
|---|---|
'ManualSource'
|
A ManualSource with the same configuration. |
to_manifest_dict ¶
Return a JSON-serializable dict representation for experiment manifests.
manual ¶
Create a ManualSource from an explicit list of parameter dictionaries.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cases
|
list[dict[str, Any]]
|
List of parameter dictionaries. |
required |
tags
|
list[str] | None
|
Optional tags to apply to all cases. |
None
|
Returns:
| Type | Description |
|---|---|
ManualSource
|
A ManualSource that yields the specified cases. |
Example: