Skip to main content

lcq-persistence

DOI

Persistent lower central series quotients (LCQ barcodes) of filtered 2-dimensional CW complexes, in pure Python.

A filtered complex $X_0 \subseteq X_1 \subseteq \dots \subseteq X_N$ has a filtration of fundamental groups $G_t = \pi_1(X_t)$. For every $k \geq 1$, the layers $\gamma_k(G_t) / \gamma_{k+1}(G_t) \otimes \mathbb{Q}$ of their lower central series, with the maps induced by the inclusions, form a persistence module, and this package computes its barcode. Layer 1 is $H_1$, so its barcode is the $H_1$ barcode. The higher layers can tell apart spaces that homology cannot: a torus from $S^2 \vee S^1 \vee S^1$, or the complement of the Borromean rings from that of the unlink.

Installation

Python 3.10 or later:

pip install lcq-persistence

or, to work on the code:

git clone https://github.com/Gonzalo-Ortega/lcq-persistence.git
cd lcq-persistence
pip install -e .

This also installs GUDHI, NumPy, SciPy and Matplotlib, which the examples, the point cloud filtrations and the plots use. The computation of the barcodes itself needs nothing beyond Python.

Quick start

import gudhi as gd
from lcq_persistence import C2CWComplex

# Two loops at level 0, filled in by one triangle at level 1 and another at
# level 2: pi_1 goes F_2 -> Z -> 1.
st = gd.SimplexTree()
for edge in ([0, 1], [1, 2], [0, 2], [1, 3], [0, 3]):
    st.insert(edge, filtration = 0)
st.insert([0, 1, 2], filtration = 1)
st.insert([0, 1, 3], filtration = 2)

X = C2CWComplex.from_simplex_tree(st)
barcodes = X.lcs_barcodes(max_layer = 3)
# {1: [(1, (0, 2)), (1, (0, 1))],
#  2: [(2, (0, 1))],
#  3: [(3, (0, 1)), (3, (0, 1))]}

lcs_barcodes returns {layer: barcode}. Each barcode is in GUDHI's format, [(layer, (birth, death)), ...], so GUDHI's plotting functions take it directly, e.g. gd.plot_persistence_barcode(barcodes[2]). The time of each stage is kept in X.timings.

Building filtered complexes

Filtration levels are the integers $0, 1, \dots, N$.

  • From a GUDHI simplex tree whose filtration values are those integers: C2CWComplex.from_simplex_tree(st). Only the 2-skeleton is used. examples.data_sets.rips_simplex_tree builds such a tree from a point cloud, as a Rips filtration either by scale or grown from a base point.

  • By hand: vertices, edges and 2-cells, each with its level. An edge ((i, j), level) goes from vertex i to vertex j. A 2-cell (((edge, sign), ...), level) is attached along the word in the edges, with sign 1 or -1. For example, a torus built in two steps:

    X = C2CWComplex(
        cells_0 = [0],                                  # one vertex, level 0
        attaching_maps_1 = [((0, 0), 0), ((0, 0), 0)],  # loops a, b, level 0
        attaching_maps_2 = [(((0, 1), (1, 1), (0, -1), (1, -1)), 1)],  # a b a^-1 b^-1, level 1
    )
    X.lcs_barcodes(max_layer = 3)
    # {1: [(1, (0, inf)), (1, (0, inf))], 2: [(2, (0, 1))], 3: [(3, (0, 1)), (3, (0, 1))]}
    
  • Complements of unions of balls around a point cloud in $\mathbb{R}^3$, as the radius shrinks: C2CWComplex(*examples.data_sets.alpha_complement_filtration(points, max_radius, min_radius, n_levels)).

  • From a filtered group presentation, with all the generators at level 0 and each relator entering at its own level: C2CWComplex.from_presentation(num_generators, relators, caps). examples/complexes.py builds link-complement filtrations this way, from Wirtinger presentations.

How it works

  1. Discrete Morse matching. The matching only pairs cells that enter at the same level. The fundamental groups of the levels then have nested presentations: each one is the previous one plus some generators and relators.
  2. Persistent nilpotent quotients. Nickel's nilpotent quotient algorithm runs on the first level. Its consistent polycyclic presentation is then updated level by level: by normal closures of the new relators, by Tietze moves, and by free extensions for new free generators. The layers of every level and the maps between them come from this single sweep, for all layers up to max_layer at once. All the arithmetic is exact.
  3. Barcodes. Each layer becomes a graded $\mathbb{Q}[t]$-module presentation, whose barcode is computed by a sparse column reduction.

The results agree with GAP's nilpotent quotient program nq, run from scratch at every level, on random presentations and filtrations and on the example complexes of the tests: see validation/.

