Skip to content

Conversation

@Bearwynn
Copy link

@Bearwynn Bearwynn commented Nov 4, 2025

Add Cellarium: A Cellular Automata Framework for EuroPi

Overview

Cellarium is a high-performance cellular automata framework designed for the EuroPi platform. It provides a flexible, extensible system for running various cellular automata simulations with CV input/output mapping for modular synthesis integration.

NOTE: since there is heavy use of Viper decorator tags, this will fail testing until they are included in the test handling.

Key Features

  • MicroPython-optimized simulation engine with bit-parallel processing
  • Seven included automata implementations:
    • Conway's Game of Life
    • Brian's Brain
    • Rule 30 (Elementary CA)
    • Rule 90 (Elementary CA)
    • Langton's Ant
    • Droplets (A completely unique water simulation)
    • Seeds
  • Real-time CV input/output mapping
  • Multi-threaded display and simulation processing
  • Configurable simulation parameters
  • Stasis detection and response system

Technical Details

Controls

  • B1/B2: Mode selection and configuration
  • K1: Food value control (population growth)
  • K2: Tick rate limiter (simulation speed)
  • DIN: Reset/Feed/Clock input
  • AIN: Food/Tick rate modulation
  • CV1-4: Automaton-specific outputs
  • CV5: Stasis indication
  • CV6: Simulation tick gate

Performance Considerations

  • Optimized for original Pico hardware limitations
  • Maintains backwards compatibility with older hardware
  • Careful memory management and buffer reuse
  • Efficient bit manipulation techniques
  • Thread-safe simulation processing

Documentation

  • Full implementation guide in cellarium.md
  • Docstrings for all classes and methods
  • Performance optimization tips
  • Example patches and use cases
  • Implementation guidelines for new automata

Testing

  • Tested on EuroPi hardware
  • Performance validated on original Pico

Labels

  • CV Generation
  • CV Modulation
  • Clock Source
  • Random
  • Envelope Generator
  • LFO
  • Controller

# Add Cellarium: A Cellular Automata Framework for EuroPi

## Overview
Cellarium is a high-performance cellular automata framework designed for the EuroPi platform. It provides a flexible, extensible system for running various cellular automata simulations with CV input/output mapping for modular synthesis integration.

## Key Features
- MicroPython-optimized simulation engine with bit-parallel processing
- Six included automata implementations:
  - Conway's Game of Life
  - Brian's Brain
  - Rule 30 & Rule 90 (Elementary CA)
  - Langton's Ant
  - Water Droplets Physics
  - Seeds
- Real-time CV input/output mapping
- Multi-threaded display and simulation processing
- Configurable simulation parameters
- Stasis detection and response system

## Technical Details
- Uses byte-parallel operations for performance
- MicroPython optimization with @viper and @Native decorators
- Thread-safe buffer management
- Memory-efficient bit field operations
- Automatic garbage collection management
- Configurable CV division ratios

## Controls
- B1/B2: Mode selection and configuration
- K1: Food value control (population growth)
- K2: Tick rate limiter (simulation speed)
- DIN: Reset/Feed/Clock input
- AIN: Food/Tick rate modulation
- CV1-4: Automaton-specific outputs
- CV5: Stasis indication
- CV6: Simulation tick gate

## Performance Considerations
- Optimized for original Pico hardware limitations
- Maintains backwards compatibility with older hardware
- Careful memory management and buffer reuse
- Efficient bit manipulation techniques
- Thread-safe simulation processing

## Documentation
- Full implementation guide in cellarium.md
- Docstrings for all classes and methods
- Performance optimization tips
- Example patches and use cases
- Implementation guidelines for new automata

## Testing
- Tested on EuroPi hardware
- Performance validated on original Pico

## Labels
- CV Generation
- CV Modulation
- Clock Source
- Random
- Envelope Generator
- LFO
- Controller
remove example automata as it's not needed, included scripts are example enough.
@Bearwynn
Copy link
Author

Bearwynn commented Nov 4, 2025

Just a note, if desired the performance tips included within cellarium.md can be pulled out and instead submitted as a separate .md guide to a more common location with the repository.

