Skip to content

Repository files navigation

Von Neumann Self-Replicating Automata - Complete Package

🔧 Fixing the Display Refresh Issue

You encountered a common matplotlib animation problem where the display only updates when you resize the window. This happens because:

  1. Animation framework issues: Some FuncAnimation settings cause refresh problems
  2. Backend compatibility: The matplotlib backend may not handle automatic updates
  3. Event loop conflicts: Display events aren't being processed correctly

✅ Solution: Use the Interactive GUI

I've created a fixed version that solves this problem:

python automata_interactive_gui.py

Key fixes implemented:

  • blit=False in FuncAnimation (critical!)
  • cache_frame_data=False to prevent caching
  • fig.canvas.draw_idle() for proper event-driven updates
  • Proper event handling for controls

📁 Files Included

Core Scripts

  1. self_replicating_automata.py - Original simulator

    • 4 automaton types: Langton Loop, Evolving Loop, Von Neumann, Wire World
    • Basic visualization with matplotlib
    • Command-line interface
    • Can be imported as a library
  2. automata_interactive_gui.pyRECOMMENDED

    • Interactive matplotlib-based GUI
    • Fixes the display refresh issue
    • Play/Pause/Step/Reset controls
    • Speed and grid size sliders
    • Real-time statistics
    • Save snapshots
    • Works with standard matplotlib (no extra dependencies)
  3. automata_gui.py - Advanced tkinter GUI

    • Professional GUI framework
    • Threaded simulation
    • Progress bars for saving
    • More polished interface
    • Requires: python3-tk package
  4. quick_start.pyEASIEST TO USE

    • Just run this!
    • Launches the interactive GUI with helpful instructions
    • Checks dependencies
    • Provides troubleshooting tips
  5. display_diagnostic.py - Diagnostic tool

    • Tests different animation settings
    • Identifies backend issues
    • Provides specific recommendations
    • Run this if you have problems

Documentation

  1. README_automata.md - Original README

    • Theoretical background
    • Von Neumann's concepts
    • Current research (2024-2025)
    • Usage examples
    • Extension guide
  2. GUI_GUIDE.md - Comprehensive GUI guide

    • Detailed explanation of the refresh fix
    • Comparison of GUI versions
    • Controls and features
    • Advanced usage
    • Troubleshooting
  3. README.md (this file) - Master guide

Sample Outputs

  1. langton_loop_snapshot.png - Example output
  2. evolving_loop_snapshot.png - Example output
  3. von_neumann_snapshot.png - Example output
  4. wireworld_snapshot.png - Example output

🚀 Quick Start (3 Steps)

1. Run the Simulator

python quick_start.py

2. Select Automaton Type

Click on the radio buttons:

  • Langton Loop - Classic self-replicator
  • Evolving Loop - With mutations (adjust rate with slider)
  • Von Neumann - Universal constructor demo
  • Wire World - Signal propagation

3. Control the Simulation

  • ▶ Play - Start running
  • ⏸ Pause - Pause
  • ⏭ Step - Advance one generation
  • 🔄 Reset - Create fresh automaton
  • Sliders - Adjust speed (10-500 ms) and grid size (50-300)
  • 📸 Save - Save current state as PNG

🔍 Which GUI Should I Use?

┌─────────────────────────────────────────────────────────┐
│  START HERE → python quick_start.py                     │
└─────────────────────────────────────────────────────────┘
                              │
                              ├─ Works? ──→ ✓ You're done!
                              │
                              └─ Issues? ──┐
                                           │
    ┌──────────────────────────────────────┘
    │
    ├─ Try: python automata_interactive_gui.py
    │        (Fixed matplotlib version)
    │
    ├─ Still issues? → python display_diagnostic.py
    │                  (Diagnose the problem)
    │
    └─ Have tkinter? → python automata_gui.py
                       (Professional version)

Decision Tree

Use automata_interactive_gui.py (recommended) if:

  • ✅ You want it to just work
  • ✅ You don't want extra dependencies
  • ✅ You had the refresh issue
  • ✅ You want built-in controls

Use automata_gui.py if:

  • ✅ You have tkinter installed
  • ✅ You want the most polished interface
  • ✅ You need threaded performance
  • ✅ You want progress bars for saving

Use self_replicating_automata.py if:

  • ✅ You want to import as a library
  • ✅ You're writing your own GUI
  • ✅ You need programmatic control
  • ✅ You want to extend the classes

💡 Understanding the Fix

The Problem

Original animation code that can fail:

# ❌ Can cause refresh issues
anim = FuncAnimation(fig, update, interval=50, blit=True)
plt.show()

The Solution

Fixed animation code:

# ✅ Reliable refresh
anim = FuncAnimation(
    fig, 
    update, 
    interval=50,
    blit=False,              # Critical!
    cache_frame_data=False   # Also important!
)
plt.show()

Why This Works

blit=False:

  • Disables "blitting" optimization
  • Blitting can skip screen updates on some systems
  • Slower but more reliable

cache_frame_data=False:

  • Prevents matplotlib from caching frames
  • Ensures fresh data every update
  • Fixes stale display issues

Event-driven updates:

  • Uses fig.canvas.draw_idle() instead of draw()
  • Schedules updates properly in the event loop
  • Prevents conflicts with window manager

