Abelian Sandpile
cax.cs.sandpile.cs.Sandpile
Bases: ComplexSystem[Array, Array]
Abelian Sandpile model.
A discrete cellular automaton demonstrating self-organized criticality. The state is a grid of non-negative integers representing chip counts. When a cell reaches the critical threshold, it topples, distributing chips to neighbors. Cascading avalanches of topplings produce power-law distributed events.
Two boundary modes are supported
- "CIRCULAR": periodic (toroidal) boundaries conserving total mass.
- "OPEN": dissipative boundaries where sand falling off the edge is lost, which is required for proper self-organized criticality.
Source code in src/cax/cs/sandpile/cs.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 | |
__init__(*, num_spatial_dims=2, threshold=None, padding='CIRCULAR')
Initialize Sandpile.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num_spatial_dims
|
int
|
Number of spatial dimensions (default 2). |
2
|
threshold
|
int | None
|
Critical chip count for toppling. Defaults to 2 * num_spatial_dims (4 in 2D, 6 in 3D). |
None
|
padding
|
Literal['CIRCULAR', 'OPEN']
|
Boundary condition mode. "CIRCULAR" for periodic boundaries, "OPEN" for dissipative boundaries (required for SOC). |
'CIRCULAR'
|
Source code in src/cax/cs/sandpile/cs.py
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | |
render(state)
Render state to RGB image.
Maps chip counts to distinct colors using the classic sandpile palette: 0 chips → dark blue, 1 chip → cyan, 2 chips → yellow, 3 chips → orange. Cells at or above the critical threshold are rendered in red.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
Array
|
Array with shape (..., *spatial_dims, 1) containing integer chip counts stored as float32. |
required |
Returns:
| Type | Description |
|---|---|
Array
|
RGB image with dtype uint8 and shape (..., *spatial_dims, 3). |
Source code in src/cax/cs/sandpile/cs.py
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 | |
__call__(state, input=None, *, num_steps=1, input_in_axis=None, sow=False)
Step the system for multiple time steps.
This method wraps _step inside a JAX scan for efficiency and JIT-compiles the loop.
If input is time-varying, set input_in_axis to the axis containing the time
dimension so that each step receives the corresponding slice of input.
When remat is enabled, the scan body is wrapped with nnx.remat to reduce memory
usage during backpropagation at the cost of recomputing intermediates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
State
|
Current state. |
required |
input
|
Input | None
|
Optional input. |
None
|
num_steps
|
int
|
Number of steps. |
1
|
input_in_axis
|
int | None
|
Axis for input if provided for each step. |
None
|
sow
|
bool
|
Whether to sow intermediate values. |
False
|
Returns:
| Type | Description |
|---|---|
State
|
Final state after |
Source code in src/cax/core/cs.py
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 | |