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.
- 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.
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)
| option | meaning |
|---|---|
--coeff Q|p | coefficients: Q (default) or a prime p |
--fp p,q,… | also compute the barcodes over these prime fields |
--maxdim d | highest homological degree (default 1 for Rips and flag, the top dimension otherwise) |
--threshold r | Rips: ignore edges longer than r (default: the enclosing radius) |
--periodic 0,2 | cubical: make these axes periodic |
--mode auto|fast|proved | how the rational barcode is certified; see section 4 (--proved is short for --mode proved) |
--target t, --seed s | fast 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-classify | list the candidate primes without settling them |
--engine e | Rips/flag: auto, implicit or sparse; cubical: auto or explicit |
--collapse auto|on|full|off | Rips: iterated edge collapse before the reduction |
--threads n | threads for settling candidate primes (default: all cores) |
--print ripser|perseus|json|none | what to print on the screen |
--stats | timings 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
- 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.
- 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 proveduses exact arithmetic throughout, switching to big integers where needed.--mode fastalways uses random primes. - Candidates. The prime factors of the pivot values are the candidates. Each candidate is settled by a rerun modulo that prime, in parallel.
- 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
| format | contents |
|---|---|
points | one point per line, coordinates separated by spaces or commas (Euclidean Vietoris–Rips) |
distance | a full symmetric distance matrix |
lower-distance | the strictly lower triangle of a distance matrix, row by row (as in Ripser); inf means no edge |
bin32, bin64 | the lower triangle in binary, float32 or float64 (Ripser's binary format) |
flag | the 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. |
cubical | a cubical grid of top-cell values: a line with the sizes, then the values in numpy's (C) order; nan marks an absent cell |
npy | a numpy array file of top-cell values (any real or integer type, C or Fortran order), for images and volumes |
cubes | a sparse cubical complex: one top cube per line, its integer corner coordinates, then its birth |
simplices | one simplex per line: vertex labels, then its birth (any real number). Faces are added automatically, born with their earliest coface. |
cells | a 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 01 12 2 1 12 |
Lines starting with # are comments. Small examples are in examples/ in the source distribution.
Understanding the output
prefix_k.txtholds the intervals in degree k, one per line asbirth death. A death of−1means the class never dies. This is the same format as Perseus 4, so persdia.m still plots it.prefix_betti.txtholds 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.
every_prime_factor_ofapplies 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-lengthkeeps 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)
| case | Perseus 6 | edge collapse + Ripser | Ripser | RedZeD |
|---|---|---|---|---|
| 4096 points on SO(3), H≤3 | 0.74 s | 1.43 s | 50.3 s | 29.2 s |
| 1024 points on SO(3), H≤3 | 0.09 s | 0.20 s | 2.57 s | 0.90 s |
| 16 random points, H≤7 | 0.03 s | 0.02 s | 4.45 s | 5.91 s |
| fractal, H≤2 | 1.22 s | 6.22 s | 5.75 s | 2.46 s |
| sphere (192 points), H≤2 | 0.50 s | 1.84 s | 0.79 s | 0.26 s |
| dragon (2000 points), H≤1 | 0.63 s | 22.2 s | 1.70 s | 0.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
| case | F2 only | Q with all bad primes | guarantee |
|---|---|---|---|
| 1024 points on SO(3), H≤3 | 0.06 s | 0.07 s | proved; bad prime 2 |
| 4096 points on SO(3), H≤3 | 0.85 s | 0.99 s | proved; bad prime 2 |
| sphere (192 points), H≤2 | 0.42 s | 0.45 s | proved; no bad primes |
| RP2 (600 points), H≤2 | 11.5 s | 19.2 s | proved; bad prime 2 |
| 300 random distances, H≤1 | 0.15 s | 2.1 s | proved; bad primes 2, 3, 5, 7, 47, 149 |
| Linial–Meshulam complex, 70 vertices | 0.03 s | 4.5 s | error probability < 2−88; 6 bad primes |
| Linial–Meshulam complex, 90 vertices | 0.16 s | 113 s | error 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)
| case | Perseus 6 | Cubical Ripser | GUDHI 3.13 |
|---|---|---|---|
| image, 1024 × 1024 | 0.37 s | 0.29 s | 0.010 s |
| image, 4096 × 4096 (smooth / noise) | 8.0 s / 11.6 s | 7.4 s / 8.5 s | 0.43 s / 1.66 s |
| volume, 192³ (smooth / noise) | 10.4 s / 26.0 s | 9.3 s / 24.9 s | 54.7 s / 89.8 s |
| 4D grid, 48⁴ (smooth) | 20.3 s | 16.0 s | 97.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.txtlists 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
--maxdimjust 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: