basin

Library Listed

Numerical optimization in pure Rust, with pluggable linear-algebra backends and WASM support.

Checked · Sources

Downloads
22,519
Dependents
9
Stars
128
Forks
6
Contributors
6
Commits
728
Latest release
3.2.0 ·

About

From the project README ·

Basin is a numerical optimization library for Rust. Solve problems with or without derivatives, fit models with nonlinear least squares, and handle bounds and other constraints with algorithms suited to your problem. Basin also provides a solver for bracketed scalar equations.

Define the function you want to minimize, choose a solver, and supply a starting point. Use plain Rust vectors or your choice of nalgebra, ndarray, or faer. Basin runs natively and in the browser, with no BLAS/LAPACK or threads required by the default build. Its design is inspired by argmin.

See the documentation at basin.rs/guide or browse the API reference at docs.rs/basin. There is also an in-browser solver visualizer and a benchmarks site comparing Basin against competing crates and across backends and solvers.

To port an existing Argmin project, see Migrating from Argmin.

Install

cargo add basin

Basin works on plain Vec<f64> out of the box. Linear-algebra backends are opt-in. Use a moving alias to follow the newest supported release:

cargo add basin --features nalgebra  # or: ndarray, faer
Read the full README

Exact version features, such as nalgebra_v0_34, keep dependency resolution stable. Basin's package minimum supported Rust version (MSRV) is 1.87.0. The one exception is nalgebra 0.35: nalgebra_v0_35 and nalgebra require Rust 1.89.

Example

Implement CostFunction (and Gradient when the solver needs derivatives), then hand the problem, a solver, and an initial state to the Executor:

use basin::{
    CostFunction, Executor, FirstOrderState, Gradient, GradientDescent,
};
use std::convert::Infallible;

struct Rosenbrock;

fn main() {
    impl CostFunction for Rosenbrock {
        type Param = Vec<f64>;
        type Output = f64;
        type Error = Infallible;

        fn cost(&self, x: &Vec<f64>) -> Result<f64, Self::Error> {
            Ok((1.0 - x[0]).powi(2) + 100.0 * (x[1] - x[0].powi(2)).powi(2))
        }
    }

    impl Gradient for Rosenbrock {
        type Gradient = Vec<f64>;

        fn gradient(&self, x: &Vec<f64>) -> Result<Vec<f64>, Self::Error> {
            Ok(vec![
                -2.0 * (1.0 - x[0]) - 400.0 * x[0] * (x[1] - x[0].powi(2)),
                200.0 * (x[1] - x[0].powi(2)),
            ])
        }
    }

    let result = Executor::new(
        Rosenbrock,
        (GradientDescent::new(1e-3)).with_absolute_gradient_tolerance(1e-6),
        FirstOrderState::new(vec![-1.2, 1.0]),
    )
    .max_iter(50_000)
    .run()
    .unwrap();

    println!(
        "x = {:?}, f = {}, stopped: {:?}",
        result.param(),
        result.cost(),
        result.report.termination
    );
}

Solvers

  • First-order, quasi-Newton, and Newton: gradient descent (with momentum and pluggable line searches), SGD, BFGS, L-BFGS, L-BFGS-B, and a Newton trust-region method.
  • Derivative-free: Nelder-Mead; Brent, Brent-with-derivatives, and golden-section search (1D); Powell's model-based family (NEWUOA, BOBYQA, LINCOA, COBYLA); and MADS (OrthoMADS).
  • Nonlinear least squares: Gauss-Newton, Levenberg-Marquardt, trust-region reflective.
  • Global and stochastic: Globalized Bounded Nelder-Mead, simulated annealing, random search, CMA-ES, differential evolution, a steady-state genetic algorithm, and memetic combinations (MA-LS-Chain, plus CMA-ES and DE injection wrappers).
  • Constrained: box bounds via projected gradient descent, bounded Nelder-Mead, Globalized Bounded Nelder-Mead, L-BFGS-B, and bounded CMA-ES; LINCOA for linear constraints and COBYLA for nonlinear inequalities; log-barrier and augmented Lagrangian wrappers for more general constraints.
  • Root finding: Brent's bracketed scalar method through the direct BrentRoot::solve API.

See Solvers for which backends each one supports.

Backends

Parameters and linear algebra are generic over the backend. Vec<f64> needs no features. Each external backend has exact version features and an unversioned alias that tracks the newest supported release:

BackendExact featuresMoving alias
nalgebranalgebra_v0_32 through nalgebra_v0_35nalgebra
ndarrayndarray_v0_15 through ndarray_v0_17ndarray
faerfaer_v0_22 through faer_v0_24faer

Every nalgebra feature includes its matching nalgebra-sparse release: 0.32/0.9, 0.33/0.10, 0.34/0.11, and 0.35/0.12. Exact acceleration features follow the same naming scheme—nalgebra_v0_34-lapack and ndarray_v0_16-blas, for example. The moving aliases are nalgebra-lapack and ndarray-blas.

Citation

If you use Basin in your research, please cite the paper:

