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
fromStudyNamestringName of the existing source study.
fromStorageBaseStorageStorage from which metadata and trials are read.
toStorageBaseStorageStorage in which the new study is created.
toStudyNamestringDestination 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
storageBaseStorageStorage object. If this argument is set to
null, InMemoryStorage is used, and the Study will not be persistent.samplerBaseSamplerA sampler object that implements background algorithm for value suggestion. If
nullis specified, TPESampler is used as the default.prunerBasePrunerA pruner object that decides early stopping of unpromising trials. If
nullis specified, MedianPruner is used as the default.studyNamestringStudy's name. If this argument is set to
null, a unique name is generated automatically.directionStudyDirection?Direction of optimization.
directionanddirectionsmust not be specified at the same time. If neither is specified, the direction is set to minimize.loadIfExistsboolFlag to control the behavior to handle a conflict of study names. In the case where a study named
studyNamealready exists in the storage, a DuplicatedStudyError is raised ifloadIfExistsis set tofalse. Otherwise, the creation of the study is skipped, and the existing one is returned.directionsIEnumerable<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
studyNamestringName identifying the study in the selected storage.
storageBaseStorageStorage 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
storageBaseStorageStorage backend holding study and trial records.
Returns
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
storageBaseStorageStorage object.
includeBestTrialboolInclude 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
studyNamestringStudy'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.storageBaseStorageStorage object (or use the OptunaSharp.Storage.* packages for URLs). The Study constructor wraps an RDB backend in a CachedStorage, as Python's
load_studydoes, so distributed workers that load a shared study read finished trials from the cache.samplerBaseSamplerSampler, defaulting to TPESampler.
prunerBasePrunerPruner, 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.