Class RetryHeartbeatStaleTrialCallback
- Namespace
- OptunaSharp.Storages
- Assembly
- OptunaSharp.dll
Retry a heartbeat-stale trial up to a maximum number of times.
Port of optuna/storages/_callbacks.py: RetryHeartbeatStaleTrialCallback
(experimental since 2.8.0).
When a running trial becomes stale due to the heartbeat mechanism, this callback can be used with a storage class to recreate the trial in Waiting to queue up the trial to be run again.
The original stale trial can be identified by RetriedTrialNumber(FrozenTrial). Even if repetitive failure occurs (a retried trial becomes stale again), this method returns the number of the original trial. To get a full list including the numbers of the retried trials as well as their original trial, call RetryHistory(FrozenTrial).
public class RetryHeartbeatStaleTrialCallback
- Inheritance
-
RetryHeartbeatStaleTrialCallback
- Derived
- Inherited Members
Constructors
RetryHeartbeatStaleTrialCallback(int?, bool)
Creates a policy for re-enqueuing heartbeat-stale trials.
public RetryHeartbeatStaleTrialCallback(int? maxRetry = null, bool inheritIntermediateValues = false)
Parameters
maxRetryint?The max number of times a trial can be retried. If
null(default), retry indefinitely; if an integer, only retry that many times.inheritIntermediateValuesboolOption to inherit
trial.intermediate_valuesreported by Report(double, long) from the failed trial.
Methods
Invoke(Study, FrozenTrial)
Python call(study, trial).
public void Invoke(Study study, FrozenTrial trial)
Parameters
studyStudyStudy whose history and storage are used by the operation.
trialFrozenTrialTrial record or active trial on which the operation acts.
Exceptions
- InvalidCastException
Reserved retry metadata does not contain the expected list.
- ValueError
The copied trial parameters or distributions fail validation.
RetriedTrialNumber(FrozenTrial)
Return the number of the original trial being retried, or null if the trial is
not a retry of a previous trial. (Experimental since 2.8.0.)
public static int? RetriedTrialNumber(FrozenTrial trial)
Parameters
trialFrozenTrialTrial record or active trial on which the operation acts.
Returns
- int?
The original failed trial number, or null if no retry marker is recorded.
Exceptions
- FormatException
The retry marker cannot be parsed as an integer.
- OverflowException
The retry marker exceeds Int32.
- InvalidCastException
The retry marker is not convertible to an integer.
RetryHistory(FrozenTrial)
Return the list of retried trial numbers with respect to the specified trial, in ascending order of the series of retried trials; empty if the trial is not a retry. (Experimental since 3.0.0.)
public static List<int> RetryHistory(FrozenTrial trial)
Parameters
trialFrozenTrialTrial record or active trial on which the operation acts.
Returns
Operators
implicit operator Action<Study, FrozenTrial>(RetryHeartbeatStaleTrialCallback)
Allows passing the callback where an Action<T1, T2> is expected.
public static implicit operator Action<Study, FrozenTrial>(RetryHeartbeatStaleTrialCallback callback)
Parameters
callbackRetryHeartbeatStaleTrialCallbackCallback instance to expose as a delegate.
Returns
- Action<Study, FrozenTrial>
A delegate bound to Invoke on this callback.