chipfiring
Unified interface for visualization and analysis of chip firing games and related algorithms.
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. 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:
- Graph Structure: Finite, connected, undirected multigraphs without loop edges
- Divisors: Elements of the free abelian group on vertices
- Laplacian Matrix: Matrix representation of lending moves
- Linear Equivalence: Equivalence relation on divisors
- Effective Divisors: Divisors with non-negative values
- 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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file chipfiring-1.1.4.tar.gz.
File metadata
- Download URL: chipfiring-1.1.4.tar.gz
- Upload date:
- Size: 126.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
47fc5935bd2d7df621fcd20bda2955671549002acec71fda4aa0c3db2cebcd34
|
|
| MD5 |
5fc58babade055a02b9bda198f268f5f
|
|
| BLAKE2b-256 |
3689f2805b797d205b852a175221e992af6fa8f326e9a41870c491cdf18516fa
|
Provenance
The following attestation bundles were made for chipfiring-1.1.4.tar.gz:
Publisher:
publish.yml on DhyeyMavani2003/chipfiring
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
chipfiring-1.1.4.tar.gz -
Subject digest:
47fc5935bd2d7df621fcd20bda2955671549002acec71fda4aa0c3db2cebcd34 - Sigstore transparency entry: 2593044354
- Sigstore integration time:
-
Permalink:
DhyeyMavani2003/chipfiring@5dd6d207dbbe99abf8db9bdf9681df0f49188f2e -
Branch / Tag:
refs/tags/v1.1.4 - Owner: https://github.com/DhyeyMavani2003
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@5dd6d207dbbe99abf8db9bdf9681df0f49188f2e -
Trigger Event:
release
-
Statement type:
File details
Details for the file chipfiring-1.1.4-py3-none-any.whl.
File metadata
- Download URL: chipfiring-1.1.4-py3-none-any.whl
- Upload date:
- Size: 73.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
248f4221cabc18d6c676393ddf2c500ae2cf4cae54ea0b2aa853ef97019e2668
|
|
| MD5 |
18529299b3ba4adef50487c0845a16f8
|
|
| BLAKE2b-256 |
695a93d87b903abbcd1c36c369f24e5369c64f9125aba0fc1147dcd315a09c36
|
Provenance
The following attestation bundles were made for chipfiring-1.1.4-py3-none-any.whl:
Publisher:
publish.yml on DhyeyMavani2003/chipfiring
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
chipfiring-1.1.4-py3-none-any.whl -
Subject digest:
248f4221cabc18d6c676393ddf2c500ae2cf4cae54ea0b2aa853ef97019e2668 - Sigstore transparency entry: 2593044510
- Sigstore integration time:
-
Permalink:
DhyeyMavani2003/chipfiring@5dd6d207dbbe99abf8db9bdf9681df0f49188f2e -
Branch / Tag:
refs/tags/v1.1.4 - Owner: https://github.com/DhyeyMavani2003
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@5dd6d207dbbe99abf8db9bdf9681df0f49188f2e -
Trigger Event:
release
-
Statement type: