Table of Contents

Class Optuna

Namespace
OptunaSharp
Assembly
OptunaSharp.dll

The top-level Optuna API surface: ports of the module-level functions re-exported by optuna/init.py (create_study, load_study, delete_study, copy_study, get_all_study_summaries, get_all_study_names).

public static class Optuna
Inheritance
Optuna
Inherited Members

Methods

CopyStudy(string, BaseStorage, BaseStorage, string?)

Copy study from one storage to another. Port of optuna.copy_study.

The direction(s) of the objective(s) in the study, trials, user attributes and system attributes are copied.

public static void CopyStudy(string fromStudyName, BaseStorage fromStorage, BaseStorage toStorage, string? toStudyName = null)

Parameters

fromStudyName string

Name of the existing source study.

fromStorage BaseStorage

Storage from which metadata and trials are read.

toStorage BaseStorage

Storage in which the new study is created.

toStudyName string

Destination name; null reuses the source name.

Remarks

The copy is incremental. A failure can leave the destination study with only part of its metadata or trials.

Exceptions

DuplicatedStudyError

If a study with a conflicting name already exists in the destination storage.

KeyError

The source study is absent.

ValueError

A copied trial has an objective count incompatible with the study.

CreateStudy(BaseStorage?, BaseSampler?, BasePruner?, string?, StudyDirection?, bool, IEnumerable<StudyDirection>?)

Create a new Study. Port of optuna.create_study.

public static Study CreateStudy(BaseStorage? storage = null, BaseSampler? sampler = null, BasePruner? pruner = null, string? studyName = null, StudyDirection? direction = null, bool loadIfExists = false, IEnumerable<StudyDirection>? directions = null)

Parameters

storage BaseStorage

Storage object. If this argument is set to null, InMemoryStorage is used, and the Study will not be persistent.

sampler BaseSampler

A sampler object that implements background algorithm for value suggestion. If null is specified, TPESampler is used as the default.

pruner BasePruner

A pruner object that decides early stopping of unpromising trials. If null is specified, MedianPruner is used as the default.

studyName string

Study's name. If this argument is set to null, a unique name is generated automatically.

direction StudyDirection?

Direction of optimization. direction and directions must not be specified at the same time. If neither is specified, the direction is set to minimize.

loadIfExists bool

Flag to control the behavior to handle a conflict of study names. In the case where a study named studyName already exists in the storage, a DuplicatedStudyError is raised if loadIfExists is set to false. Otherwise, the creation of the study is skipped, and the existing one is returned.

directions IEnumerable<StudyDirection>

A sequence of directions during multi-objective optimization.

Returns

Study

A study bound to the resolved storage, using the requested sampler and pruner.

Exceptions

ValueError

Both direction forms are supplied, the directions sequence is empty, or a direction is neither Minimize nor Maximize.

DeleteStudy(string, BaseStorage)

Delete a Study object. Port of optuna.delete_study.

public static void DeleteStudy(string studyName, BaseStorage storage)

Parameters

studyName string

Name identifying the study in the selected storage.

storage BaseStorage

Storage backend holding study and trial records.

Exceptions

KeyError

The named study does not exist.

GetAllStudyNames(BaseStorage)

Get all study names stored in a specified storage. Port of optuna.get_all_study_names.

public static List<string> GetAllStudyNames(BaseStorage storage)

Parameters

storage BaseStorage

Storage backend holding study and trial records.

Returns

List<string>

Names of all studies in the order returned by the storage backend.

GetAllStudySummaries(BaseStorage, bool)

Get all history of studies stored in a specified storage. Port of optuna.get_all_study_summaries.

public static List<StudySummary> GetAllStudySummaries(BaseStorage storage, bool includeBestTrial = true)

Parameters

storage BaseStorage

Storage object.

includeBestTrial bool

Include the best trials if exist. It potentially increases the number of queries and may take longer to fetch summaries depending on the storage.

Returns

List<StudySummary>

Summaries in storage order, including counts and optional single-objective best trials.

LoadStudy(string?, BaseStorage, BaseSampler?, BasePruner?)

Load the existing Study that has the specified name. Port of optuna.load_study.

public static Study LoadStudy(string? studyName, BaseStorage storage, BaseSampler? sampler = null, BasePruner? pruner = null)

Parameters

studyName string

Study's name. Each study has a unique name as an identifier. If null, checks whether the storage contains a single study, and if so loads that study.

storage BaseStorage

Storage object (or use the OptunaSharp.Storage.* packages for URLs). The Study constructor wraps an RDB backend in a CachedStorage, as Python's load_study does, so distributed workers that load a shared study read finished trials from the cache.

sampler BaseSampler

Sampler, defaulting to TPESampler.

pruner BasePruner

Pruner, defaulting to MedianPruner.

Returns

Study

The existing study with this invocation's sampler and pruner.

Exceptions

ValueError

The name is omitted and storage does not contain exactly one study.

KeyError

The named study does not exist.