Table of Contents

Class TrialPruned

Namespace
OptunaSharp
Assembly
OptunaSharp.dll

Exception for pruned trials.

This error tells a trainer that the current Trial was pruned. It is supposed to be raised after ShouldPrune() as shown in the following example.

public class TrialPruned : OptunaError, ISerializable
Inheritance
TrialPruned
Implements
Inherited Members

Examples

for (int step = 0; step < nTrainIter; step++)
{
    // ... partial fit ...
    trial.Report(intermediateValue, step);
    if (trial.ShouldPrune())
        throw new TrialPruned();
}

Constructors

TrialPruned()

Creates a TrialPruned with an empty Message, as Python's str(TrialPruned()) is ''.

public TrialPruned()

Remarks

The message is not cosmetic: Optimize logs every pruned trial as "Trial {number} pruned. {message}", the port of Optuna's f"... pruned. {str(func_err)}". Left to the BCL default, the bare throw new TrialPruned(); every prune loop ends with would log Exception of type 'OptunaSharp.TrialPruned' was thrown. on each pruned trial where Optuna logs nothing after the period.

TrialPruned(string)

Creates a TrialPruned carrying the supplied failure details, if any.

public TrialPruned(string message)

Parameters

message string

Error message explaining the failure.