Particle Lenia
cax.cs.particle_lenia.cs.ParticleLenia
Bases: ComplexSystem
Particle Lenia class.
Source code in src/cax/cs/particle_lenia/cs.py
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 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 | |
__init__(num_spatial_dims, *, T, kernel_fn=peak_kernel_fn, growth_fn=exponential_growth_fn, rule_params)
Initialize Particle Lenia.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num_spatial_dims
|
int
|
Number of spatial dimensions (e.g., 2 for 2D, 3 for 3D). Determines the dimensionality of particle positions and field computations. |
required |
T
|
int
|
Time resolution controlling the temporal discretization. Higher values produce smoother temporal dynamics with smaller update steps. |
required |
kernel_fn
|
Callable
|
Callable that computes pairwise kernel weights between particles based on their distance. Takes rule parameters and returns kernel values. |
peak_kernel_fn
|
growth_fn
|
Callable
|
Callable that maps kernel field values to growth field values. Defines how particles respond to their local neighborhood density. |
exponential_growth_fn
|
rule_params
|
ParticleLeniaRuleParams
|
Instance of ParticleLeniaRuleParams containing kernel and growth parameters such as radii, peak positions, widths, and heights. |
required |
Source code in src/cax/cs/particle_lenia/cs.py
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 | |
render(state, *, resolution=512, extent=15.0, particle_radius=0.3, type='UG')
Render state to RGB image.
Renders Particle Lenia state as particles optionally overlaid on field visualizations. Particles appear as blue circles. The background can show kernel field (U), growth field (G), or energy field (E) to visualize the underlying dynamics driving particle motion. Field visualizations use color mapping to represent field intensities across space.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
State
|
Array of shape (num_particles, num_spatial_dims) containing particle positions in continuous space. Currently only 2D visualization is supported. |
required |
resolution
|
int
|
Size of the output image in pixels for both width and height. Higher values produce smoother field gradients but increase computation cost. |
512
|
extent
|
float
|
Half-width of the viewing area in coordinate space. The view spans from -extent to +extent in each dimension. Adjust to zoom in or out on the particle system. |
15.0
|
particle_radius
|
float
|
Radius of each particle in coordinate space. Particles are drawn as smooth circles with anti-aliased edges. |
0.3
|
type
|
str
|
Visualization mode determining what fields to display: "particles": Only show particles on white background (default). "UG": Show particles overlaid on kernel (U) and growth (G) field visualization. "E": Show particles overlaid on energy field visualization. |
'UG'
|
Returns:
| Type | Description |
|---|---|
Array
|
RGB image with dtype uint8 and shape (resolution, resolution, 3), showing particles and optionally the underlying field structure that drives their motion. |
Source code in src/cax/cs/particle_lenia/cs.py
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 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 | |
__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.
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
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 | |