Larsson, J. (2026). Basin: Efficient and Extensible Numerical Optimization in Rust (arXiv:2608.11279). arXiv. https://doi.org/10.48550/arXiv.2608.11279

@misc{larsson2026basin,
  title         = {Basin: Efficient and Extensible Numerical Optimization in {{Rust}}},
  shorttitle    = {Basin},
  author        = {Larsson, Johan},
  year          = {2026},
  month         = aug,
  number        = {arXiv:2608.11279},
  eprint        = {2608.11279},
  primaryclass  = {cs.LG},
  publisher     = {arXiv},
  doi           = {10.48550/arXiv.2608.11279},
  archiveprefix = {arXiv}
}

BibLaTeX

@online{larsson2026basin,
  title       = {Basin: Efficient and Extensible Numerical Optimization in {{Rust}}},
  shorttitle  = {Basin},
  author      = {Larsson, Johan},
  date        = {2026-08-11},
  eprint      = {2608.11279},
  eprinttype  = {arXiv},
  eprintclass = {cs.LG},
  doi         = {10.48550/arXiv.2608.11279},
  pubstate    = {prepublished}
}

For reproducibility, also cite the software release you used. Select that release in the Zenodo archive and export its citation. The concept DOI 10.5281/zenodo.20610944 identifies Basin across all releases.

CITATION.cff contains the software metadata and preferred paper citation, and basin.rs/guide renders the paper in APA, BibTeX, and BibLaTeX.

Acknowledgements

Basin owes a substantial intellectual debt to argmin: the Executor driver loop, the Solver/Problem trait split, and per-solver State are borrowed from it, and several solver implementations and test-problem conventions were modeled on argmin's. Thanks to the argmin authors and contributors for a library that is a pleasure to learn from.

The Powell-family derivative-free solvers (COBYLA, NEWUOA, BOBYQA, LINCOA) are derived from PRIMA, Zaikun Zhang's modern-Fortran reference implementation of M. J. D. Powell's methods, used as the authoritative source for the exact formulas and as the cross-validation oracle. PRIMA is distributed under the BSD 3-Clause License; its notice is retained in COPYRIGHT.

The bound-constrained L-BFGS-B solver is a port of the L-BFGS-B version 3.0 Fortran code by Ciyou Zhu, Richard H. Byrd, Peihuang Lu, and Jorge Nocedal (ACM TOMS Algorithm 778), with the v3.0 improvements by José Luis Morales and Jorge Nocedal. It is released under the New BSD (BSD 3-Clause) License; its notice is likewise retained in COPYRIGHT.

License

Licensed under either of

at your convenience.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Runs on
GPU support unknown
What shows it
  • no dependency or feature matches a backend row
Native code
Optional
  • Binds native code: blas-sys (feature nalgebra_latest-lapack), lapack-sys (feature nalgebra_latest-lapack)
Python bindings
No Python binding crate found
License
Apache-2.0 OR MIT

Compare with similar projects

Order: strongest tier first, then most downloads, then name, with unmeasured values last. A library counts downloads over 30 days. An app counts binary downloads per release. An app with none counts its crate downloads over 30 days. ML Rust runs this catalogue, so its closest project always gets a row.

basin beside the projects that share a topic with it
ProjectDownloadsDependentsStarsLatest releaseRuns on (GPU)Native codeLicense
basin This page Listed

Numerical optimization in pure Rust, with pluggable linear-algebra backends and WASM support.

22,519 downloads over 30 days 9 128 3.2.0 GPU support unknown Binds native code: blas-sys (feature nalgebra_latest-lapack), lapack-sys (feature nalgebra_latest-lapack) Apache-2.0 OR MIT
nalgebra Featured

General-purpose linear algebra library with transformations and statically-sized or dynamically-sized matrices.

6,251,820 downloads over 30 days 2,119 4,810 0.35.0 GPU support unknown Binds native code: blas-sys, lapack-sys, defmt (feature defmt) Apache-2.0
argmin Featured

Numerical optimization in pure Rust

310,783 downloads over 30 days 98 1,278 0.11.0 GPU support unknown Binds native code: lapack-sys (feature ndarray_v0_15) Apache-2.0 OR MIT
linfa-linalg Listed Dormant

Pure-Rust implementation of linear algebra routines for ndarray

198,623 downloads over 30 days 20 39 0.2.1 GPU support unknown No native code found Apache-2.0 OR MIT
peroxide Listed

Rust comprehensive scientific computation library contains linear algebra, numerical analysis, statistics and machine learning tools with familiar syntax

Python bindings

56,548 downloads over 30 days 9 732 0.43.1 GPU support unknown Binds native code: openblas-src (feature O3-openblas-system), blas-sys (feature O3), hdf5-metno-sys (feature nc), lapack-sys (feature O3), libz-sys (feature nc) and 1 more Apache-2.0 OR MIT
numr Listed

