strategies.SweepStrategy
strategies.SweepStrategy()Base class for sweep expansion strategies.
Strategies define how parameter combinations are generated: - Non-adaptive strategies (like CartesianStrategy) yield all combinations upfront - Adaptive strategies (like OptunaStrategy) generate combinations on-demand based on results from previous runs
Subclasses must implement: - is_adaptive property - expand() method (for non-adaptive) or indicate adaptive behavior - to_dict() and from_dict() for serialization
Attributes
| Name | Description |
|---|---|
| is_adaptive | True if strategy needs results before suggesting next params. |
Methods
| Name | Description |
|---|---|
| expand | Yield parameter combinations to try. |
| from_dict | Create from dict (YAML/JSON deserialization). |
| to_dict | Convert to dict for YAML/JSON serialization. |
expand
strategies.SweepStrategy.expand(
config_params,
file_params,
compound_params=None,
)Yield parameter combinations to try.
For non-adaptive strategies, yields all combinations upfront. For adaptive strategies, this raises an error - use run_adaptive_sweep() instead.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| config_params | list[ConfigSweepParameter] | Configuration parameters to sweep over. | required |
| file_params | list[FileSweepParameter] | File parameters to sweep over. | required |
| compound_params | list[CompoundSweepParameter] | None | Groups of parameters that should co-vary (zipped internally). | None |
Returns
| Name | Type | Description |
|---|---|---|
| Iterator[dict[str, Any]] | Iterator of dicts, each containing parameter values for one combination. | |
| Iterator[dict[str, Any]] | Config params: {“name”: value} | |
| Iterator[dict[str, Any]] | File params: {“name”: {“path”: Path, “label”: str}} | |
| Iterator[dict[str, Any]] | Compound params: {“group_name”: label, plus all inner param entries} |
from_dict
strategies.SweepStrategy.from_dict(data)Create from dict (YAML/JSON deserialization).
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| data | dict[str, Any] | Dict WITHOUT the “type” key (already consumed by strategy_from_dict). | required |
to_dict
strategies.SweepStrategy.to_dict()Convert to dict for YAML/JSON serialization.
Must include a “type” key for deserialization.