Skip to main content

pbcgraph

CI Docs PyPI Python versions License: LGPL v3

pbcgraph is a compact Python library for translation-labeled periodic graphs on the integer lattice Z^d.

You store a finite quotient graph (internally a NetworkX MultiDiGraph), but every directed edge carries an integer translation vector. This gives the quotient an exact infinite-lift semantics and lets you do instance-aware connectivity tests without enumerating the infinite graph.

What you get in v0.1:

  • PeriodicGraph / PeriodicDiGraph: unique edge per (u, v, tvec).
  • PeriodicMultiGraph / PeriodicMultiDiGraph: parallel edges allowed for the same (u, v, tvec).
  • PeriodicComponent: lattice invariants (rank, SNF torsion) and exact instance connectivity via same_fragment(...).
  • lift_patch(...): extract a finite (non-periodic) patch of the infinite lift around a seed instance.
  • canonical_lift(...): select one lifted instance per quotient node for a chosen strand (coset in Z^d/L).

Status

pbcgraph is alpha (v0.1). The core containers and component invariants are implemented and covered by tests. The API may still evolve, but the library is already useful for research code and prototyping.

Install

Requires Python 3.10+. Latest stable version is usually published on PyPI:

python -m pip install pbcgraph

To install the latest version (or for the latest dev branch), install from GitHub:

python -m pip install git+https://github.com/DeloneCommons/pbcgraph.git

For local development:

python -m pip install -e ".[dev]"

Quickstart

from pbcgraph import PeriodicGraph

# A quotient graph in Z^2.
G = PeriodicGraph(dim=2)

# Undirected edges are stored internally as two directed realizations
# with tvec and -tvec.

# Self-loop periodic edges are supported (quotient bond to a periodic image):
G1 = PeriodicGraph(dim=1)
G1.add_edge('A', 'A', tvec=(1,))

G.add_edge('A', 'B', tvec=(0, 0))
G.add_edge('B', 'C', tvec=(0, 0))
G.add_edge('C', 'A', tvec=(1, 0))  # closes a periodic cycle (rank-1 along x)

# Lifted nodes are (node_id, cell_shift).
neighbors = list(G.neighbors_inst(('A', (0, 0))))

comp = G.components()[0]
assert comp.same_fragment(('A', (0, 0)), ('A', (1, 0)))
assert not comp.same_fragment(('A', (0, 0)), ('A', (0, 1)))

# Extract a finite patch of the infinite lift around a seed instance.
patch = G.lift_patch(('A', (0, 0)), radius=2)
nx_patch = patch.to_networkx()  # nx.Graph / nx.MultiGraph for undirected sources

# For directed sources, patches are directed by default:
#   nx_patch = patch.to_networkx()  # nx.DiGraph / nx.MultiDiGraph
# and you can obtain undirected views via:
#   nx_u = patch.to_networkx(as_undirected=True, undirected_mode='multigraph')
#   nx_c = patch.to_networkx(as_undirected=True, undirected_mode='orig_edges')

# Canonical lift: pick one instance per quotient node for a strand.
lift = comp.canonical_lift(placement='tree')
assert len(lift.instances) == len(comp.nodes)

Documentation

Local docs build:

python -m pip install -e ".[docs]"
mkdocs serve

Notebooks in docs/examples/ are executed during mkdocs build (MkDocs + mkdocs-jupyter).

License

GNU LGPLv3 (or later). See LICENSE / COPYING.

Metadata

Release files for pbcgraph 0.1.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pbcgraph 0.1.4
File Size Uploaded
pbcgraph-0.1.4.tar.gz 81.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pbcgraph 0.1.4
File Interpreter ABI Platform
pbcgraph-0.1.4-py3-none-any.whl Python 3 none any Details

Total release size: 143.4 kB

Release files / pbcgraph-0.1.4.tar.gz

Download URL pbcgraph-0.1.4.tar.gz
Size 81.3 kB
Tags Source
SHA-256 checksum
How to use checksums
8d75dad7c11851803efff05d416bcc120cb1888512fee9c6d71b738d7da3bc9d
BLAKE2b-256 checksum
How to use checksums
8d361f79850779d7d7a33c6e35e56835bc7548f30dd0563d84bf1ee7a8b9f6dc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Release files / pbcgraph-0.1.4-py3-none-any.whl

Download URL pbcgraph-0.1.4-py3-none-any.whl
Size 62.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0b491f714b279dba2e36d7029b25a87ed8c0a76cb67c9a7dc18291402c859764
BLAKE2b-256 checksum
How to use checksums
13a436b633cf44f9d2befab2837cf99d8395ac83a312b7ea618b6401dc747464
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Release history Release notifications | RSS feed

This release

0.1.4 This release

2 release files

0.1.3

2 release files

0.1.0

2 release files

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