@Bearwynn
Copy link
Author

Bearwynn commented Nov 4, 2025

My main concerns at the moment revolve around file size, by creating the framework I have circumvented quite a bit of code duplication when adding multiple cellular automata, but the file sizes can still be a little heavy due to some of the optimisations.
I am looking to try and take as much shared functionality as I can and move it to a shared location, but it may take some time.

from ucollections import OrderedDict

# Local imports
from contrib.cellarium_docs.automata_registry import get_automata_by_index, get_automata_names
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of putting the extra modules in the *_docs directory, can you put them in firmware/experimental/automata instead? Generally any shared code/modules get put in experimental. The _docs directories shouldn't contain any executable code, just text and any supporting doc files (e.g. images, PDFs, etc...).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, can do!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thinking about it more, perhaps instead of firmware/experimental it might make more sense to keep it in contrib/automata? Unless you're hoping to share these across multiple contrib scripts they probably don't need to go in firmware.

The CI does a lot more formatting & linting checks on things put in the firmware directory. We turn most of that off for contrib since each program is generally assumed to be self-contained and wanted to keep the barrier to entry low for beginners who wanted to contribute code.

Copy link
Author

@Bearwynn Bearwynn Nov 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm that's probably a good idea.
They are quite bespoke to the cellarium script so it makes sense to not have it's presence within firmware mislead people.
I think Contrib/Automata makes sense but do you think it may make sense to have a Contrib/Supplementary/Cellarium folder or other such names sub directory?

I guess it depends on how likely it is for others to take a multi-file script approach.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keeping the additional-module directory the same (or broadly similar) to the base script it's from makes sense to me. Currently the only other multi-file programs use experimental for their extra stuff (because it's all shared across multiple programs). I don't think contrib/supplementary/* is necessary at this point.

A couple of years ago when I was first starting to share pieces between scripts (e.g. using the Euclidean pattern generator or quantizers in multiple programs) there was discussion about how to organize things. If we start getting more multi-file contrib programs we can definitely revisit that question, but for now I'm not too concerned.

def on_b2():
show_settings = False
b2_mode = list(self.MODES_B2.keys())[self.b2_idx]
if b2_mode == 'D IN':
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally in EuroPi nomenclature we don't include the space in ain or din (or their all-caps equivalents). Not a big deal, but if these strings are ever visible to the user I'd prefer if they used the same formatting as the official docs.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Acknowledged :) makes sense to match the official docs

self.din_idx = (self.din_idx + 1) % len(self.MODES_DIN)
mode = list(self.MODES_DIN.keys())[self.din_idx]
show_settings = True
elif b2_mode == 'A IN':
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above: consider using AIN instead if A IN.

self.num_alive = self.num_alive + born_died_diff

# Atomic swap under lock
with self._buf_lock:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per the docs the with keyword doesn't appear to be supported by the micropython.native code emitter.

It looks like it's used a few times in this function. Should these be refactored to not use the with keyword?

self.update_inputs()
self.reset()
#Start ASYNC display thread
if not self._display_thread_started:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you checking if the thread's started before starting it? Nothing ever sets this flag to False after initialization, so shouldn't this thread always get started?

module, clazz = automaton_class_name.rsplit(".", 1)
return getattr(__import__(module, None, None, [None]), clazz)
except Exception as e:
log_warning(f"Warning: Invalid automaton class name: {automaton_class_name}\n caused by: {e}", "cellarium")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need to add Warning: to the start of the log strings; the log_warning function automatically adds a [warn] prefix to the messages to make the level clear.

@chrisib
Copy link
Collaborator

chrisib commented Nov 28, 2025

Gave the code a quick first-pass. It looks good, but I have a few questions and some suggestions for how to better-organize it. The biggest issue I see is having executable code in the _docs directory.

@Bearwynn
Copy link
Author

Nice, thank you for your time!
I'll try and get around to responding to the review soon, been a bit busy since it's the start of the Christmas season 😂

I also wasn't sure on the docs folder, so expected there to need a change there :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants