Skip to main content

Translation-labeled periodic graphs on Z^d with exact component lattice invariants.

Project description

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pbcgraph-0.1.3.post1.tar.gz (70.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pbcgraph-0.1.3.post1-py3-none-any.whl (60.6 kB view details)

Uploaded Python 3

File details

Details for the file pbcgraph-0.1.3.post1.tar.gz.

File metadata

  • Download URL: pbcgraph-0.1.3.post1.tar.gz
  • Upload date:
  • Size: 70.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.19

File hashes

Hashes for pbcgraph-0.1.3.post1.tar.gz
Algorithm Hash digest
SHA256 1b5a8f9028cec223a9b6e2018feedbb96df42be5f230bb15d15ef397389d9ed9
MD5 4666c81df9ba88e423ee673a9d0bbc0f
BLAKE2b-256 321bcdd664d2ab4354607fe2086998d966e87957d410dfd90f09ae2093228efe

See more details on using hashes here.

File details

Details for the file pbcgraph-0.1.3.post1-py3-none-any.whl.

File metadata

  • Download URL: pbcgraph-0.1.3.post1-py3-none-any.whl
  • Upload date:
  • Size: 60.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.19

File hashes

Hashes for pbcgraph-0.1.3.post1-py3-none-any.whl
Algorithm Hash digest
SHA256 f290d8a465291624d8ea9c1a003ca60055d50c4aad7b214f01a484ee1a0d78a1
MD5 7eb1b3e414dcf9bbd5b7859024b849d4
BLAKE2b-256 146f8fcf09fedd554ad33fe710b6534414ac5a42b7522e313991e0a89264e574

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page