OptunaSharp.Interop.PyCma 1.0.0

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

OptunaSharp.Interop.PyCma

PyCmaSampler for OptunaSharp — a native OptunaSharp BaseSampler that drives the real pycma (Nikolaus Hansen's cma package: cma.CMAEvolutionStrategy + cma.BoundTransform) in-process via Python.NET.

It is a faithful C# port of the glue in optuna_integration.PyCmaSampler — "Layer 1": the sampler protocol (intersection search space, startup trials, direction flipping), the parameter ⇄ cma-space transforms, and the ask/tell generation replay — while the CMA-ES numerics (the covariance update and candidate generation) are direct calls into cma. So a seeded run is byte-exact with pycma, with the Optuna side staying native OptunaSharp (your study, storage, and RNG). The bridge keeps pythonnet off its public surface.

Unlike the Python integration, this package does not depend on optuna_integration — we port it. You only need cma installed in a discoverable CPython:

pip install cma

Not the same as CmaEsSampler

OptunaSharp's native CmaEsSampler (in Core) ports the separate cmaes package — a different CMA-ES implementation. PyCmaSampler wraps the cma (pycma) package. This mirrors Optuna's own split between optuna.samplers.CmaEsSampler (cmaes) and optuna.integration.PyCmaSampler (pycma). The two are not bit-identical to each other; each is byte-exact against its own backend. PyCmaSampler is deprecated upstream (@deprecated_class("4.9.0", "6.0.0")) — prefer the native CmaEsSampler for new work; this package exists for faithful parity with optuna_integration.PyCmaSampler.

Usage

using OptunaSharp;
using OptunaSharp.Interop.PyCma;

var study = Optuna.CreateStudy(sampler: new PyCmaSampler(seed: 42));
study.Optimize(t =>
{
    double x = t.SuggestFloat("x", -5, 5);
    double y = t.SuggestFloat("y", -5, 5);
    return x * x + y * y;
}, nTrials: 50);

Console.WriteLine($"{study.BestValue} at ({study.BestParams["x"]}, {study.BestParams["y"]})");

PyCmaSampler runs the first nStartupTrials (default 1) through an independent RandomSampler (bit-exact with Optuna). From then on, on each ask it rebuilds a cma.CMAEvolutionStrategy with the same seed, replays every completed generation through tell, and asks for the next candidate — all in real pycma. It optimizes float, int, and categorical parameters (categoricals as ordinals), skipping only single-value distributions. Note that, as in Optuna, PyCmaSampler does not support 1-D search spaces or multi-objective studies.

Requirements

  • A discoverable CPython (set PYTHONNET_PYDLL to pin the interpreter) with pip install cma.
  • 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