Perseus

Persistent homology over Q, together with every prime p for which coefficients in Fp give a different answer, and a proof that the list is complete. Or simply over the field of your choice, quickly.

What's new in Perseus 6

Perseus 6 is a complete rewrite, ten years after Perseus 4. It offers three things:

  • Rational barcodes with a certificate. One run gives you the barcode over Q and all bad primes, meaning the primes p for which the Fp barcode is different. For each bad prime it tells you exactly which intervals change. On typical data the rational computation is exact, so the certificate is a proof, and it costs little more than computing over a single prime field.
  • General inputs. Vietoris–Rips filtrations of point clouds and distance matrices, clique filtrations of weighted graphs, cubical complexes (images and volumes, including periodic ones, straight from numpy), simplicial complexes, and arbitrary filtered cell complexes with integer boundary coefficients.
  • Speed. For Vietoris–Rips in degree 2 and up it is usually much faster than Ripser and than edge collapse followed by Ripser. On volumes and 4D grids it is 3–5× faster than GUDHI and close to Cubical Ripser; on 2D images GUDHI's dedicated image algorithm is much faster than both. On sparse point clouds it is on a par with GUDHI. See performance, including where other tools win.
For example, take 1024 points sampled from SO(3) ≅ RP3. Perseus 6 proves that 2 is the only bad prime:
  • over Q, two H1 intervals die at 1.288 and 1.307;
  • over F2, those two intervals live forever, and two H2 intervals are born at exactly those times.
This is the Z/2 in H1(RP3; Z), detected and located in the filtration.

Download, install, compile

The current version is 6.0.0. Download the executable for your operating system, install the Python module, or compile from source.

