Skip to main content

deblais

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 or any power of the distance, |x - y|p. 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?

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::certify checks 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 1 000 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.tune times a few solves of your clouds and returns the fastest options on your machine. The automatic mode is tuned for the squared distance: for another exponent (p=1, p=3...), run deblais.tune once. 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.

Time of network_simplex and deblais against the number of points, log-log scale
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
Time against the number of points, one panel per dimension, log-log scale

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.

Metadata

Release files for deblais 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for deblais 0.2.0
File Size Uploaded Provenance Actions
deblais-0.2.0.tar.gz 112.8 kB With provenance Details for deblais-0.2.0.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for deblais 0.2.0
File Actions
deblais-0.2.0-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl CPython 3.13 CPython 3.13 Linux glibc 2.24+ x86-64, Linux glibc 2.28+ x86-64 Details for deblais-0.2.0-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
deblais-0.2.0-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.28+ x86-64, Linux glibc 2.24+ x86-64 Details for deblais-0.2.0-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
deblais-0.2.0-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl CPython 3.11 CPython 3.11 Linux glibc 2.28+ x86-64, Linux glibc 2.24+ x86-64 Details for deblais-0.2.0-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
deblais-0.2.0-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl CPython 3.10 CPython 3.10 Linux glibc 2.28+ x86-64, Linux glibc 2.24+ x86-64 Details for deblais-0.2.0-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl

Total release size: 11.3 MB

Release files / deblais-0.2.0.tar.gz

Download URL deblais-0.2.0.tar.gz
Size 112.8 kB
Tags Source
SHA-256 checksum
How to use checksums
612fd920fc59c947f314294eebd905a43c3d09dab19a496a7f014cb88e1afa41
BLAKE2b-256 checksum
How to use checksums
c38a6c8e57c10be49c1a4364ff60bff46c5cff6154c8befd620ac05b9cf11501
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 log

Release files / deblais-0.2.0-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl

Download URL deblais-0.2.0-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Size 2.8 MB
Tags CPython 3.13 Linux glibc 2.24+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
42a2344e4613c9d5a31acf5d4dae0239e4927a7890870c27ad38dd0fc433ef4e
BLAKE2b-256 checksum
How to use checksums
98e8b711d70bd1d71bef46056ebebf3cb829a4e6b41247ebe001480cb10a6d6d
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 log

Release files / deblais-0.2.0-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl

Download URL deblais-0.2.0-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Size 2.8 MB
Tags CPython 3.12 Linux glibc 2.24+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
652ba7ff0810944304e3b78ecf407c91999e0fbb05469f6d6882307eeaf302a0
BLAKE2b-256 checksum
How to use checksums
26be6b2570a00cb67089a6448955842ef48c81e2f6d6ab55cae10f173acf796b
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 log

Release files / deblais-0.2.0-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl

Download URL deblais-0.2.0-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Size 2.8 MB
Tags CPython 3.11 Linux glibc 2.24+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
329bffe7480ad5077012a890d2aa8c6fd87508e0f8c05fcc36bcf381fda9412b
BLAKE2b-256 checksum
How to use checksums
bb6c5f73868927fa36552896a45f9a7601725941bcade2d0be90050e8951a306
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 log

Release files / deblais-0.2.0-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl

Download URL deblais-0.2.0-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Size 2.8 MB
Tags CPython 3.10 Linux glibc 2.24+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
667bea30922bde86ed871784a2bf2d7f1d1349833f5883f0d0467e4629a92081
BLAKE2b-256 checksum
How to use checksums
e38fd82a219e52f1f193fcee603b70f0d69470d2ae182d5491e94be69e7b2c1f
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 log

Security for deblais 0.2.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.

Select from 5 files

Attestation for deblais-0.2.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 log

A 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.

Release history Release notifications | RSS feed

This release

0.2.0 This release

5 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page