Skip to main content

chipfiring

Unified interface for visualization and analysis of chip firing games and related algorithms.

Latest Version on PyPI Build Status Documentation Status Coverage Status PyPI Downloads

A Python implementation of the chip-firing game (also known as the dollar game) on graphs. This package provides a mathematical framework for studying and experimenting with chip-firing games, with a focus on the dollar game variant.

Documentation

Visit Read the Docs for the full documentation, including overviews and several examples. Repository-specific guides are available in the changelog, contributing guide, and examples directory.

Overview

The chip-firing game is a mathematical model that can be used to study various phenomena in graph theory, algebraic geometry, and other areas of mathematics. In the dollar game variant, we consider a graph where:

  • Vertices represent people
  • Edges represent relationships between people
  • Each vertex has an integer value representing wealth (negative values indicate debt)
  • Players can perform lending/borrowing moves by sending money across edges

The goal is to find a sequence of moves that makes everyone debt-free. If such a sequence exists, the game is said to be winnable.

Installation

chipfiring requires Python 3.8 or newer.

pip install chipfiring

Usage

Here is a complete example using the current public API:

from chipfiring import CFDivisor, CFGraph, is_q_reduced, is_winnable, q_reduction

vertices = {"Alice", "Bob", "Charlie", "Elise"}
edges = [
    ("Alice", "Bob", 1),
    ("Alice", "Charlie", 1),
    ("Alice", "Elise", 2),
    ("Bob", "Charlie", 1),
    ("Charlie", "Elise", 1),
]
graph = CFGraph(vertices, edges)
divisor = CFDivisor(
    graph,
    [("Alice", 2), ("Bob", -3), ("Charlie", 4), ("Elise", -1)],
)

print(is_winnable(divisor))

bob_reduced = q_reduction(divisor, q_name="Bob")
print(is_q_reduced(bob_reduced, q_name="Bob"))

The predicate and reduction helpers operate on a copy and do not mutate the supplied divisor. The same holds for DharAlgorithm, GreedyAlgorithm, and the rank and gonality helpers: every algorithm works on a private copy that stays attached to the caller's graph object, and only the explicit move methods (lending_move, borrowing_move, set_fire, chip_transfer) change a divisor in place. Use CFDivisor.copy() when you need an independent divisor for such moves. CFGraph equality is structural, so linear_equivalence also accepts divisors on independently constructed copies of the same graph. If q_name is omitted, q_reduction preserves the historical most-indebted-vertex heuristic. Use q_reduction_with_root when the automatically chosen root is needed for a later is_q_reduced check.

Mathematical Background

The package uses the standard divisor theory of finite graphs, including:

  1. Graph Structure: Finite, connected, undirected multigraphs without loop edges
  2. Divisors: Elements of the free abelian group on vertices
  3. Laplacian Matrix: Matrix representation of lending moves
  4. Linear Equivalence: Equivalence relation on divisors
  5. Effective Divisors: Divisors with non-negative values
  6. Winnability: Property of being linearly equivalent to an effective divisor

Features

  • Mathematical graph implementation with support for multigraphs
  • Divisor class with operations for lending and borrowing
  • Laplacian matrix computations
  • Linear equivalence checking
  • Set-firing moves
  • Winnability and explicit q-reduction
  • Baker-Norine rank and graph gonality helpers
  • Dhar's burning algorithm and graph orientations
  • Interactive graph and divisor visualization
  • Type hints and API documentation

Development

To set up the development environment:

# Clone the repository
git clone https://github.com/DhyeyMavani2003/chipfiring.git
cd chipfiring

# Create and activate virtual environment
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate

# Install development dependencies
pip install -r requirements.txt
pip install -r requirements.docs.txt

# Run the regression tests and package doctests
python -m pytest -q
python -m pytest --doctest-modules chipfiring -q

# Verify the saved-output examples
make check-example-outputs PYTHON=python

# Build documentation
cd docs
make html

License

This project is licensed under the MIT License; see LICENSE.txt.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Download files

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

Source Distribution

chipfiring-1.1.5.tar.gz (133.3 kB view details)

Uploaded Source

Built Distribution

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

chipfiring-1.1.5-py3-none-any.whl (75.2 kB view details)

Uploaded Python 3

File details

Details for the file chipfiring-1.1.5.tar.gz.

File metadata

  • Download URL: chipfiring-1.1.5.tar.gz
  • Upload date:
  • Size: 133.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for chipfiring-1.1.5.tar.gz
Algorithm Hash digest
SHA256 a7ab4ab8ff9f09b4d3f3a51f9337345357686b714c25977b8c428f2c750b05f4
MD5 42792af264ec8a06f34c8f4c165ac857
BLAKE2b-256 0ed4550d72ec6166c6148b84c4af771d94041f723fcca0ed6eea067e64c0e83c

See more details on using hashes here.

Provenance

The following attestation bundles were made for chipfiring-1.1.5.tar.gz:

Publisher: publish.yml on DhyeyMavani2003/chipfiring

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file chipfiring-1.1.5-py3-none-any.whl.

File metadata

  • Download URL: chipfiring-1.1.5-py3-none-any.whl
  • Upload date:
  • Size: 75.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for chipfiring-1.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 b2debb26dc83460c8b633d2a4c4405f41f4ec13e471081b759e2ccb0d528e66e
MD5 709cec5d7944a8be96d050f260af2ab7
BLAKE2b-256 62d2702e2b18b96877cc13c68d83e9f3a57a417547af50dc59faf519229466ff

See more details on using hashes here.

Provenance

The following attestation bundles were made for chipfiring-1.1.5-py3-none-any.whl:

Publisher: publish.yml on DhyeyMavani2003/chipfiring

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

1.1.5 This release

2 files

1.1.4

2 files

1.1.3

2 files

1.1.1

2 files

1.1.0

2 files

1.0.0

2 files

0.1.2

2 files

0.1.1

2 files

0.1.0

2 files

0.0.3

2 files

0.0.1

2 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