📊 Features Comparison

Feature Original Interactive GUI Tkinter GUI
Refresh fix
Play/Pause
Step control
Speed slider
Grid size control
Statistics
Save snapshots Manual ✅ Button ✅ Button
Extra dependencies None None tkinter
Threading
Polish level Basic Good Professional

🛠️ Installation

Minimal (Interactive GUI)

pip install matplotlib numpy
python automata_interactive_gui.py

Full (Tkinter GUI)

# Install tkinter first
sudo apt-get install python3-tk  # Ubuntu/Debian
# or
brew install python-tk            # macOS

# Install Python packages
pip install matplotlib numpy

python automata_gui.py

🧪 Testing

1. Quick Test

python quick_start.py

2. Diagnostic Test

python display_diagnostic.py

This will:

  • Check your matplotlib backend
  • Test different animation settings
  • Provide specific recommendations
  • Show what's working/not working

3. Manual Test

from automata_interactive_gui import InteractiveAutomatonGUI

gui = InteractiveAutomatonGUI()
gui.show()  # Should update smoothly when you click Play

📖 Usage Examples

Basic Usage

# Easiest way - just run it!
python quick_start.py

# Or directly
python automata_interactive_gui.py

Programmatic Control

from self_replicating_automata import LangtonLoop

# Create automaton
automaton = LangtonLoop(150, 150)

# Run simulation
for i in range(100):
    automaton.step()
    print(f"Generation {i}: {np.count_nonzero(automaton.grid)} active cells")

# Access the grid
print(automaton.grid.shape)

Custom Visualization

from automata_interactive_gui import InteractiveAutomatonGUI
import matplotlib.pyplot as plt

# Create custom GUI
gui = InteractiveAutomatonGUI()

# Modify before showing
gui.speed_ms = 25  # Faster updates
gui.grid_size = 200  # Larger grid

gui.show()

🔧 Troubleshooting

Display still not updating?

  1. Check your backend:
python -c "import matplotlib; print(matplotlib.get_backend())"
  1. Try a different backend:
import matplotlib
matplotlib.use('Qt5Agg')  # or TkAgg, GTK3Agg
  1. Run the diagnostic:
python display_diagnostic.py
  1. Update matplotlib:
pip install --upgrade matplotlib

Performance issues?

  • Reduce grid size (use slider or set to 50-100)
  • Increase speed interval (slower updates)
  • Use Wire World (simplest automaton)
  • Close other applications

Import errors?

# Make sure all files are in the same directory
ls -l *.py

# Check dependencies
pip list | grep -E "(matplotlib|numpy)"

# Reinstall if needed
pip install --force-reinstall matplotlib numpy

📚 Learn More

Theoretical Background

See README_automata.md for:

  • Von Neumann's original concepts
  • History of self-replicating automata
  • Current research (2024-2025)
  • Mathematical foundations
  • Biological parallels

GUI Details

See GUI_GUIDE.md for:

  • Complete feature list
  • Advanced usage
  • Customization examples
  • Integration with your research
  • Technical implementation details

Research Context

Von Neumann's work (1940s-1950s) predated the discovery of DNA but arrived at similar concepts:

  • Self-description (genetic code)
  • Universal construction (ribosomes)
  • Information duplication (replication)

Recent developments (2024-2025):

  • 25th anniversary of evoloops
  • Renewed interest in open-ended evolution
  • Continuous cellular automata
  • Physical implementations

🎯 Next Steps

  1. Run the simulator - Start with quick_start.py
  2. Experiment - Try different automaton types and parameters
  3. Observe - Watch self-replication in action
  4. Extend - Create your own automaton variants
  5. Analyze - Export data and study patterns

Ideas for Extension

Given your microscopy background:

  • Adapt for modeling PIEZO1 clustering
  • Simulate calcium wave propagation
  • Test segmentation algorithms
  • Model particle interactions

📝 Citation

If you use this code in your research:

Von Neumann Self-Replicating Automata Simulator
Based on: von Neumann, J. (1966). Theory of Self-Reproducing Automata
Implementation: 2024

🆘 Support

If you encounter issues:

  1. Read the error message - Often points to the solution
  2. Run diagnostics - python display_diagnostic.py
  3. Check documentation - GUI_GUIDE.md has detailed troubleshooting
  4. Try alternative GUI - If one doesn't work, try the other
  5. Update packages - Make sure matplotlib/numpy are current

✨ Summary

Problem: Display only refreshes when resizing window Solution: Use automata_interactive_gui.py with fixed animation settings Quick Start: Run python quick_start.py Need Help: Run python display_diagnostic.py

The simulator now has:

  • ✅ Proper display refresh
  • ✅ Interactive controls
  • ✅ Real-time statistics
  • ✅ Easy parameter adjustment
  • ✅ Multiple automaton types
  • ✅ Save functionality

Enjoy exploring self-replicating automata! 🔬✨


Created for George Dickinson's Lab - Bioinformatics & Cellular Automata Research


Built with AI assistance from Claude (Anthropic).

About

interactive visualizations of several types of self-replicating cellular automata, inspired by John von Neumann's pioneering work on artificial self-reproduction

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages