Reference
HPO¶
Optuna-backed hyperparameter optimization: the run_hpo entry point, five
loss functions built for judging forecasts of (possibly chaotic) dynamics,
and helpers for inspecting finished studies.
Optional dependency
run_hpo and the study utilities require optuna
(pip install "resdag[hpo]"). The loss functions import without it.
hpo
¶
Hyperparameter Optimization¶
This module provides Optuna-based hyperparameter optimization for ESN models. It supports multiple loss functions specialized for time series forecasting and chaotic systems.
Installation
This module requires the optional optuna dependency::
pip install resdag[hpo]
or::
pip install optuna
| FUNCTION | DESCRIPTION |
|---|---|
run_hpo |
Run hyperparameter optimization study. |
get_loss |
Get a loss function by name. |
get_study_summary |
Generate summary of completed study. |
resolve_pruner |
Resolve a pruner key/instance to an :class: |
Pruners
Pass pruner= to :func:run_hpo to enable Optuna early stopping, fed by the
per-trial intermediate forecast-horizon reports. Registry keys (PRUNERS):
"asha": ASHA / SuccessiveHalvingPruner"hyperband": Hyperband pruner"median": Median pruner (recommended starting point)"threshold": Threshold pruner"none": NopPruner (no pruning, the default)
Loss Functions
The following loss functions are available:
"efh": Expected Forecast Horizon (default, recommended for chaotic systems)"forecast_horizon": Forecast Horizon Loss (contiguous valid steps)"lyapunov": Lyapunov-weighted Loss (exponential decay)"standard": Standard Loss (mean geometric mean error)"soft_horizon": Soft valid horizon (cumulative survival probability)
Examples:
Basic HPO workflow:
>>> from resdag.hpo import run_hpo, get_study_summary
>>> from resdag.models import ott_esn
>>>
>>> def model_creator(reservoir_size, spectral_radius):
... return ott_esn(
... reservoir_size=reservoir_size,
... feedback_size=3,
... output_size=3,
... spectral_radius=spectral_radius,
... )
>>>
>>> def search_space(trial):
... return {
... "reservoir_size": trial.suggest_int("reservoir_size", 100, 500, step=50),
... "spectral_radius": trial.suggest_float("spectral_radius", 0.5, 1.5),
... }
>>>
>>> def data_loader(trial):
... return {
... "warmup": warmup, "train": train, "target": target,
... "f_warmup": f_warmup, "val": val,
... }
>>>
>>> study = run_hpo(
... model_creator=model_creator,
... search_space=search_space,
... data_loader=data_loader,
... n_trials=50,
... )
>>> print(get_study_summary(study))
See Also
resdag.training.ESNTrainer : Training interface. resdag.utils.data : Data loading utilities.
run_hpo
¶
run_hpo(model_creator: Callable[..., ESNModel], search_space: Callable[[Trial], dict[str, Any]], data_loader: Callable[[Trial], dict[str, Any]], n_trials: int, loss: str | LossProtocol = 'efh', loss_params: dict[str, Any] | None = None, targets_key: str = 'output', drivers_keys: list[str] | None = None, monitor_losses: list[str | LossProtocol] | None = None, monitor_params: dict[str, dict[str, Any]] | None = None, study_name: str | None = None, storage: str | None = None, warm_start: list[dict[str, Any]] | None = None, transfer_from: Study | str | None = None, sampler: BaseSampler | None = None, pruner: str | BasePruner | None = None, seed: int | None = None, device: str | device | None = None, n_workers: int = 1, verbosity: int = 1, catch_exceptions: bool = True, penalty_value: float = 10000000000.0, clip_value: float | None = None, prune_on_clip: bool = False, horizon_key: str | None = None, n_checkpoints: int = 5, torch_scoring: bool = True, trial_callbacks: list[TrialCallback] | None = None) -> Study
Run an Optuna hyperparameter optimization study for ESN models.
This function provides a complete HPO pipeline that handles model creation, training, forecasting, and evaluation with robust error handling.
When n_workers > 1, optimization is parallelized using real OS processes
(not threads) that coordinate via shared file storage. By default, uses
Optuna's JournalFileStorage which is designed for multi-process
coordination. Pass a .db path or sqlite:/// URL to use SQLite
instead (with WAL mode for concurrency).
| PARAMETER | DESCRIPTION |
|---|---|
model_creator
|
Function that creates a fresh model for each trial. Must accept all
hyperparameters from |
search_space
|
Function that defines the hyperparameter search space. Uses Optuna's
|
data_loader
|
Function that loads and returns data. Must return a dictionary with:
|
n_trials
|
Total number of trials to run.
TYPE:
|
loss
|
Loss function to optimize. Can be:
TYPE:
|
loss_params
|
Additional keyword arguments for the loss function.
TYPE:
|
targets_key
|
Name of the readout layer for training targets.
TYPE:
|
drivers_keys
|
List of driver input keys in data dict for input-driven models. |
monitor_losses
|
Additional loss functions to compute and log (but not optimize on).
Can be loss names (e.g.,
TYPE:
|
monitor_params
|
Keyword arguments for each monitor loss. Keys are loss function names
(e.g., |
study_name
|
Name for the study. If
TYPE:
|
storage
|
Storage path or URL. Behaviour depends on the value:
TYPE:
|
warm_start
|
Known-good configurations to evaluate before any sampler-proposed
trial. Each dict maps parameter name to a fixed value and is enqueued
via :meth: |
transfer_from
|
A prior study (or a storage path/URL holding exactly one study) whose
TYPE:
|
sampler
|
Optuna sampler. Defaults to
TYPE:
|
pruner
|
Early-stopping policy fed by the per-trial intermediate
forecast-horizon reports. Accepts a registry key —
TYPE:
|
seed
|
Random seed for reproducibility. Seeds the Optuna sampler and, per
trial, PyTorch / NumPy / Python
TYPE:
|
device
|
Device to place models and data on (e.g., |
n_workers
|
Number of parallel workers. When
TYPE:
|
verbosity
|
Logging verbosity:
TYPE:
|
catch_exceptions
|
If
TYPE:
|
penalty_value
|
Value returned for failed trials.
TYPE:
|
clip_value
|
Upper bound for the objective value. When set and the raw loss
exceeds this threshold, the value returned to Optuna is clamped to
clip_value (or the trial is pruned, see prune_on_clip). The
unclipped value is always stored as the
TYPE:
|
prune_on_clip
|
If
TYPE:
|
horizon_key
|
Key in the
TYPE:
|
n_checkpoints
|
Number of growing forecast-horizon checkpoints at which each trial
reports an intermediate loss and the configured pruner is consulted.
The single forecast is sliced to each checkpoint (no repeated
forecasts), and reports are keyed by 1-based checkpoint index. Values
TYPE:
|
torch_scoring
|
If
TYPE:
|
trial_callbacks
|
Per-trial callbacks invoked after each successful evaluation. Each is
called as
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Study
|
The completed study with all trial results. |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If n_trials is not positive. |
TypeError
|
If model_creator, search_space, or data_loader are not callable. |
Examples:
Basic usage:
>>> from resdag.hpo import run_hpo
>>> from resdag.models import ott_esn
>>>
>>> def model_creator(reservoir_size, spectral_radius):
... return ott_esn(
... reservoir_size=reservoir_size,
... feedback_size=3,
... output_size=3,
... spectral_radius=spectral_radius,
... )
>>>
>>> def search_space(trial):
... return {
... "reservoir_size": trial.suggest_int("reservoir_size", 100, 500, step=50),
... "spectral_radius": trial.suggest_float("spectral_radius", 0.5, 1.5),
... }
>>>
>>> def data_loader(trial):
... # Load your data here
... return {
... "warmup": warmup, "train": train, "target": target,
... "f_warmup": f_warmup, "val": val,
... }
>>>
>>> study = run_hpo(
... model_creator=model_creator,
... search_space=search_space,
... data_loader=data_loader,
... n_trials=50,
... loss="efh",
... )
>>> print(f"Best params: {study.best_params}")
>>> print(f"Best value: {study.best_value}")
Parallel with 4 workers:
>>> study = run_hpo(
... model_creator=model_creator,
... search_space=search_space,
... data_loader=data_loader,
... n_trials=100,
... n_workers=4,
... storage="study.log",
... )
See Also
LOSSES : Available loss functions. get_study_summary : Generate study summary. ESNTrainer : Training interface.
Source code in src/resdag/hpo/run.py
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 | |
Reproducible studies¶
Pass seed= to run_hpo to make a study reproducible end to end. The seed is
applied in two places:
- The Optuna sampler — so the sequence of sampled hyperparameters is identical across runs.
- Each trial, where the per-trial seed
seed + trial.numberseeds PyTorch, NumPy, and Python'srandom, and is threaded into yourmodel_creator.
That last step is the one that matters for the reservoir. The recurrent
topology and the input/feedback initializers build their own RNGs
(np.random.default_rng(...) / torch.Generator) and do not read NumPy's
legacy global state — so seeding np.random alone leaves the reservoir weights
varying run-to-run. To close the gap, make your creator accept a seed keyword
and forward it to the reservoir (the premade factories forward **kwargs
straight to ESNLayer, which fixes the whole reservoir):
from resdag.models import ott_esn
def model_creator(reservoir_size, spectral_radius, seed=None):
# `seed` reaches ESNLayer/ESNCell, fixing the topology, the
# feedback/input initializers, and the random bias.
return ott_esn(
reservoir_size=reservoir_size,
feedback_size=3,
output_size=3,
spectral_radius=spectral_radius,
seed=seed,
)
study_a = run_hpo(model_creator, search_space, data_loader, n_trials=20, seed=42)
study_b = run_hpo(model_creator, search_space, data_loader, n_trials=20, seed=42)
assert study_a.best_value == study_b.best_value # identical
run_hpo only injects seed when model_creator declares a seed parameter
(or **kwargs); creators without one are called unchanged, and an explicit
seed returned by search_space always wins. Reproducibility is exact for
single-worker (n_workers=1) studies; with n_workers > 1, trial scheduling
across processes is non-deterministic, so the set of evaluated configurations is
reproducible but their order — and therefore best_value — may differ.
Pruning (early stopping)¶
Each trial forecasts once and is scored at a handful of growing
forecast-horizon checkpoints, reporting the prefix loss at every one. A diverging
configuration already shows a large loss at an early checkpoint — so an Optuna
pruner can terminate it before paying for the full horizon. Pass pruner= to
turn this on:
from resdag.hpo import run_hpo
study = run_hpo(
model_creator, search_space, data_loader,
n_trials=100,
pruner="median", # stop trials worse than the running median at each checkpoint
)
# Pruned trials are recorded but excluded from `best_value`:
print(get_study_summary(study)) # the summary lists the Pruned count
pruner accepts a registry key, a fully-configured
optuna.pruners.BasePruner
instance, or None:
| Key | Pruner | When to reach for it |
|---|---|---|
"none" (default) |
NopPruner |
No pruning. |
"median" |
MedianPruner |
Good default — prunes trials worse than the running median. |
"asha" |
SuccessiveHalvingPruner (ASHA) |
Aggressive, scales well with many parallel workers. |
"hyperband" |
HyperbandPruner |
ASHA across several budgets; strong when the right budget is unknown. |
"threshold" |
ThresholdPruner |
Prune on an absolute loss bound (default upper=1.0; pass a configured instance for a different bound). |
Need to tune a pruner's knobs? Build the instance and pass it in:
import optuna
study = run_hpo(
model_creator, search_space, data_loader, n_trials=100,
pruner=optuna.pruners.MedianPruner(n_startup_trials=5, n_warmup_steps=2),
)
Pruning is honored in both single- and multi-process (n_workers > 1) runs — the
resolved pruner is attached to every worker's study. It also composes with the
clip_value / prune_on_clip bound: the clip path prunes on the raw
loss exceeding a ceiling, while the pruner reacts to the intermediate horizon
reports; both can be active at once.
losses
¶
Loss functions for hyperparameter optimization.
This module provides specialized loss functions for evaluating multi-step
forecasts in reservoir computing applications. All functions operate on
batched predictions with shape (B, T, D) where B is batch size, T is
time steps, and D is the number of dimensions.
Available Losses
"efh": Expected Forecast Horizon (default, recommended for chaotic systems)"forecast_horizon": Forecast Horizon Loss (contiguous valid steps)"lyapunov": Lyapunov-weighted Loss (exponential decay for chaotic systems)"standard": Standard Loss (mean geometric mean error)"soft_horizon": Soft valid horizon (cumulative survival probability)
Scale conventions
The threshold-based horizon losses (:func:expected_forecast_horizon,
:func:forecast_horizon, :func:soft_valid_horizon) compare a per-timestep
error against a fixed threshold. For that comparison to be meaningful the
error metric must be scale-free, otherwise the same threshold collapses the
horizon to 0 or T depending on the absolute scale of the data. All of
these losses therefore default to metric="nrmse" (RMSE normalised by the
per-dimension standard deviation of y_true). Selecting a raw-scale metric
("rmse", "mse", "mae") for a threshold-based loss emits a
:class:UserWarning, because the threshold is then only valid on
unit-scale data.
Batch aggregation
Per-timestep errors of shape (B, T) are collapsed across the batch axis
with the median in every loss (see :func:_aggregate_batch). The median
is robust to outlier trajectories and — unlike the geometric mean — does not
collapse to 0 when a single batch element happens to be perfect at a step.
When a geometric mean is requested explicitly it is computed on
clipped errors so it is zero-safe.
Example
from resdag.hpo import LOSSES, get_loss loss_fn = get_loss("efh") loss = loss_fn(y_true, y_pred, threshold=0.2)
See Also
resdag.hpo.objective : Objective builder that wraps these losses for Optuna. resdag.hpo.run : High-level HPO orchestrator.
LOSSES
module-attribute
¶
LOSSES: dict[str, Callable[..., float]] = {'efh': expected_forecast_horizon, 'forecast_horizon': forecast_horizon, 'lyapunov': lyapunov_weighted, 'standard': standard_loss, 'soft_horizon': soft_valid_horizon}
LossProtocol
¶
Bases: Protocol
Protocol for HPO loss functions.
All loss functions must accept y_true and y_pred arrays of shape
(B, T, D) as positional-only arguments and return a single float
value to minimize.
Examples:
Implementing a custom loss:
get_loss
¶
get_loss(key_or_callable: str | LossProtocol) -> LossProtocol
Get a loss function by key or return the callable directly.
| PARAMETER | DESCRIPTION |
|---|---|
key_or_callable
|
Either a string key from LOSSES (e.g., "efh") or a custom callable following the LossProtocol interface. |
| RETURNS | DESCRIPTION |
|---|---|
LossProtocol
|
The loss function callable. |
| RAISES | DESCRIPTION |
|---|---|
KeyError
|
If the string key is not found in LOSSES. |
TypeError
|
If the provided callable doesn't match LossProtocol. |
Example
loss_fn = get_loss("efh") loss_fn = get_loss(my_custom_loss)
Source code in src/resdag/hpo/losses.py
expected_forecast_horizon
¶
expected_forecast_horizon(y_true: NDArray[floating], y_pred: NDArray[floating], /, metric: MetricType = 'nrmse', threshold: float = 0.2, softness: float = 0.04) -> float
Differentiable proxy for forecast horizon length.
This is the recommended loss for chaotic systems. It provides a smooth, differentiable approximation of the forecast horizon by using a soft threshold. The loss rewards models that keep errors below the threshold for as many consecutive steps as possible.
| PARAMETER | DESCRIPTION |
|---|---|
y_true
|
True values of shape (B, T, D).
TYPE:
|
y_pred
|
Predicted values of shape (B, T, D).
TYPE:
|
metric
|
Error metric to compute.
TYPE:
|
threshold
|
Error threshold below which predictions are considered "good".
TYPE:
|
softness
|
Controls the width of the soft threshold boundary. Smaller values create a harder threshold. Good default is ~10% of threshold.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
float
|
Negative expected forecast horizon. Lower (more negative) is better. |
| WARNS | DESCRIPTION |
|---|---|
UserWarning
|
If metric is not scale-free (i.e. not |
Source code in src/resdag/hpo/losses.py
forecast_horizon
¶
forecast_horizon(y_true: NDArray[floating], y_pred: NDArray[floating], /, metric: MetricType = 'nrmse', threshold: float = 0.2) -> float
Contiguous valid forecast horizon length.
Counts the number of consecutive time steps where the error stays below the threshold, starting from the beginning of the forecast.
| PARAMETER | DESCRIPTION |
|---|---|
y_true
|
True values of shape (B, T, D).
TYPE:
|
y_pred
|
Predicted values of shape (B, T, D).
TYPE:
|
metric
|
Error metric to compute. Defaults to the scale-free
TYPE:
|
threshold
|
Error threshold below which predictions are considered valid.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
float
|
Negative of the valid horizon length. Lower is better. |
| WARNS | DESCRIPTION |
|---|---|
UserWarning
|
If metric is not scale-free (i.e. not |
Source code in src/resdag/hpo/losses.py
lyapunov_weighted
¶
lyapunov_weighted(y_true: NDArray[floating], y_pred: NDArray[floating], /, metric: MetricType = 'nrmse', lyapunov_t: int = 64) -> float
Lyapunov-compensated time-weighted error.
Computes a time-weighted error where weights decay exponentially with characteristic time equal to the Lyapunov time. This compensates for expected exponential error growth in chaotic systems by applying a weight of exp(-t / lyapunov_t) at time step t.
At t = lyapunov_t, the weight equals exp(-1).
| PARAMETER | DESCRIPTION |
|---|---|
y_true
|
True values of shape (B, T, D).
TYPE:
|
y_pred
|
Predicted values of shape (B, T, D).
TYPE:
|
metric
|
Error metric to compute per time step. Defaults to the scale-free
TYPE:
|
lyapunov_t
|
Characteristic Lyapunov time (in time steps) controlling the exponential decay rate of the weights.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
float
|
Exponentially time-weighted average error. Lower is better. |
Notes
Errors are reduced across the batch with a zero-safe geometric mean
(clipped to a small positive floor; see :func:_aggregate_batch).
Source code in src/resdag/hpo/losses.py
standard_loss
¶
standard_loss(y_true: NDArray[floating], y_pred: NDArray[floating], /, metric: MetricType = 'nrmse') -> float
Mean geometric mean error across all timesteps.
Simple baseline loss suitable for both stable and unstable systems.
| PARAMETER | DESCRIPTION |
|---|---|
y_true
|
True values of shape (B, T, D).
TYPE:
|
y_pred
|
Predicted values of shape (B, T, D).
TYPE:
|
metric
|
Error metric to compute.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
float
|
Mean of geometric mean errors. Lower is better. |
Notes
The geometric mean across the batch is zero-safe: errors are clipped to a
small positive floor before reduction (see :func:_aggregate_batch) so a
single perfect batch element cannot collapse a step to 0.
Source code in src/resdag/hpo/losses.py
soft_valid_horizon
¶
soft_valid_horizon(y_true: NDArray[floating], y_pred: NDArray[floating], /, metric: MetricType = 'nrmse', threshold: float = 0.3, n: int = 6) -> float
Soft forecast horizon via cumulative survival probability.
At each timestep a soft indicator measures how "good" the prediction is using a Hill-function gate:
.. math::
g_t = \frac{1}{1 + (e_t / \theta)^n}
where :math:e_t is the median error at step t, :math:\theta is the
threshold, and n controls the sharpness. A cumulative product of these
indicators gives a survival probability that drops to zero once any step
fails, mimicking a contiguous forecast horizon:
.. math::
H = \sum_t \prod_{i \leq t} g_i
The function is numerically safe: error ratios are clipped before exponentiation to prevent overflow.
| PARAMETER | DESCRIPTION |
|---|---|
y_true
|
True values of shape (B, T, D).
TYPE:
|
y_pred
|
Predicted values of shape (B, T, D).
TYPE:
|
metric
|
Error metric to compute per timestep. Defaults to the scale-free
TYPE:
|
threshold
|
Error threshold below which predictions are considered "good".
TYPE:
|
n
|
Hill exponent controlling gate sharpness. Lower values (4-8) give smoother landscapes suitable for TPE optimisation; higher values (>12) approach a hard step function with poor gradient signal.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
float
|
Negative expected horizon. Lower (more negative) is better. |
| WARNS | DESCRIPTION |
|---|---|
UserWarning
|
If metric is not scale-free (i.e. not |
Notes
Compared to :func:expected_forecast_horizon (which uses a sigmoid gate
and batch-median), this loss uses a Hill-function gate and batch-median.
The Hill gate has a sharper but still tunable transition and is symmetric
around the threshold on a log-error scale.
See Also
expected_forecast_horizon : Sigmoid-gated variant with cumprod survival.
Source code in src/resdag/hpo/losses.py
396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 | |
utils
¶
Utility functions for hyperparameter optimization.
Provides helpers for study management, naming, and result summarization.
See Also
resdag.hpo.run : High-level HPO orchestrator that uses these utilities.
get_study_summary
¶
Generate a human-readable summary of an Optuna study.
Creates a formatted text summary including study statistics, best trial information, and top N trials.
| PARAMETER | DESCRIPTION |
|---|---|
study
|
The Optuna study to summarize.
TYPE:
|
top_n
|
Number of top-performing trials to include.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
Formatted multi-line summary string. |
Example
study = optuna.create_study()
... run optimization ...¶
print(get_study_summary(study))
Source code in src/resdag/hpo/utils.py
make_study_name
¶
Generate a stable study name from the model creator callable.
Creates a study name based on the callable's source file and name. It is robust to callables that lack the usual introspection metadata:
functools.partialobjects are unwrapped to their underlying function so the wrapped factory's name and source file are used (a barepartialraisesTypeErrorin :func:inspect.getsourcefile).- Callables without a usable
__name__(e.g. lambdas or callable class instances) fall back to their type name plus a short stable hash of theirrepr, so two logically-distinct creators do not collide onto the same study name and silently share persisted storage.
| PARAMETER | DESCRIPTION |
|---|---|
model_creator
|
The model creator callable to generate a name from. May be a plain
function, a :class:
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
Study name in the format |
Example
def my_model_creator(units): ... return model make_study_name(my_model_creator) 'script:my_model_creator'
Source code in src/resdag/hpo/utils.py
get_best_params
¶
get_best_params(study: Study) -> dict
Get the best parameters from a study.
Convenience function that returns the best trial's parameters.
| PARAMETER | DESCRIPTION |
|---|---|
study
|
The Optuna study.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict
|
Dictionary of best hyperparameters. |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If no completed trials exist. |