Table of Contents

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

maxRetry int?

The max number of times a trial can be retried. If null (default), retry indefinitely; if an integer, only retry that many times.

inheritIntermediateValues bool

Option to inherit trial.intermediate_values reported by Report(double, long) from the failed trial.

Methods

Invoke(Study, FrozenTrial)

Python call(study, trial).

public void Invoke(Study study, FrozenTrial trial)

Parameters

study Study

Study whose history and storage are used by the operation.

trial FrozenTrial

Trial 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

trial FrozenTrial

Trial 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

trial FrozenTrial

Trial record or active trial on which the operation acts.

Returns

List<int>

A new list of ancestor trial numbers in retry order; empty when absent.

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

callback RetryHeartbeatStaleTrialCallback

Callback instance to expose as a delegate.

Returns

Action<Study, FrozenTrial>

A delegate bound to Invoke on this callback.