The cost grows quickly with the first Betti number $b_1$ of the early levels. By Witt's formula, layer $k$ has about $b_1^k / k$ generators. Start the filtration later (for example min_edge_length in rips_simplex_tree), or ask for fewer layers, when $b_1$ is large.

From group presentations

If you have a nested filtration of group presentations rather than a complex, persistent_lcs computes its LCS layers, the maps between them and their barcodes over $\mathbb{Q}$ or $\mathbb{F}_p$. Its levels count from 1:

from lcq_persistence.algorithms.persistent_nilpotent_quotients import persistent_lcs

# Level 1: the free group on x, y. Level 2: add the relator [x, y].
commutator = [('x', -1), ('y', -1), ('x', 1), ('y', 1)]
result = persistent_lcs([['x', 'y'], []], [[], [commutator]], 3)
result.barcode(2)     # [(1, 2)]: [x, y] dies when Z^2 is reached
result.barcode(2, 2)  # the same over F_2

Examples

python -m lcq_persistence.examples.cw_examples            # handmade complexes, link complements
python -m lcq_persistence.examples.point_cloud_examples   # lists the point cloud examples
python -m lcq_persistence.examples.point_cloud_examples torus_vs_wedge

The point cloud examples include tori versus sphere wedges, grid cell recordings, molecular Borromean rings and catenanes, and a protein catenane. The real data sets are downloaded the first time they are used (about 350 MB in total) to ~/.cache/lcq_persistence. To keep them somewhere else, set the environment variable LCQ_PERSISTENCE_DATA to another directory.

Tests

python tests/test_persistent_nilpotent_quotients.py
python tests/test_pipeline.py

or pytest. The tests are pure Python. They check the algorithm on worked examples, check random filtrations against independent computations, and compare the barcodes of the example complexes with stored ones, which agree with GAP's nq. The checks against GAP itself are in validation/, which needs SageMath.

Layout

src/lcq_persistence/
  c2cw_complex.py       filtered 2-dimensional CW complexes (C2CWComplex)
  lcs_pipelines.py      the LCS persistence pipeline, complex -> barcodes
  algorithms/           Morse matching, nested presentations of pi_1,
                        persistent nilpotent quotients, graded barcodes
  plotting.py           plots of point clouds, filtrations and barcodes
  examples/             example complexes, point clouds and scripts
tests/                  pure Python tests
validation/             checks and timings against GAP's nq (needs SageMath)

Use of AI tools

Parts of the code, tests and documentation in this repository were written with the help of an AI coding assistant, under the author's direction and review. The author is responsible for the code and its results, which are checked by the tests in tests/ and against GAP's nilpotent quotient program nq in validation/.

Citing

If you use this package in your work, please cite it. GitHub's "Cite this repository" button gives the reference, from CITATION.cff. The DOI 10.5281/zenodo.24474871 cites all versions, and each release also has its own DOI on Zenodo: version 0.1.0 is 10.5281/zenodo.24474872.

License

GNU General Public License, version 3 or later: see LICENSE.

Metadata

Release files for lcq-persistence 0.1.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 lcq-persistence 0.1.0
File Size Uploaded Provenance Actions
lcq_persistence-0.1.0.tar.gz 98.6 kB With provenance Details for lcq_persistence-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for lcq-persistence 0.1.0
File Interpreter ABI Platform Actions
lcq_persistence-0.1.0-py3-none-any.whl Python 3 none any Details for lcq_persistence-0.1.0-py3-none-any.whl

Total release size: 192.2 kB

Release files / lcq_persistence-0.1.0.tar.gz

Download URL lcq_persistence-0.1.0.tar.gz
Size 98.6 kB
Tags Source
SHA-256 checksum
How to use checksums
11a77c7035f58ead7c024a0fe9e638464db430628cc038cbf277d8aadd70062e
BLAKE2b-256 checksum
How to use checksums
586cdb9dd48539f36a640100e226ce59228502a9f2177071f0111c00871e23f8
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 24, 2026.

Transparency log

Release files / lcq_persistence-0.1.0-py3-none-any.whl

Download URL lcq_persistence-0.1.0-py3-none-any.whl
Size 93.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1eed59097bddd1293a7b8a7a94227d35ecaca8544801a973795fcd11835506c5
BLAKE2b-256 checksum
How to use checksums
fe940c0521f851f51d37a2e3cb84973714f34c2483fe8ea6c2dd92dee7e905a0
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 24, 2026.

Transparency log

Security for lcq-persistence 0.1.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

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for lcq_persistence-0.1.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 24, 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.1.0 This release

2 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