The base for numerical code in Rust, in the role NumPy has in Python: n-dimensional tensors, linear algebra, FFT, statistics and autograd on CPU, CUDA and WebGPU. The backends use native kernels, with no cuBLAS, MKL or other vendor math library.

1,673 downloads over 30 days 7 59 0.15.2 CUDA, WebGPU Binds native code: ring (feature distributed) Apache-2.0
Why ListedNo archive, New or Featured rule places it, so it is Listed.

What it lacks for Featured

  • It has 6 active dependents and 6 new dependents in 365 days. Featured needs 11 active dependents or 9 new dependents in 365 days. The repository route reads 128 stars, 6 forks and 6 contributors. It needs 4,539 stars, 434 forks and 79 contributors together.

What else the check found

  • The last activity is on 6 Nov 2026, 3 days ago. The rules expect an update within 365 days. Dormancy rule

Exact rules: Listed, Featured library. The check on applied thresholds version 9.

Every rule outcome, as the check records it
  • expected-interval: version 3.2.0 base 200, raised to the 365-day floor: E = 365 days
  • dormancy: last activity 2026-11-06, 3 days ago, E = 365: active
  • featured: not featured: active_users 6 < 11 and new_adopters 6 < 9 and repository route stars 128 (needs 4539), forks 6 (needs 434), contributors 6 (needs 79)
  • listed: listed: no archive, new or featured rule applies

Measurements and sources

Each signal row shows the raw value, its source and the fetch date. The Sources list gathers every distinct source on this page. Movement needs more history.

Sources6 sources
Adoption6 active dependents, 6 new dependents in 365 days1 not measured
Adoption measurements
SignalValueSourceFetchedCounts
Active dependents6crates.io database dumpYes
New dependents (365 days)6crates.io database dumpYes
Peak active dependents6.5crates.io database dumpYes
Active dependents as a share of the peak1crates.io database dumpYes
Binary downloads per releaseNot measuredYes
MaintenanceLatest human commit: 3 days ago3 not measured
Maintenance measurements
SignalValueSourceFetchedCounts
Latest human commit2026-11-06GitHub repositoryYes
Latest release2026-11-02crates.io database dumpYes
First release2026-04-30crates.io database dumpYes
Latest version3.2.0crates.io database dumpYes
Days the oldest outside issue waits for a reply0GitHub repositoryYes
Maintainer replies over 365 days28GitHub repositoryYes
Repository archivedfalseGitHub repositoryYes
Repository gonefalseGitHub repositoryYes
Release commit or manifest in the repotruecrates.io packageYes
Published docstruecrates.io database dumpYes
Latest release fails cargo checkNot measuredYes
Build check dateNot measuredYes
Build check toolchainNot measuredYes
SecurityUnpatched vulnerabilities: none
Security measurements
SignalValueSourceFetchedCounts
Unpatched vulnerabilities past the grace windownoneRustSec advisory databaseYes
RustSec unmaintained advisorynoneRustSec advisory databaseYes
Deprecation noticenonecrates.io database dumpYes
Deprecated requirementnonecrates.io database dumpYes
Distribution37 releases, 22,519 downloads over 30 days5 not measured
Distribution measurements
SignalValueSourceFetchedCounts
Releases37crates.io database dumpYes
Downloads over 30 days22519crates.io database dumpYes
Binary downloads over the last 3 releasesNot measuredYes
Homebrew installs on request over 365 daysNot measuredYes
Repology repository familiesNot measuredYes
Docker pull growth over 90 daysNot measuredYes
Docker pulls at the growth baselineNot measuredYes
Every version a prereleasefalsecrates.io database dumpYes
Every version 0.0.xfalsecrates.io database dumpYes
Every version yankedfalsecrates.io database dumpYes
Crate deleted from crates.iofalsecrates.io database dumpYes
Repository128 stars, 6 forks, 6 contributors, 728 commits. Stars alone never qualify a project.
Repository measurements
SignalValueSourceFetchedCounts
GitHub stars128GitHub repositoryYes — one part of the repository route
GitHub forks6GitHub repositoryYes — one part of the repository route
Contributors with a GitHub account6GitHub contributorsYes — one part of the repository route
Commits on the default branch728GitHub repositoryNo
Repository's main crate left out of the entrynonecrates.io database dumpYes
Facts that never count
Facts that never count measurements
SignalValueSourceFetchedCounts
LicenseApache-2.0 OR MITcrates.io database dumpNo
Runs on, from listed crates and their direct dependenciesGPU support unknowncrates.io database dumpNo
What shows each backendno dependency or feature matches a backend rowcrates.io database dumpNo
Native code, from listed crates and their dependenciesBinds native code: blas-sys (feature nalgebra_latest-lapack), lapack-sys (feature nalgebra_latest-lapack)crates.io database dumpNo
Python bindings, from direct dependencies of listed cratesNo Python binding crate foundcrates.io database dumpNo
Crates that depend on a listed crate directly9crates.io database dumpNo

Corrections and review history

Report a correction

No correction applies to this entry.

Judgments

A judgment enters only through an approved issue and a merged pull request.

No judgment applies to this entry.