OptunaSharp.Interop.pythonnet
1.0.0
dotnet add package OptunaSharp.Interop.pythonnet --version 1.0.0
NuGet\Install-Package OptunaSharp.Interop.pythonnet -Version 1.0.0
<PackageReference Include="OptunaSharp.Interop.pythonnet" Version="1.0.0" />
<PackageVersion Include="OptunaSharp.Interop.pythonnet" Version="1.0.0" />
<PackageReference Include="OptunaSharp.Interop.pythonnet" />
paket add OptunaSharp.Interop.pythonnet --version 1.0.0
#r "nuget: OptunaSharp.Interop.pythonnet, 1.0.0"
#:package OptunaSharp.Interop.pythonnet@1.0.0
#addin nuget:?package=OptunaSharp.Interop.pythonnet&version=1.0.0
#tool nuget:?package=OptunaSharp.Interop.pythonnet&version=1.0.0
OptunaSharp.Interop.pythonnet
OptunaSharp's bridge to the live Python Optuna ecosystem via Python.NET (pythonnet) — most importantly OptunaHub, Optuna's community registry of black-box-optimization methods and benchmarks.
It is the .NET analog of NumSharp.Interop.pythonnet (which bridges NDArray ↔ NumPy): here, OptunaHub.LoadModule("category/name") mirrors optunahub.load_module, and the loaded contributor packages are wrapped so an OptunaSharp Study can drive them directly.
Core stays pure-managed. This package takes a foreign-runtime dependency (an embedded CPython), so it ships separately — the
NumSharp.Interop.OpenBLASoptional-package pattern.
Prerequisites
A discoverable CPython with Optuna and OptunaHub:
pip install optuna optunahub
git on PATH (OptunaHub's default download path). Set PYTHONNET_PYDLL to your libpython if it can't be found automatically (e.g. C:\...\python312.dll, /usr/lib/.../libpython3.12.so).
Benchmarks — optimize a real hub problem with any OptunaSharp sampler
using OptunaSharp;
using OptunaSharp.Interop.PythonNet;
using var bbob = OptunaHub.LoadModule("benchmarks/bbob");
var problem = bbob.CreateProblem("Problem", new() { ["function_id"] = 1, ["dimension"] = 2 });
var study = Optuna.CreateStudy(directions: problem.Directions); // Sphere is single-objective
study.Optimize(problem.SingleObjective, nTrials: 50);
Console.WriteLine(study.BestValue);
problem.Directions and problem.SearchSpace are exposed as OptunaSharp types; problem.Objective
(multi-objective) / problem.SingleObjective suggest each parameter on the C# trial, then call the
Python evaluate. With OptunaHub ≥ 0.5.0 they first record the problem's evaluate_constraints(params)
on the trial through trial.SetConstraint, as BaseProblem.__call__ does, so constraint-aware samplers
see feasibility without a constraints_func.
Samplers — drive an OptunaSharp study with a hub sampler
using var nm = OptunaHub.LoadModule("samplers/nelder_mead");
using var sampler = nm.CreateSampler("NelderMeadSampler", new() { ["seed"] = 0 });
var study = Optuna.CreateStudy(sampler: sampler);
study.Optimize(t => {
var x = t.SuggestFloat("x", -10, 10);
return (x - 2) * (x - 2);
}, nTrials: 50);
The real Python sampler decides each suggestion; the bridge keeps a Python shadow study in sync
with the OptunaSharp study's finished trials and delegates
infer_relative_search_space / sample_relative / sample_independent to it. Designed for
single-worker Study.Optimize (nJobs = 1).
Loading
OptunaHub.LoadModule(package, repoOwner, repoName, gitRef, forceReload, baseUrl)— mirrorsoptunahub.load_module;baseUrl/repoOwner/repoNamereach third-party registries.OptunaHub.LoadLocalModule(package, registryRoot)— mirrorsoptunahub.load_local_moduleagainst a local registry checkout (e.g. the pinnedrefs/optunahub-registrysubmodule; no network).
Part of the SciSharp STACK.
| 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)
- OptunaSharp (>= 1.0.0)
- pythonnet (>= 3.2.1 && < 4.0.0)
-
net8.0
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.2)
- OptunaSharp (>= 1.0.0)
- pythonnet (>= 3.2.1 && < 4.0.0)
NuGet packages (3)
Showing the top 3 NuGet packages that depend on OptunaSharp.Interop.pythonnet:
| Package | Downloads |
|---|---|
|
OptunaSharp.Interop.PyCma
PyCmaSampler for OptunaSharp — a native OptunaSharp BaseSampler that drives the real pycma (Nikolaus Hansen's `cma` package: cma.CMAEvolutionStrategy + cma.BoundTransform) library in-process via Python.NET (pythonnet). A faithful C# port of optuna_integration's PyCmaSampler glue (the sampler protocol + the parameter/cma-space transforms + the ask/tell generation replay) whose CMA-ES numerics are direct pycma calls, so it is byte-exact with pycma. Distinct from OptunaSharp's native CmaEsSampler, which ports the separate `cmaes` package — this mirrors Optuna's own optuna.integration.PyCmaSampler vs optuna.samplers.CmaEsSampler split. Does NOT require the Python optuna_integration package — install only `cma`. The .NET analog of using optuna_integration.PyCmaSampler, built on OptunaSharp.Interop.pythonnet. 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. |
|
|
OptunaSharp.Interop.Pymoo
PymooSampler for OptunaSharp — a native OptunaSharp BaseSampler that drives the real pymoo (the multi-objective evolutionary-optimization library) in-process via Python.NET (pythonnet). One sampler exposes pymoo's whole multi-objective algorithm zoo — NSGA-II, NSGA-III, R-NSGA-II, R-NSGA-III, U-NSGA-III, AGE-MOEA, AGE-MOEA-2, RVEA, SMS-EMOA, SPEA2, C-TAEA — through a pythonnet-free PymooAlgorithm enum. The Optuna side (study, storage, ask/tell, search space) is native OptunaSharp; the operators, reference-direction machinery and HV/decomposition survival are genuine pymoo, reconstructed from the study's completed trials and driven through pymoo's native ask()/tell() — the same reconstruct-from-trials bridge as OptunaSharp.Interop.PyCma / .BoTorch. Configurable through PymooAlgorithmOptions: SBX crossover + PM mutation, duplicate elimination, RVEA alpha/adapt_freq, R-NSGA weights/mu/epsilon, and Das-Dennis / Riesz-energy reference directions. Supports constrained optimization (pymoo's G ≤ 0 feasibility, via Trial.SetConstraint or a constraintsFunc) and single-, two- and many-objective studies over Optuna's full parameter space (float/int with log/step, categoricals, dynamic spaces). Beyond Optuna core (Optuna ships only NSGA-II/III), a live-runtime complement to the native AgeMoea2Sampler. Does NOT require any Python glue package — install only `pymoo`. Built on OptunaSharp.Interop.pythonnet. Part of the SciSharp STACK. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.0 | 40 | 11/8/2026 |