dew.config.sweep
Search hyperparameters over the ordinary training path.
A sweep overrides a RunConfig through its own record, hands each trial to
the recipe’s train entry point, and records the score that entry point
returns. Trials land in a JSON ledger before they are reported, so an
interrupted sweep resumes at the trial it stopped on instead of retraining
the finished ones. random_search and grid_search need nothing beyond
numpy; optuna_search asks Optuna’s sampler for the next point and tells it
the ledger’s trials, and needs dew-ml[hpo].
| Name | Summary |
|---|---|
Choice | One candidate value for a swept field: what JSON and Optuna both hold. |
Space | Dotted paths into a run record, each with the values a trial draws from. |
Point | |
C | |
Search | Chooses the next point of a space, given the trials already finished. |
override | Return config with each dotted path in point replaced, through its record. |
random_search | Draw one independent value per field, reproducible from the trial’s number. |
grid_search | Return the next point of the space’s cartesian product, in order. |
optuna_search | Ask Optuna’s sampler for the next point over the same space. |
sweep | Train trials trials of config over space and return the ledger. |
Choice
Section titled “Choice”One candidate value for a swept field: what JSON and Optuna both hold.
Dotted paths into a run record, each with the values a trial draws from.
C = TypeVar('C', bound=RunConfig)Search
Section titled “Search”class Search(Protocol)Chooses the next point of a space, given the trials already finished.
seed is read by the samplers that draw at random, random_search and
optuna_search; grid_search walks the product in order and ignores it.
override
Section titled “override”def override(config: C, point: Point) -> CReturn config with each dotted path in point replaced, through its record.
RunConfig.from_dict refuses a leaf the class does not declare, so a
misspelled path raises instead of training the unchanged config.
random_search
Section titled “random_search”def random_search(space: Space, finished: Sequence[TrialFinished], seed: int) -> PointDraw one independent value per field, reproducible from the trial’s number.
grid_search
Section titled “grid_search”def grid_search(space: Space, finished: Sequence[TrialFinished], seed: int) -> PointReturn the next point of the space’s cartesian product, in order.
seed is the Search protocol’s, and this walk draws nothing, so it goes
unread here.
optuna_search
Section titled “optuna_search”def optuna_search(space: Space, finished: Sequence[TrialFinished], seed: int) -> PointAsk Optuna’s sampler for the next point over the same space.
The study is built from the ledger on every call rather than kept across them, so a resumed sweep asks from the same trials a fresh one would.
def sweep( config: C, space: Space, *, train: Callable[[C], float], trials: int, ledger: str | Path, tracker: Tracker, search: Search = random_search, seed: int = 0,) -> list[TrialFinished]Train trials trials of config over space and return the ledger.
Each trial draws a point from space, trains under the run name
<trainer.name>/trial-<index> so trials keep their own checkpoints and
tracking, and records the score train returns for it. tracker
receives that score as sweep/value at the trial’s number and the
trial’s TrialFinished record. A trial reaches ledger before it is
reported, so rerunning the same call continues an interrupted sweep.