Differentiable Cellular Automata Learn to Grow and Regenerate

Distill.pub published an article on Growing Neural Cellular Automata, part of their Differentiable Self-organizing Systems Thread. The key insight: you can use gradient-based optimization to train a cellular automaton (CA) that starts from a single cell and grows into a predefined 2D pattern, then regenerates after damage.

The Model: Continuous States and Differentiable Updates

Traditional CAs use discrete states (e.g., alive/dead). This model uses a vector of 16 continuous real values per cell. The first three channels are RGB color; the fourth is alpha (α) marking living cells (α > 0.1). The remaining 12 channels are hidden — the update rule can use them for internal signaling, analogous to chemical concentrations in biology.

The update rule is a neural network with ~8,000 parameters. It operates on each cell's perception vector, which concatenates the cell's own state with gradients computed via fixed Sobel filters (3x3 convolutions estimating partial derivatives in x and y). The network outputs a delta to the cell state, applied incrementally. Crucially, the final layer's weights are initialized to zero, so the rule initially does nothing — the network learns to make changes from scratch.

def perceive(state_grid):
    sobel_x = [[-1, 0, +1],
               [-2, 0, +2],
               [-1, 0, +1]]
    sobel_y = transpose(sobel_x)
    grad_x = conv2d(sobel_x, state_grid)
    grad_y = conv2d(sobel_y, state_grid)
    perception_grid = concat(state_grid, grad_x, grad_y, axis=2)
    return perception_grid

def update(perception_vector):
    x = dense(perception_vector, output_len=128)
    x = relu(x)
    ds = dense(x, output_len=16, weights_init=0.0)
    return ds

Stochastic Updates and Living Cell Masking

Real cells don't update synchronously. The model applies a random per-cell mask during training, zeroing out 50% of updates (like dropout). This forces the system to be robust without global coordination. Dead cells (those with α ≤ 0.1 and no living neighbor) are reset to zero each step, preventing ghost patterns.

Training: From Seed to Pattern

The CA is trained by starting with a single living cell (a seed with α=1.0 and target color) and running for N steps. The loss function compares the final state to a target image (e.g., a lizard shape). Gradients flow back through the entire sequence of updates, optimizing the network parameters. The authors used 64x64 grids and 48 training steps, with batch size 64.

Results: Growth and Regeneration

The trained CA reliably grows the target pattern from a single seed. More impressively, after the pattern is grown, if you damage it (e.g., remove a chunk), the CA self-repairs over subsequent steps. The hidden channels encode positional information — the network learns to use them as a coordinate system to know where each cell is relative to the whole.

Why This Matters for Developers

This work bridges differentiable programming and self-organizing systems. The same techniques could apply to:

  • Designing self-repairing soft robotics
  • Generating textures or structures in games
  • Understanding biological morphogenesis computationally

The code is open-source (link in article) and runs on standard ML frameworks (PyTorch, TensorFlow). You can train your own patterns with minimal changes.

Technical Depth: The Perception-Action Loop

The use of Sobel filters for perception is a deliberate choice — it's biologically plausible (cells sense gradients) and keeps the network small. The update network is just two dense layers with ReLU, plus a zero-initialized output layer. This minimal architecture is surprisingly powerful: it learns to coordinate thousands of cells to form complex shapes.

Stochastic updates are crucial. Without them, the model relies on global sync and fails to regenerate after damage. The dropout-like mask forces cells to work asynchronously, which is more realistic and robust.

Limitations and Open Questions

The model only works on 2D grids with simple patterns. Scaling to 3D or more complex anatomies remains challenging. The authors note that the hidden channels often encode a "chemical gradient" that dissipates from the seed, but the representation isn't interpretable. Also, training requires many steps (48) and careful hyperparameter tuning.

Editor's Take

I've spent years playing with CAs in my spare time, and this paper made me rethink what's possible. The idea of training a CA end-to-end with backprop is elegant — it's like evolution, but with gradients. I immediately tried replicating the results with my own patterns. The regeneration behavior blew me away: after cutting a grown lizard in half, each half regrows into a full lizard. That's not something you see in traditional CAs. My only gripe: the article doesn't discuss failure modes. What happens if you train on a pattern with holes? Does the CA learn to skip those? I'd love to see more analysis of what the hidden channels encode. Overall, this is a must-read for anyone interested in self-organizing systems or differentiable programming.

Developer Insights

  • The code is available at the Distill.pub article; you can train your own patterns by replacing the target image and adjusting the grid size.
  • The model uses ~8,000 parameters — tiny by deep learning standards. You can run inference on a CPU in real time.
  • To apply this to 3D or irregular grids, you'd need to replace the Sobel filters with a graph neural network or 3D convolutions.

Why It Matters

This work provides a practical framework for training self-organizing systems with deep learning. If you build games, simulations, or robotics, you can now grow structures that self-repair without explicit programming. It's a step toward software that builds itself.