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/IvanChernyshov/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.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-py3-none-any.whl (60.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pbcgraph-0.1.3.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.tar.gz
Algorithm Hash digest
SHA256 7f6b7dea9365a67a6a8d90ebe8f1e08190da2e63fdba5e5e0a392ed0f974f21d
MD5 630566c10f481eddcb24ec6ddf4df6ce
BLAKE2b-256 0187f7c7bb9cfe754e2ba2f7e3c59d433d2593780694be331f98a3a072c31b90

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pbcgraph-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 60.5 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-py3-none-any.whl
Algorithm Hash digest
SHA256 96b05bc6295fd360ce7427f1ec2ddf873979c157776997c1e205fce64030590e
MD5 e610cc24e4d9134f90947f9d58383366
BLAKE2b-256 19305348a10c7eee210efaed549d077b60c25d4ec44439e3e90cc402378bfd55

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