optuna.storages.RetryFailedTrialCallback¶
-
class
optuna.storages.
RetryFailedTrialCallback
(max_retry=None)[source]¶ Retry a failed trial up to a maximum number of times.
When a trial fails, this callback can be used with the
optuna.storage
class to recreate the trial inTrialState.WAITING
to queue up the trial to be run again.This is helpful in environments where trials may fail due to external conditions, such as being preempted by other processes.
Usage:
import optuna from optuna.storages import RetryFailedTrialCallback storage = optuna.storages.RDBStorage( url="sqlite:///:memory:", heartbeat_interval=60, grace_period=120, failed_trial_callback=RetryFailedTrialCallback(max_retry=3), ) study = optuna.create_study( storage=storage, )
- Parameters
max_retry – The max number of times a trial can be retried. Must be set to
None
or an integer. If set to the default value ofNone
will retry indefinitely. If set to an integer, will only retry that many times.
Note
Added in v2.8.0 as an experimental feature. The interface may change in newer versions without prior notice. See https://github.com/optuna/optuna/releases/tag/v2.8.0.
Methods
retried_trial_number
(trial)Return the number of the trial being retried.
-
static
retried_trial_number
(trial)[source]¶ Return the number of the trial being retried.
- Parameters
trial (optuna.trial._frozen.FrozenTrial) – The trial object.
- Returns
The number of the first failed trial. If not retry of a previous trial, returns
None
.- Return type
Optional[int]
Note
Added in v2.8.0 as an experimental feature. The interface may change in newer versions without prior notice. See https://github.com/optuna/optuna/releases/tag/v2.8.0.