OptunaSharp.Interop.BoTorch
1.0.0
dotnet add package OptunaSharp.Interop.BoTorch --version 1.0.0
NuGet\Install-Package OptunaSharp.Interop.BoTorch -Version 1.0.0
<PackageReference Include="OptunaSharp.Interop.BoTorch" Version="1.0.0" />
<PackageVersion Include="OptunaSharp.Interop.BoTorch" Version="1.0.0" />
<PackageReference Include="OptunaSharp.Interop.BoTorch" />
paket add OptunaSharp.Interop.BoTorch --version 1.0.0
#r "nuget: OptunaSharp.Interop.BoTorch, 1.0.0"
#:package OptunaSharp.Interop.BoTorch@1.0.0
#addin nuget:?package=OptunaSharp.Interop.BoTorch&version=1.0.0
#tool nuget:?package=OptunaSharp.Interop.BoTorch&version=1.0.0
OptunaSharp.Interop.BoTorch
BoTorchSampler for OptunaSharp — a native OptunaSharp
BaseSampler that drives the real BoTorch (PyTorch + GPyTorch) library
in-process via Python.NET.
It is a faithful C# port of the glue in optuna_integration.BoTorchSampler — the sampler protocol
(search-space intersection, one-hot transform, startup trials, running-trial handling, direction
flipping, seed handling) and the candidates_func selection — while every numerical step
(SingleTaskGP, fit_gpytorch_mll, the acquisition functions, optimize_acqf) is a direct call
into botorch. So you get the genuine article: byte-exact with BoTorch and its acquisition
suite — with the Optuna side staying native OptunaSharp (your study, storage, and RNG). The bridge keeps
pythonnet off its public surface: you pick an acquisition with the BoTorchCandidatesFunc enum, never a
torch.Tensor.
Unlike the Python integration, this package does not depend on optuna_integration — we port it.
You only need botorch installed in a discoverable CPython:
pip install botorch # pulls torch + gpytorch
Usage
using OptunaSharp;
using OptunaSharp.Interop.BoTorch;
var study = Optuna.CreateStudy(sampler: new BoTorchSampler(seed: 0));
study.Optimize(t => Math.Pow(t.SuggestFloat("x", -10, 10) - 2, 2), nTrials: 30);
Console.WriteLine($"{study.BestValue} at {study.BestParams["x"]}");
By default the acquisition function is chosen automatically (BoTorchCandidatesFunc.Auto) from the
number of objectives and whether running trials are considered (single-objective → log-Expected
Improvement). Pick one explicitly:
var study = Optuna.CreateStudy(
sampler: new BoTorchSampler(candidatesFunc: BoTorchCandidatesFunc.QNei, seed: 0));
How it works
BoTorchSampler runs the first nStartupTrials (default 10) through an independent RandomSampler
(bit-exact with Optuna). From then on, on each ask it assembles the completed (and, if
considerRunningTrials, running) trials into the train_x / train_obj / bounds tensors exactly as
optuna_integration.botorch does, wraps the call in BoTorch's manual_seed, and hands them to the
selected candidates_func, which builds and fits a SingleTaskGP and optimizes the acquisition
function — all in real BoTorch. The returned candidate is un-transformed back to your parameters.
Requirements
- A discoverable CPython (set
PYTHONNET_PYDLLto pin the interpreter) withpip install botorch. - Not AOT-compatible (it hosts CPython). This is a satellite package; OptunaSharp Core stays pure managed.
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)
- NumSharp.Interop.pythonnet (>= 0.80.0)
- OptunaSharp (>= 1.0.0)
- OptunaSharp.Interop.pythonnet (>= 1.0.0)
-
net8.0
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.2)
- NumSharp.Interop.pythonnet (>= 0.80.0)
- OptunaSharp (>= 1.0.0)
- OptunaSharp.Interop.pythonnet (>= 1.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.0 | 36 | 11/8/2026 |