Mandip Adhikari
← Index
ProjectAug 2025 — Jul 2026

Optimal Transport Studio

A client-side tool for entropic optimal transport with three modes: particles, continuous fields, and photo color transfer. The Sinkhorn solvers run in a worker or on WebGPU, and check themselves against an exact Hungarian solver and golden fixtures generated from POT.

TypeScript · React 19 · WebGPU (WGSL) · Web Workers · Typed arrays · Vite · Vitest · POT (fixtures)

1,048,576
grid cells in Field mode (1024², WebGPU)
60
tests, incl. POT parity within 0.1%
3
modes: particles, field, color transfer

Solver core

Sinkhorn runs in the linear or log domain, switching automatically on max(C)/ε. A streaming log-sum-exp means it never materializes e^(−C/ε), and the barycentric map finishes as a row-wise softmax.

ε-annealing is a geometric ladder: potentials are rescaled between rungs and warm-start the next one. The solver also covers unbalanced OT (KL-relaxed), debiased Sinkhorn divergence, and iterated free-support barycenters.

Execution

One persistent worker holds one solve in flight. Because the Sinkhorn loop is synchronous, cancelling means terminating the worker and lazily respawning it.

The GPU point solver recomputes costs in-kernel, so GPU memory is O(N+M) instead of O(NM). Both GPU paths fall back to the CPU worker.

┌────────────────┐  solve()  ┌──────────────────┐
│ React UI       │──────────▶│ OT client        │
│ particles ·    │◀──────────│ one solve in     │
│ field · color  │  progress │ flight           │
└───────┬────────┘           └────────┬─────────┘
        │                             ▼
        │                  ┌──────────────────────┐
        │                  │ worker               │
        │                  │ point · field solver │
        │                  └─────┬──────────┬─────┘
        │                        ▼          ▼
        │                  ┌──────────┐ ┌──────────┐
        │                  │ GPU pts  │ │ GPU field│
        │                  │ O(N+M)   │ │ f32      │
        │                  └──────────┘ └──────────┘
        ▼
  instanced particle renderer (up to 1M)

Field mode

On a grid, the squared-Euclidean Gibbs kernel factorizes into two 1D passes — O(WHr) instead of O((WH)²). On top of that: a grid pyramid with large-ε rungs on downsampled grids, plan-following truncation windows, and over-relaxation at θ = 1.5.

The fine rungs run in f32 on WebGPU, so stage tolerance is floored at 1e-4; the f64 CPU path is the reference. 512² and 1024² are disabled without WebGPU.

Verification

An O(n³) Hungarian assignment runs on a subsample of the live problem and shows the exact cost next to the entropic one.

A script generates golden fixtures from POT's sinkhorn_log; the tests require costs within 0.1% and maps within 2e-3.