OptunaSharp 1.1.0
dotnet add package OptunaSharp --version 1.1.0
NuGet\Install-Package OptunaSharp -Version 1.1.0
<PackageReference Include="OptunaSharp" Version="1.1.0" />
<PackageVersion Include="OptunaSharp" Version="1.1.0" />
<PackageReference Include="OptunaSharp" />
paket add OptunaSharp --version 1.1.0
#r "nuget: OptunaSharp, 1.1.0"
#:package OptunaSharp@1.1.0
#addin nuget:?package=OptunaSharp&version=1.1.0
#tool nuget:?package=OptunaSharp&version=1.1.0
OptunaSharp
Optuna for .NET: a C#/F# port of Optuna, the define-by-run hyperparameter optimization framework, built on NumSharp.
Install
dotnet add package OptunaSharp
The package targets .NET 8 and .NET 10. It needs dynamic code: NumSharp compiles its kernels at run time, so
OptunaSharp does not run under NativeAOT. A .NET 10 file-based app turns NativeAOT on by default, so declare
#:property PublishAot=false next to #:package OptunaSharp@*; without it the first trial fails with
PlatformNotSupportedException: Dynamic code generation is not supported on this platform.
Quick start
using OptunaSharp;
var study = Optuna.CreateStudy(direction: StudyDirection.Minimize);
study.Optimize(trial =>
{
double x = trial.SuggestFloat("x", -10, 10);
return (x - 2) * (x - 2);
}, nTrials: 100);
Console.WriteLine(study.BestValue); // ~0
Console.WriteLine(study.BestParams["x"]); // ~2
What this package contains
- Studies and trials:
Optuna.CreateStudy/LoadStudy,Optimize, ask-and-tell, multi-objective directions, constraints, user and system attributes, callbacks. - Distributions and search spaces: float, int and categorical distributions, plus search-space inference for dynamic (define-by-run) spaces.
- Samplers: TPE, CMA-ES, GP, Random, Grid, QMC, BruteForce, PartialFixed, NSGA-II and NSGA-III. It also ships samplers Optuna does not have, among them AGE-MOEA-2, SMS-EMOA, MOEA/D, RVEA, LM-CMA, VkD-CMA, differential evolution, PSO, the natural evolution strategies (OpenAI-ES, SNES, xNES), TuRBO, REMBO, SAASBO and JANUS.
- Pruners: Median, Percentile, SuccessiveHalving, Hyperband, Threshold, Patient, Wilcoxon and Nop.
- Storages: in-memory and journal-file storage, heartbeats and
RetryFailedTrialCallback. - Analysis: parameter importance (fANOVA, mean decrease impurity, PED-ANOVA, SHAP), terminators,
the data layer behind every
plot_*function, and a scikit-learn-styleOptunaSearchCV. - Artifacts: a file-system artifact store.
Companion packages
Anything that needs a foreign runtime or a heavy client library ships separately, so this package
depends only on NumSharp, its OpenBLAS backend and Microsoft.Extensions.DependencyInjection.Abstractions.
| Package | What it adds |
|---|---|
OptunaSharp.Storage.Sqlite |
SQLite RDBStorage, database-compatible with Python Optuna |
OptunaSharp.Storage.EFCore |
PostgreSQL and MySQL RDBStorage over Entity Framework Core |
OptunaSharp.Storage.Grpc |
the gRPC storage proxy, client and server |
OptunaSharp.Storage.StackExchange.Redis, .NRedisStack, .ServiceStack.Redis |
Redis journal backends, one per Redis client, over the shared OptunaSharp.Storage.Redis |
OptunaSharp.Artifacts.S3, .Gcs, .AzureBlob, .R2 |
cloud artifact stores |
OptunaSharp.Visualization.Plotly |
interactive figures for every plot_* function |
OptunaSharp.Integration.LightGbm, .ML.NET |
LightGBMTuner, pruning callbacks and ML.NET-backed importance evaluators |
OptunaSharp.Interop.pythonnet, .BoTorch, .PyCma, .Pymoo |
bridges that drive OptunaHub, BoTorch, pycma and pymoo in-process |
OptunaSharp.Cli |
the optunasharp command-line tool (dotnet tool install -g OptunaSharp.Cli) |
Compatibility target
OptunaSharp tracks Optuna 5.x as its behavioral source of truth: names, defaults, edge cases and error messages follow Optuna. Where OptunaSharp and Optuna differ, Optuna is treated as correct and OptunaSharp is aligned to it. The test suite checks OptunaSharp against live Python Optuna, including seeded runs that must reproduce the values Optuna samples exactly.
Links
- Documentation: https://scisharp.github.io/OptunaSharp
- Source and issues: https://github.com/SciSharp/OptunaSharp
License
MIT. OptunaSharp is a derivative of Optuna (© Preferred Networks, Inc.) and retains its notice —
see LICENSE.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.12)
- NumSharp (>= 0.81.0)
- NumSharp.Interop.OpenBLAS (>= 0.81.0)
-
net8.0
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.2)
- NumSharp (>= 0.81.0)
- NumSharp.Interop.OpenBLAS (>= 0.81.0)
NuGet packages (17)
Showing the top 5 NuGet packages that depend on OptunaSharp:
| Package | Downloads |
|---|---|
|
OptunaSharp.Interop.pythonnet
OptunaSharp's bridge to the live Python Optuna ecosystem via Python.NET (pythonnet), most importantly OptunaHub (https://hub.optuna.org/). OptunaHub.LoadModule("samplers/auto_sampler") / ("benchmarks/bbob") mirrors optunahub.load_module, and the loaded contributor packages are wrapped so an OptunaSharp Study can drive them directly: a hub SimpleBaseSampler becomes an OptunaSharp BaseSampler (over a synchronized shadow study), and a hub BaseProblem becomes an OptunaSharp objective (search space + directions + evaluate). The .NET analog of NumSharp.Interop.pythonnet. Requires a discoverable CPython with `pip install optuna optunahub`. Part of the SciSharp STACK. |
|
|
OptunaSharp.Storage.Redis
Shared, client-agnostic primitives for the OptunaSharp Redis journal backends: the redis:// URL parser (RedisEndpoint / RedisUrl), the Redis key layout, and the atomic append Lua script (RedisJournalProtocol). No Redis client dependency of its own — the StackExchange / NRedisStack / ServiceStack backend packages build on this. Part of the SciSharp STACK. |
|
|
OptunaSharp.Artifacts.S3
Amazon S3 (and S3-compatible) artifact store for OptunaSharp — a port of optuna.artifacts.Boto3ArtifactStore, backed by the official AWS SDK for .NET (AWSSDK.S3). Optional satellite package; OptunaSharp Core stays pure-managed and does not depend on it. |
|
|
OptunaSharp.Integration.ML.NET
The ML.NET integration for OptunaSharp (a .NET port of Optuna): ML.NET-backed forest parameter-importance evaluators over the Microsoft.ML.FastTree runtime. A faithful FastForest backend — FastForestFanovaImportanceEvaluator (fANOVA — Hutter et al. 2014) and FastForestMeanDecreaseImpurityImportanceEvaluator (MDI) — plus EXPERIMENTAL / off-label gradient-boosted-tree backends (ML.NET FastTree and FastTreeTweedie): FastTree/FastTreeTweedie {Fanova,MeanDecreaseImpurity}ImportanceEvaluator. The canonical FanovaImportanceEvaluator / MeanDecreaseImpurityImportanceEvaluator ship in Core as a pure-managed, bit-exact port of scikit-learn's RandomForestRegressor (value-parity with Python Optuna); FastForest fits that same bagging model with ML.NET (ranking parity — values diverge, not tree-identical to scikit-learn), while the boosters fit the ensemble residual rather than the objective, so fANOVA/MDI over them is off-label — a non-standard quantity with NO value-parity to Optuna (weak ranking agreement at best). Prefer the canonical Core evaluators when Optuna parity matters. Also ships the ML.NET backend for the Core OptunaSearchCV (the Phase-6 optuna.integration analog): MLNetEstimator, the ICrossValidationEstimator that cross-validates an arbitrary ML.NET pipeline — an adapter (validated by usage, not bit-parity), since ML.NET is not scikit-learn. (OptunaSearchCV itself, the ICrossValidationEstimator seam, and the byte-exact native scikit-learn backend all live in Core — the latter under namespace OptunaSharp.Integration.Sklearn.) The framework-agnostic PruningCallback — for driving pruning from your own training loop — lives in Core (OptunaSharp) as the base that framework integration packages extend. LightGBM lives in the separate OptunaSharp.Integration.LightGbm package (distinct heavy native runtime + Optuna tuner identity). Part of the SciSharp STACK. |
|
|
OptunaSharp.Interop.BoTorch
BoTorchSampler for OptunaSharp — a native OptunaSharp BaseSampler that drives the real BoTorch (PyTorch + GPyTorch) library in-process via Python.NET (pythonnet). A faithful C# port of optuna_integration's BoTorchSampler glue (sampler protocol + candidates_func selection) whose numerics are direct botorch calls, so it is byte-exact with BoTorch. You pick the acquisition function with the pythonnet-free BoTorchCandidatesFunc enum: LogEI, qEI, qLogEI and qNEI for one objective; qEHVI, EHVI, qNEHVI, qParEGO and qLogEI-ParEGO for several; the knowledge-gradient qKG and qHVKG; constrained optimization through Trial.SetConstraint. Does NOT require the Python optuna_integration package — install only `botorch`. The .NET analog of using optuna_integration.BoTorchSampler, built on OptunaSharp.Interop.pythonnet. Part of the SciSharp STACK. |
GitHub repositories
This package is not used by any popular GitHub repositories.