Skip to main content

Cycle exchange: sampling the minimum cycle bases of a graph

Project description

Cycle exchange: Enhanced sampling of minimum cycle bases

The cycle exchange (cycxchg) is a collection of Python codes for sampling cycles from a NetworkX simple graph. These codes are computationally efficient for physical networks, e.g., material networks. These codes can be used to compute:

  • Polyhedron-interchangeability (pi) and short loop-interchangeability (sli) classes that partition the set of relevant cycles (Vismara,1997). pi classes identify three-dimensional structures and sli classes group related large relevant cycles together.
  • Uniform random sampling of the minimum cycle bases (MCBs) of a graph. This definition outputs a set of cycles that are relevant, grow linearly with system size, and are statistically well-defined.
  • Pairwise intersection characteristics of MCB cycles. These are the paths that join two cycles in an MCB together. These intersections can be used to define a dual graph.

These codes are a part of the article "Theory and algorithms for clusters of cycles in graphs for material networks" listed below. If you use these codes please cite this work.

Installation

Included in this repository is a package cycxchg for computing cycles from a NetworkX graph. This can be installed from PyPI as follows:

pip install cycxchg

We recommended installing this package in a new Python environment.

Alternatively, the cycxchg package can be installed locally, so that the files can be modified.

git clone https://github.com/perrineruth/Sampling_Minimum_Cycle_Bases
cd Sampling_Minimum_Cycle_Bases
pip install -e .

This has the same affect as including the files cycxchg.py (for computing cycles) and sparseb.py (for performing sparse binary matrix operations) in the current working directory. These files are located in the \src folder.

General Workflow

We assume the cycxchg and networkx packages are imported with the given syntax.

import networkx as nx
import cycxchg as cxc

The main component of these codes is the cycle_decomposition object. For a NetworkX graph G this decomposition is given by:

cyc_dec = cxc.cycle_decomposition(G)

The cyc_dec object breaks the relevant cycles of G into pi and sli classes. These are contained in cyc_dec.pi_classes and cyc_dec.sli_classes. A sli class "sc" can be visualized as a NetworkX graph by extracting its edges:

Gsc = nx.from_edgelist(sc.edges())
nx.draw(Gsc)

A pi class can be visualized by this method as well. More methods for the pi and sli classes are given in cycle_decomposition.ipynb.

A random MCB can be extracted from the cyc_dec object as follows:

rMCB = cyc_dec.random_MCB()

If the optional argument merge_MCB is set to True, then the MCB is postprocessed so that every pair of cycles intersects over at most one path. These connection paths are returned as two matrices.

  1. Weights. Weights[i,j] is a signed integer whose magnitude is the length of the intersection path between MCB cycles i and j. The sign of Weights[i,j] gives the orientation of this path in cycle i.
  2. Indices. Indices[i,j] points to the start of the intersection path between MCB cycles i and j. Indices[i,j] and Indices[j,i] point to the same node in cycles i and j respectively.

These matrices are returned as follows:

rMCB,Weights,Indices = cyc_dec.random_MCB(merge_MCB=True)

See random_MCB_and_twistane for more on random sampling of MCBs.

Examples

This repository includes several Jupyter notebooks (located in \examples):

  • cycle_decomposition.ipynb. This notebook gives an overview of the cycle_decomposition object including:
    • example graphs and their pi and sli classes,
    • algorithmic tests of the time-complexity to compute the cycle_decomposition object,
    • and an outline of the algorithmic steps to compute the cycle_decomposition object.
  • random_MCB_and_twistane.ipynb. This notebook demonstrates the procedure for sampling the MCB of a graph uniformly at random including:
    • an outline of the algorithmic steps used to construct a random MCB,
    • discussion of the convergence of this approach,
    • and an example of the connection matrices Weights and Indices when merge_MCB=True
  • random_geometric_graphs.ipynb. Computation of the loop length distribution for the relevant cycles and for a random MCB given by a random geometric graph model with periodic boundary conditions. These codes show the number of large relevant cycles grows much faster than the number of large MCB cycles.
  • C10H16_cycle_analysis.ipynb. Analysis of the size distribution of the pi and sli classes in the carbon skeleton of an adamantane ($\rm C_{10}H_{16}$) simulation at 4000K. The data for this notebook are contained in the zip file in data/C10H16_4000K_bond_data.

Citing this repository

If you use the codes or data in this repository please cite the following

Theory and algorithms for clusters of cycles in graphs for material networks. Perrin E. Ruth, Maria K. Cameron, submitted. arXiv:2511.09732

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

cycxchg-0.0.1.tar.gz (25.8 kB view details)

Uploaded Source

Built Distribution

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

cycxchg-0.0.1-py3-none-any.whl (26.9 kB view details)

Uploaded Python 3

File details

Details for the file cycxchg-0.0.1.tar.gz.

File metadata

  • Download URL: cycxchg-0.0.1.tar.gz
  • Upload date:
  • Size: 25.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for cycxchg-0.0.1.tar.gz
Algorithm Hash digest
SHA256 755d63cc5448f1c262522efd094236d5373b022b757e153d8f58d25fee116c55
MD5 8d82d8fd23757c45168be22c9b79bffc
BLAKE2b-256 66a2f83b9d1217e32726e2ffb48dc835f75383223b2f80d8858d32db0ee6affc

See more details on using hashes here.

File details

Details for the file cycxchg-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: cycxchg-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 26.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for cycxchg-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d21d2a23582267a71592ae1d20e02a3026e490f0a9578feafec30837362f3ff6
MD5 c7d62ec27c48151b2f27248ad6131e27
BLAKE2b-256 69c1c2e50fe7a391807f4da2d412cfd2047422948e5f56c70e6bec956e895d6e

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