CellPyLib
raw JSON → 2.4.0 verified Sat May 09 auth: no python
CellPyLib is a Python library for working with Cellular Automata, supporting 1D and 2D automata with various rules (e.g., Rule 30, Conway's Game of Life). Current version 2.4.0 requires Python >3.6. The library is actively maintained with a focus on simulation, visualization, and analysis.
pip install cellpylib Common errors
error TypeError: evolve() got an unexpected keyword argument 'apply_rule' ↓
cause Using old v1.x API where evolve accepted 'rule' parameter instead of 'apply_rule'.
fix
Upgrade to v2.x and change 'rule' to 'apply_rule': cpl.evolve(ca, timesteps=100, apply_rule=...) or for v1.x use evolve(ca, timesteps=100, rule=...)
error AttributeError: module 'cellpylib' has no attribute 'cellular_automaton' ↓
cause Attempting to import 'cellular_automaton' as a function; it is not a top-level function but a class or incorrect import pattern.
fix
Use import cellpylib as cpl and then cpl.init_simple(), cpl.evolve() etc.
error ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all() ↓
cause Trying to use a rule function that returns a vector instead of a single value, common in custom rules.
fix
Ensure the rule function returns a single integer (0 or 1) per cell.
Warnings
breaking In v2.x, the 'evolve' function signature changed. The 'apply_rule' parameter now expects a function with three arguments (n, c, g) instead of two (n, c). Update your custom rules accordingly. ↓
fix Change rule function signature from lambda n, c: ... to lambda n, c, g: ...
gotcha init_simple() expects a tuple (rows, cols) for 2D, but many users mistakenly pass a single integer for 1D. For 1D, pass the size as an integer, for 2D pass a tuple. ↓
fix For 1D: init_simple(100). For 2D: init_simple((50,50)).
gotcha Plotting requires Matplotlib to be installed separately. It is not a dependency of cellpylib. ↓
fix Install matplotlib: pip install matplotlib
Imports
- cellular_automaton wrong
from cellpylib import cellular_automatoncorrectimport cellpylib as cpl - init_simple
from cellpylib import init_simple - evolve
from cellpylib import evolve
Quickstart
import cellpylib as cpl
import matplotlib.pyplot as plt
# Initialize a 1D cellular automaton (Rule 30, size 100)
cellular_automaton = cpl.init_simple(100)
# Evolve for 100 time steps
cellular_automaton = cpl.evolve(cellular_automaton, timesteps=100, apply_rule=lambda n, c, g: cpl.nks_rule(n, 30))
# Plot the result
plt.imshow(cellular_automaton, cmap='binary')
plt.show()