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
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="OptunaSharp.Interop.pythonnet" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="OptunaSharp.Interop.pythonnet" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="OptunaSharp.Interop.pythonnet" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add OptunaSharp.Interop.pythonnet --version 1.0.0
                    
#r "nuget: OptunaSharp.Interop.pythonnet, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package OptunaSharp.Interop.pythonnet@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=OptunaSharp.Interop.pythonnet&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=OptunaSharp.Interop.pythonnet&version=1.0.0
                    
Install as a Cake Tool

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.OpenBLAS optional-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) — mirrors optunahub.load_module; baseUrl/repoOwner/repoName reach third-party registries.
  • OptunaHub.LoadLocalModule(package, registryRoot) — mirrors optunahub.load_local_module against a local registry checkout (e.g. the pinned refs/optunahub-registry submodule; no network).

Part of the SciSharp STACK.

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (3)

Showing the top 3 NuGet packages that depend on OptunaSharp.Interop.pythonnet:

Package Downloads
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.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.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