deblais computes exact optimal transport between point clouds: the optimal plan, its cost (the squared Wasserstein-2 distance) and the Kantorovich potentials, for the squared Euclidean cost. It is a header-only C++17 library with no dependency, and a Python package on top of it that takes NumPy arrays and PyTorch tensors.
The solver is a network simplex that never stores the cost matrix, started by a multiscale scheme and by parallel sweeps of a domain decomposition. It solves a million points against a million in the plane in 13 to 31 seconds on 8 threads depending on the masses, in linear memory, and returns a certificate of optimality.
deblais is the twin of remblais, which computes geometric losses (Sinkhorn divergences, kernel norms, Hausdorff divergences): which one do I need?
- Documentation: https://keckj.github.io/deblais/
- Getting started: https://keckj.github.io/deblais/getting-started/
- Example, ten million grains from the streets of Paris to the streets of London, in your browser: https://keckj.github.io/deblais/demo/paris-london/
- More examples (morphing, color transfer, stippling, a generative network trained with the exact distance): https://keckj.github.io/deblais/examples/
import deblais
plan = deblais.solve(x, y) # x: (n, d), y: (m, d), NumPy or PyTorch
plan.cost # W2^2, exact
plan.source, plan.target, plan.mass # sparse optimal plan
plan.f, plan.g # dual potentials
#include <deblais/deblais.hpp>
const deblais::Plan plan = deblais::solve(2, x, y); // std::vector<double>, point after point
Why deblais
- Exact. The result is an optimal vertex of the transport polytope: no
regularization, no blur, no tolerance to tune. With uniform or integer
masses the flows are computed in integer arithmetic. The plan comes with
dual potentials that prove its optimality, and
deblais::certifychecks them independently of the solver. - Fast. The time grows almost linearly with the number of points, in every dimension from 1 to 4. On 8 threads, a million points against a million take 13 to 31 seconds in the plane, ten million points 4 to 10 minutes. At 100 000 points, deblais is 450 times faster than the network simplex it started from on one thread, and 900 times faster when both run on 16 cores. See Performance.
- Large problems. The cost matrix is never stored: memory is linear in the number of points. A dense solver needs 8 TB for the cost matrix of a million points; deblais solves that problem in seconds.
- Automatic.
method="auto"picks the algorithm and its parameters from the dimension, the sizes and the masses: closed form on the line, plain simplex on small problems, multiscale domain decomposition on large ones, auction on assignment problems.deblais.tunetimes a few solves of your clouds and returns the fastest options on your machine. See Automatic mode. - Header-only C++. One include, C++17, no dependency. OpenMP is used when
the compiler has it. CMake target
deblais::deblais, or just-I include. - NumPy and PyTorch. Tensors go in on any device and come back on it. The cost is differentiable with respect to the points and the masses. The package shares the OpenMP runtime that PyTorch ships.
- Permissive license. MIT or Apache-2.0, no GPL code.
Installation
Python, on x86-64 Linux (Python 3.10 or later):
pip install deblais
C++, with CMake:
include(FetchContent)
FetchContent_Declare(deblais GIT_REPOSITORY https://github.com/keckj/deblais.git GIT_TAG v0.1.0)
FetchContent_MakeAvailable(deblais)
target_link_libraries(my_program PRIVATE deblais::deblais)
or without it: copy include/ and compile with
g++ -std=c++17 -O3 -march=native -fopenmp -I include. The details, and the
build from source, are in Getting started.
Usage
Python
import numpy as np
import deblais
rng = np.random.default_rng(0)
x, y = rng.random((100_000, 3)), rng.random((80_000, 3))
a, b = rng.random(100_000), rng.random(80_000)
plan = deblais.solve(x, y, a / a.sum(), b / b.sum())
print(plan.cost, plan.status, plan.method) # exact cost, 'optimal', 'decomposition'
T = plan.map() # barycentric map, shape (100000, 3)
P = plan.sparse() # scipy.sparse matrix, at most n + m - 1 entries
With PyTorch, as a loss:
import torch
x = torch.rand(20_000, 2, device="cuda", requires_grad=True)
y = torch.rand(20_000, 2, device="cuda")
loss = deblais.wasserstein2(x, y)
loss.backward()
C++
#include <deblais/deblais.hpp>
#include <cstdio>
#include <vector>
// n source points and m target points in dimension 3, stored point after
// point (x0 y0 z0 x1 y1 z1 ...), with one mass per point
std::vector<double> x(3 * n), a(n), y(3 * m), b(m);
deblais::Cloud source(x.data(), n, a.data()); // views, nothing is copied
deblais::Cloud target(y.data(), m, b.data());
deblais::Options options; // method, threads, ...: all automatic by default
const deblais::Plan plan = deblais::solve<3>(source, target, options);
// The plan is a list of arcs: arc k moves plan.mass[k] from the source point
// plan.source[k] to the target point plan.target[k]
std::printf("cost %g, %zu arcs\n", plan.cost, plan.size());
for (std::size_t k = 0; k < plan.size(); ++k)
std::printf("%g from source %d to target %d\n", plan.mass[k], plan.source[k], plan.target[k]);
const deblais::Certificate proof = deblais::certify<3>(source, target, plan);
assert(proof.optimal());
Performance
Against network_simplex, the
implementation deblais started from (the one behind POT's ot.emd), on its
own test case (dimension 2, random masses, two AMD EPYC 9655).
network_simplex grows like $n^{2.5}$ and stores the cost matrix (80 GB at 100 000 points); deblais grows like $n$ in linear memory, and on a single thread it is 450 times faster at 100 000 points.
| Points per cloud | network_simplex, 1 thread | network_simplex, 16 threads | deblais, 1 thread | deblais, 16 threads |
|---|---|---|---|---|
| 10 000 | 4.4 s | 3.4 s | 0.21 s | 0.092 s |
| 100 000 | 1 385 s | 658 s | 3.1 s | 0.72 s |
| 1 000 000 | 47 s | 8.4 s |
Larger problems, in every dimension: wall time of a complete solve in the automatic mode, optimality certificate included, for a million points against a million drawn uniformly in the unit cube, two AMD EPYC 9654 (192 threads, pinned), GCC 14.
| Masses | Dimension 1 | Dimension 2 | Dimension 3 | Dimension 4 |
|---|---|---|---|---|
| uniform (assignment) | 0.19 s | 14 s | 11 s | 21 s |
| random integers | 0.33 s | 25 s | 33 s | 92 s |
| random reals | 0.36 s | 7.5 s | 15 s | 49 s |
The time grows like $n^\alpha$ with the number $n$ of points per cloud, with $\alpha$ between 1.0 and 1.3 in every dimension, up to thirty million points (a hundred million on the line).
The protocol, the fitted exponents, the three families of masses, the scaling with the number of threads and the command lines that reproduce these numbers are on the Performance page.
deblais and remblais
deblais and remblais are twin projects: two solvers for the two ways of computing discrete-discrete optimal transport.
| deblais | remblais | |
|---|---|---|
| Problem | exact optimal transport | entropic transport: Sinkhorn divergences, kernel norms (MMD), Hausdorff |
| Algorithm | network simplex, domain decomposition | Sinkhorn iterations |
| Result | optimal sparse plan, exact cost, certificate | a smooth loss, with a blur that trades accuracy for speed |
| Runs on | CPUs | NVIDIA, AMD and Intel GPUs, several GPUs or nodes, CPUs |
| Interface | C++17 headers, NumPy, PyTorch | PyTorch, drop-in replacement of GeomLoss |
Take deblais for a plan, an assignment or a reference value; take remblais for a loss to minimize, for other costs, unbalanced measures, images and volumes. The page deblais and remblais compares them in detail and shows how to use them together.
About the name
In 1781, Gaspard Monge asked how to move a pile of earth, the déblais, into a hole of the same volume, the remblais, at the lowest cost: the founding problem of optimal transport. deblais is where the mass comes from, and remblais is where it ends up.
License
At your option, MIT or Apache-2.0. deblais
contains no third-party code; the algorithms it implements are credited in
THIRD_PARTY.md.
Related projects
- remblais, the twin project: Sinkhorn divergences, kernel norms and Hausdorff divergences, a drop-in replacement of GeomLoss: https://github.com/keckj/remblais
- network_simplex by Nicolas Bonneel, the implementation deblais started from as a baseline: https://github.com/nbonneel/network_simplex
- LEMON, the graph library behind it: https://lemon.cs.elte.hu
- kernox, fused GPU and CPU reductions, the engine of remblais: https://github.com/keckj/kernox
Metadata
Release files for deblais 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| deblais-0.1.0.tar.gz | 109.5 kB | With provenance | Details for deblais-0.1.0.tar.gz |
Built distributions (wheels)
Total release size: 5.5 MB
Release files / deblais-0.1.0.tar.gz
| Download URL | deblais-0.1.0.tar.gz |
|---|---|
| Size | 109.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4724c72e0c3984b6359648dfc75677654a7e704cbbb97964a9ad728ac74f5b01
|
|
BLAKE2b-256 checksum How to use checksums |
8f8756b20c667ab734f24f4e12b81eac48fb6fd2be09a542016c4da25b3ea4ac
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 28, 2026.
Transparency logRelease files / deblais-0.1.0-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
| Download URL | deblais-0.1.0-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl |
|---|---|
| Size | 1.3 MB |
| Tags | CPython 3.13 Linux glibc 2.24+ x86-64 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
ce47390814c7e150fa44fec9debf18b2bdd8a72f0226c0323012db05a4a44031
|
|
BLAKE2b-256 checksum How to use checksums |
5ac0f176ae0dd563a2c67a552b9fd10e7d5756911196b190cf60f21d1ab38c37
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 28, 2026.
Transparency logRelease files / deblais-0.1.0-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
| Download URL | deblais-0.1.0-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl |
|---|---|
| Size | 1.3 MB |
| Tags | CPython 3.12 Linux glibc 2.24+ x86-64 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
fdd1c840e8429fd48109bd0d3538ac3b85337e72685b13c61b172f0e4ef4ecf8
|
|
BLAKE2b-256 checksum How to use checksums |
9baab4b6e9bb15c1d57bf7ad315bd0c4d0a244320cb45705f67c92c6c41b25ce
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 28, 2026.
Transparency logRelease files / deblais-0.1.0-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
| Download URL | deblais-0.1.0-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl |
|---|---|
| Size | 1.3 MB |
| Tags | CPython 3.11 Linux glibc 2.24+ x86-64 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
24a264899bbd154badd742a730bb868c0a8e02b8b178b6b7e294a642a870ceba
|
|
BLAKE2b-256 checksum How to use checksums |
20a353fad498ee65254e85560d7321bb359678de82a38a6abc0e44b183777958
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 28, 2026.
Transparency logRelease files / deblais-0.1.0-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
| Download URL | deblais-0.1.0-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl |
|---|---|
| Size | 1.3 MB |
| Tags | CPython 3.10 Linux glibc 2.24+ x86-64 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
d1bbbbe9e5fcff3a6f850123567c98333748d8ca7a7f1bc0b4384a3d8344c017
|
|
BLAKE2b-256 checksum How to use checksums |
a1012a16fcf4ecc21b2a8d2c2ab1631cee35e407cd6c08a42f80c1a07b8e0519
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 28, 2026.
Transparency logSecurity for deblais 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 5 files in this release have been uploaded with provenance metadata.
Attestation for deblais-0.1.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 28, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.