The executables are command-line programs: run them from a terminal. On macOS you may need to allow the downloaded file under System Settings → Privacy & Security, and make it executable with chmod +x. To compile from source, you need a C++17 compiler with 128-bit integers: g++ 9+ or clang 10+ (on Windows, MinGW-w64; Microsoft's compiler lacks 128-bit integers).

make                                              # builds ./perseus
make test                                         # optional: differential tests
cd python && pip install --no-build-isolation .   # optional: Python module

The Python module needs pybind11 and numpy; the tests use Ripser as an oracle if it is installed.

Bug reports and feature requests are welcome on the issue tracker, or by email with “Perseus” in the subject line.

Basic usage

perseus <format> <input file> [<output prefix>] [options]

Some examples:

perseus points cloud.txt --maxdim 2             # Rips over Q, with the bad primes
perseus points cloud.txt --maxdim 2 --coeff 3   # only the barcode over F_3
perseus distance dist.csv --maxdim 1 --fp 2,3   # over Q, plus F_2 and F_3
perseus npy image.npy --periodic 0              # an image, periodic in axis 0
perseus simplices complex.txt out               # writes out_k.txt, out_betti.txt, out_cert.json
perseus flag graph.txt --maxdim 2 --proved      # exact arithmetic throughout

A summary of the certificate is printed to stderr, for example:

Q barcode: proved (exact arithmetic: int64)
bad primes: 2  (2 non-unit pivots)
optionmeaning
--coeff Q|pcoefficients: Q (default) or a prime p
--fp p,q,…also compute the barcodes over these prime fields
--maxdim dhighest homological degree (default 1 for Rips and flag, the top dimension otherwise)
--threshold rRips: ignore edges longer than r (default: the enclosing radius)
--periodic 0,2cubical: make these axes periodic
--mode auto|fast|provedhow the rational barcode is certified; see section 4 (--proved is short for --mode proved)
--target t, --seed sfast mode: aim for an error probability below 2−t (default 64); reproduce a run from its reported seed (a reproduced run is not certified)
--no-classifylist the candidate primes without settling them
--engine eRips/flag: auto, implicit or sparse; cubical: auto or explicit
--collapse auto|on|full|offRips: iterated edge collapse before the reduction
--threads nthreads for settling candidate primes (default: all cores)
--print ripser|perseus|json|nonewhat to print on the screen
--statstimings and engine statistics

Coefficients, bad primes and certificates

Over Z, persistence modules do not decompose into intervals, so there is no integral barcode. Perseus 6 reports the next best thing:

  • the barcode over Q, and
  • the set of bad primes: those p for which the barcode over Fp (same filtration, degrees 0 to maxdim) differs from the one over Q. For each bad prime you get the intervals that appear only over Fp and those that appear only over Q.

Equivalently, p is bad exactly when some relative homology group Hq(Xj, Xi; Z) of the filtration, with q ≤ maxdim, has p-torsion. This is a theorem of Obayashi and Yoshiwaki. So the bad primes record where the filtration carries integral torsion, and every other prime gives the rational answer. For filtrations of planar complexes, such as 2D images without periodic axes, Alexander duality shows there is never any torsion, so there are no bad primes.

How the certificate works

  1. The rational reduction. A prime that divides no pivot value of the reduction over Q cannot change the barcode. These pivot values are invariants of the filtered complex: ratios of minors of the boundary matrix.
  2. Arithmetic. By default (--mode auto) the reduction over Q runs in exact 64-bit arithmetic with overflow checks, and the result is a proof. If the numbers outgrow 64 bits, which happens with heavy torsion, Perseus reduces modulo a few primes drawn at random from [261, 262) instead. It then reports a bound on the probability of error, which holds for every input (below 2−64 by default); the probability is over a fresh 256-bit random seed. --mode proved uses exact arithmetic throughout, switching to big integers where needed. --mode fast always uses random primes.
  3. Candidates. The prime factors of the pivot values are the candidates. Each candidate is settled by a rerun modulo that prime, in parallel.
  4. Numbers too hard to factor. A pivot value that resists factoring does not leave a gap. One run modulo the number N itself either splits N, or proves that all prime factors of N behave identically. The certificate then states the answer for all of them at once, for example "every prime factor of N is bad".

The output says what is guaranteed: "proved", or "probabilistic" with the error bound, and whether the description of the bad primes is complete. The mathematics, with proofs, is in docs/CERTIFICATE.md.

Input formats

formatcontents
pointsone point per line, coordinates separated by spaces or commas (Euclidean Vietoris–Rips)
distancea full symmetric distance matrix
lower-distancethe strictly lower triangle of a distance matrix, row by row (as in Ripser); inf means no edge
bin32, bin64the lower triangle in binary, float32 or float64 (Ripser's binary format)
flagthe clique filtration of a weighted graph. Lines u v birth are edges and lines v birth give vertices their births (default 0). Labels can be any words. An edge may not be born before its endpoints.
cubicala cubical grid of top-cell values: a line with the sizes, then the values in numpy's (C) order; nan marks an absent cell
npya numpy array file of top-cell values (any real or integer type, C or Fortran order), for images and volumes
cubesa sparse cubical complex: one top cube per line, its integer corner coordinates, then its birth
simplicesone simplex per line: vertex labels, then its birth (any real number). Faces are added automatically, born with their earliest coface.
cellsa general filtered cell complex: one cell per line, dim birth face coeff face coeff …, where faces are the (0-based) line numbers of earlier cells and coefficients are integers. For example, the Moore space M(Z/12, 1):
0 0
1 1
2 2 1 12

Lines starting with # are comments. Small examples are in examples/ in the source distribution.

Understanding the output

  • prefix_k.txt holds the intervals in degree k, one per line as birth death. A death of −1 means the class never dies. This is the same format as Perseus 4, so persdia.m still plots it.
  • prefix_betti.txt holds the Betti numbers at every filtration value where they change.
  • prefix_cert.json (over Q) contains:
    • the barcode and the certificate mode;
    • what is guaranteed, including the error bound and random seed in fast mode;
    • the bad primes with their differing intervals, and whether that list is complete;
    • the exact values of all non-unit pivots.
    An entry marked every_prime_factor_of applies to every prime factor of the number given.
  • Without a prefix, intervals are printed to the screen in Ripser's style. Values are printed exactly: the shortest decimal that reads back as the same number.
  • Intervals of length zero are not reported (--zero-length keeps them for explicit complexes).

Python

import numpy as np, perseus
r = perseus.rips(points=X, maxdim=2)               # or distances=D
r["barcode"][1]                                    # H1 as an (m, 2) array
r["certificate"]["mode"]                           # "proved" or "fast"
perseus.bad_primes(r)                              # e.g. [2]
r["certificate"]["bad_primes"][2]["only_over_Fp"]  # what changes over F_2
perseus.cubical(image, periodic=[True, False])     # NaN = absent cell
perseus.flag([(0, 1, 0.5), (1, 2, 0.7)], vertex_births=[0, 0, 0.2])
perseus.simplices([((0, 1, 2), 1.0), ((1, 2, 3), 2.5)])
perseus.cells([(0, 0.0, []), (1, 1.0, []), (2, 2.0, [(1, 12)])])
perseus.rips(points=X, maxdim=2, coeff=2)          # just F_2
perseus.rips(points=X, maxdim=2, mode="proved")    # exact throughout

Intervals come as numpy arrays, with death inf for classes that never die. In fast mode the certificate also carries log2_error_bound and the random seed. The cells line is the Moore space M(Z/12, 1), whose bad primes are 2 and 3.

Every function takes the same options as the command line (coeff, mode, seed, target, fp, threads, classify).

Performance

All timings are wall clock on a 2-core 2.1 GHz Xeon, single-threaded except where candidate primes are settled in parallel. Every barcode in the comparisons below agrees exactly with the other tool's. The Rips comparisons can be rerun with the scripts in bench/ in the source distribution.

Vietoris–Rips (F2)

casePerseus 6edge collapse + RipserRipserRedZeD
4096 points on SO(3), H≤30.74 s1.43 s50.3 s29.2 s
1024 points on SO(3), H≤30.09 s0.20 s2.57 s0.90 s
16 random points, H≤70.03 s0.02 s4.45 s5.91 s
fractal, H≤21.22 s6.22 s5.75 s2.46 s
sphere (192 points), H≤20.50 s1.84 s0.79 s0.26 s
dragon (2000 points), H≤10.63 s22.2 s1.70 s0.21 s

RedZeD remains faster for H1 alone and on some small examples (the 192-point sphere), and edge collapse followed by Ripser is as fast on the 16-point example. For sparse point clouds Perseus builds the radius graph directly. For example, 8,000 points in the unit cube with 13,056 edges at r = 0.047 take 0.02 s and 13 MB through H2, close to GUDHI's RipsPersistence (0.016 s against 0.012 s, both in-process).

What the certificate costs

caseF2 onlyQ with all bad primesguarantee
1024 points on SO(3), H≤30.06 s0.07 sproved; bad prime 2
4096 points on SO(3), H≤30.85 s0.99 sproved; bad prime 2
sphere (192 points), H≤20.42 s0.45 sproved; no bad primes
RP2 (600 points), H≤211.5 s19.2 sproved; bad prime 2
300 random distances, H≤10.15 s2.1 sproved; bad primes 2, 3, 5, 7, 47, 149
Linial–Meshulam complex, 70 vertices0.03 s4.5 serror probability < 2−88; 6 bad primes
Linial–Meshulam complex, 90 vertices0.16 s113 serror probability < 2−86; bad primes 2 and a 166-bit prime

Time beyond F2 is mostly spent settling candidate primes. Random 2-complexes near the threshold where their homology vanishes carry enormous torsion. At 90 vertices the rational reduction takes 1.3 s and produces 463 candidate primes, of which exactly two are bad.

Cubical complexes (F2)

casePerseus 6Cubical RipserGUDHI 3.13
image, 1024 × 10240.37 s0.29 s0.010 s
image, 4096 × 4096 (smooth / noise)8.0 s / 11.6 s7.4 s / 8.5 s0.43 s / 1.66 s
volume, 192³ (smooth / noise)10.4 s / 26.0 s9.3 s / 24.9 s54.7 s / 89.8 s
4D grid, 48⁴ (smooth)20.3 s16.0 s97.6 s

All three compute the same complex (top-cell values) and the same barcode. GUDHI times are for CubicalPersistence, its recommended entry point, which uses a dedicated algorithm for 2D images and is 20–35× faster than Perseus and Cubical Ripser there. In 3 and 4 dimensions it uses the general algorithm. Perseus uses less than a third of Cubical Ripser's memory on large images (0.9 GB against 3.1 GB at 4096²).

Old Perseus files

Perseus 6 does not read the Perseus 4/5 input formats (cubtop, scubtop, simtop, nmfsimtop, cellcomp, distmat, corrmat, rips, brips) directly. Instead, convert them:

python3 tools/convert_legacy.py cubtop old.txt new.txt
# prints the matching command, e.g.:  perseus cubical new.txt --coeff 2 --periodic 1

The converter reproduces the old semantics exactly, and the test suite checks converted files against the Perseus 5 executable. The printed command uses --coeff 2, because Perseus 4 and 5 computed over F2; drop it to get the rational barcode and its bad primes. Other changes from the old programs:

  • Birth times can be any real numbers; the old restriction to positive integers is gone.
  • output_betti.txt lists Betti numbers at every value where they change.
  • For Rips-type files, the old programs reported spurious infinite intervals in their top degree. The converter caps --maxdim just below it.
  • The compiler problems with Clang and recent gcc are gone.

Older versions remain available: Linux, macOS, Windows, source (Perseus 4 beta). The old example files are still here: cubgrid.txt, scubtop.txt, simtop.txt, nmfst.txt, brips.txt, rips.txt, distmat.txt.

How it works, and credits

Perseus 4 and 5 were built on discrete Morse theory. Perseus 6 uses different algorithms, combining many published ideas with some of its own:

  • persistent cohomology with clearing (de Silva–Morozov–Vejdemo-Johansson; Chen–Kerber);
  • Ripser's implicit coboundaries and apparent pairs (Bauer);
  • edge collapse (Boissonnat–Pritam; Glisse–Pritam);
  • active enumeration for H1 (Kapulkin–Kershaw's RedZeD);
  • annotation-based persistent cohomology (Dey–Fan–Wang; Boissonnat–Dey–Maria);
  • implicit cubical persistence, including union-find on the dual graph in the top degree (Kaji–Sudo–Ahara's Cubical Ripser);
  • multi-field persistence (Boissonnat–Maria);
  • the torsion characterisation of field dependence (Obayashi–Yoshiwaki);
  • multi-modular computer algebra (rational reconstruction after Wang) and integer factoring (Pollard–Brent).

What is new is the certificate: exact or randomized rational reduction with a proven error bound, and classification of every candidate prime, including those that cannot be factored. The Rips engine also folds edge domination into the reduction itself. A full catalogue, saying what is new and what is not, is in docs/TECHNIQUES.md, and the proofs behind the certificate are in docs/CERTIFICATE.md.

Licence and citing

Perseus 6 is released under the MIT licence. The software comes with no warranty.

If Perseus helps your research, please cite the software:

Vidit Nanda. Perseus, the Persistent Homology Software, version 6.0.0. doi:10.5281/zenodo.24305983.

For results obtained with Perseus 4 or 5, whose engine is discrete Morse theory, please also cite this paper:

Konstantin Mischaikow and Vidit Nanda. Morse Theory for Filtrations and Efficient Computation of Persistent Homology. Discrete & Computational Geometry, 50(2): 330–353, September 2013.

And finally, the parts of the world where Perseus 4 was downloaded:

World map highlighting places where Perseus has been downloaded