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
                    
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.BoTorch" 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.BoTorch" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="OptunaSharp.Interop.BoTorch" />
                    
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.BoTorch --version 1.0.0
                    
#r "nuget: OptunaSharp.Interop.BoTorch, 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.BoTorch@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.BoTorch&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=OptunaSharp.Interop.BoTorch&version=1.0.0
                    
Install as a Cake Tool

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_PYDLL to pin the interpreter) with pip install botorch.
  • Not AOT-compatible (it hosts CPython). This is a satellite package; OptunaSharp Core stays pure managed.

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

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