Skip to content

Automatic mode

With method="auto" (Method::automatic, the default), deblais chooses the method and its parameters from the dimension and the sizes of the problem. Every method is exact: the choice only changes the running time.

The rule

Problem Method Parameters
dimension 1 line closed form
fewer than 500 points on the larger side in dimension 2, 2000 above simplex from scratch
more decomposition multiscale start, 2 sweeps per level, cells of 384 sources below 300 000 points, 512 above

The coarsest level of the multiscale start, min_size, follows the size: the largest of 100, 300, 1000 and 3000 points that is at most a sixth of the larger cloud. Small problems get a few levels instead of a single one.

Two more decisions are taken from the masses, whatever the method:

  • Flows: integers when the masses are uniform on each side or are integers, doubles otherwise.
  • Auction: when there are as many targets as sources with uniform masses (an assignment problem), the levels of the multiscale start are solved by an auction instead of the simplex.

Inside the simplex, the dynamic trees and the pricing helper threads switch on by themselves on large problems.

To see the choice without solving:

deblais.recipe(3, 1_000_000, 1_000_000)
# {'method': 'decomposition', 'sweeps': 2, 'cell': 512, 'min_size': 3000}
const deblais::Recipe r = deblais::recipe(3, 1000000, 1000000);

and after a solve, plan.method is the method that ran.

Where the threshold comes from

The threshold was measured, not guessed: times in seconds of the three methods on uniform clouds of the unit square, same number of sources and targets, 8 threads of a desktop machine (Intel, 8 cores). Best time in bold.

Points simplex multiscale decomposition
1 000 0.018 0.07
3 000 0.10 0.06 0.06
6 000 0.15 0.13 0.07
12 000 0.47 0.38 0.14
25 000 3.7 1.5 0.2
50 000 12.8 4.5 1.1

The plain simplex wins on small problems, where building the levels of a multiscale start costs more than the solve. From a few thousand points on, the domain decomposition wins and the gap widens quickly. The same order holds in dimension 3 and with random masses (20 000 points: 2.1, 3.3 and 0.77 s), and on a single thread (40 000 points: 2.8 s for multiscale, 1.7 s for decomposition).

multiscale alone was never the fastest in these measurements: it stays available as an explicit method, but the automatic mode does not choose it.

The small sizes were then measured more finely on a 192-core node (AMD EPYC 9654): 500 to 20 000 points, dimensions 2 and 3, five shapes of clouds, uniform and random masses, 1 to 192 threads, every method and coarsest level. A multiscale start with a small coarsest level beats the plain simplex from 500 points in the plane and from 2000 points in dimension 3. Compared with a coarsest level of 3000 points everywhere, the size-dependent min_size makes the automatic mode 1.2 to 3 times faster from 1000 to 10 000 points in the plane (geometric mean over the problems), and up to 1.3 times in dimension 3. The plain simplex remains faster on some problems of a few thousand points with uniform masses and 64 threads or more.

From 10 000 to 100 000 points, cells of 384 sources and pricing helper threads from 20 000 sources save 7 to 25 % on 16 threads; they cost 1 to 2 % from a million points on, so the automatic mode keeps the former values there.

These timings come from one machine and one family of problems. If your problems are very different (strongly clustered data, very unequal sizes), it is worth timing the methods once: the result is the same, only the time changes.

Other costs

The rule above was measured for the squared Euclidean cost, \(p = 2\), and the automatic mode applies it to every exponent (except line with \(p < 1\), where the closed form does not hold and the simplex runs instead). Only \(p = 2\) keeps the single precision filter of the pricing; the other exponents compute every candidate cost in double precision.

The strategies of deblais still pay for other costs, but less, and the best one depends more on the problem. On the 192-core node, 16 threads, dimensions 2 and 3, four shapes of clouds, uniform and random masses, speed-up over the plain simplex (geometric means, below 1: slower):

Cost best method, 10 000 points best method, 20 000 points automatic mode, 2 000 points
\(p = 0.5\) 2.3 5.8 0.68
\(p = 1\) 2.0 5.4 0.65
\(p = 1.5\) 2.8 7.7 0.78
\(p = 2\) 4.0 11.4 1.17
\(p = 3\) 2.8 8.8 0.67

For \(p \ne 2\) the automatic mode is slower than the plain simplex up to a few thousand points, and the winner among multiscale and decomposition and their coarsest levels changes from one problem to the next. For another exponent, run tune once on a typical problem and reuse its options:

t = deblais.tune(x, y, p=1)
plan = deblais.solve(x2, y2, **t["options"])   # t["options"] contains p=1

Overriding

Any option you set is kept; the automatic mode fills in the others.

deblais.solve(x, y, method="simplex")              # force a method
deblais.solve(x, y, sweeps=3, cell=1024)           # tune the decomposition
deblais.solve(x, y, auction=False, flows="real")   # switch off the special cases

Tuning for your clouds

The automatic mode decides from the dimension and the sizes only. Its thresholds were measured on uniform clouds, and the best choice also depends on the shape of the clouds and on the machine. tune measures instead: it solves the problem in the automatic mode, then changes one choice at a time and keeps a change when the solve gets faster by at least 3 %:

  1. the method: simplex from scratch (up to 20 000 points), multiscale start, domain decomposition;
  2. the number of threads, halved as long as the time does not grow, which frees the rest of the machine, or doubled when the solve gets faster;
  3. the size of the coarsest level of the multiscale start, min_size, from 100 to 30 000 points;
  4. the auction, on assignment problems;
  5. the sweeps and the cell size of the domain decomposition.

Steps 2 to 5 are repeated while one of them changes something, since the choices interact. Short solves are timed several times and the fastest time is kept.

t = deblais.tune(x, y)
t["options"]    # for instance {'method': 'decomposition', 'threads': 16, 'sweeps': 2, 'cell': 512, 'min_size': 1000, 'auction': True}
t["seconds"], t["seconds_automatic"]
t["plan"]       # the plan of x and y, already solved

for x, y in batches:   # many problems of the same size and shape
    loss = deblais.wasserstein2(x, y, **t["options"])
const deblais::Tuning t = deblais::tune<2>(source, target);
const deblais::Plan plan = deblais::solve<2>(other_source, other_target, t.options);

Every configuration is an exact solve, timed one to seven times, and a search tries 10 to 25 of them: tune pays off when many problems of the same size and shape follow, as in a training loop. max_seconds bounds the search. The gains are on small and medium problems, where the best method and coarsest level depend on the shape of the clouds and on the number of threads: from 500 to 10 000 points, the automatic mode is 18 % slower than the best configuration on average, more than 1.7 times slower on one problem in ten, and up to 5 times on the worst one. From 100 000 points on, the parameters change the time by a few percent at most, and tune mostly finds how many threads are worth using.