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()

Alternatively, a random MCB can be output as a dual graph by setting the optional argument merge_MCB is set to True.

Dual = cyc_dec.random_MCB(merge_MCB=True)

Dual is a NetworkX graph that is structured as follows

  • Nodes. The nodes of the dual graph are integers as indexes of each cycle in the random minimum cycle basis. Each node in the dual graph has two attributes.
    • nodes: the nodes in the corresponding MCB cycle.
    • length: the length of the corresponding MCB cycle.
  • Edges. The edges of the dual graph represent intersection paths between pairs of MCB cycles. Each edge has two attributes
    • length: the number of edges in the intersection path.
    • indices: a pair of indices denoting the starting point of the connection path between for both of the MCB cycles. See the notebook cycle_decomposition.ipynb for more information on constructing the intersection paths from the dual graph.

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.2.tar.gz (25.9 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.2-py3-none-any.whl (27.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: cycxchg-0.0.2.tar.gz
  • Upload date:
  • Size: 25.9 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.2.tar.gz
Algorithm Hash digest
SHA256 6b72c6681e16fc7459dd90dbcedccfed637dbf212e3bf3b468f44b44a69d7d50
MD5 e4c0eef78e3bb34956bf64cb293e1fa1
BLAKE2b-256 b0eccd1d65be25cb945a7257321963e10f7390c8023e58d212c9cdd9c985ff83

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cycxchg-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 27.0 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 9e29ffeffed996b68feafd9f2eefef731c76bc81b322d7fb2a3b0ef20a412bbc
MD5 63aade9c1f20fde5761b8f284b77a660
BLAKE2b-256 340403dd90cc9d7b05180f17ec42e4970c449c192e08ca822356523f1cf8137f

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