Vivarium
Vivarium is a digital terrarium that I built to combine my love of genetic algorithms and emergence with my hobby of homelabbing.
The creatures
Each creature is an arrow, pointing where it's headed. They each spawn with a set of genes that determine their physical aspects: how much energy they need to stay alive, what color they are, how fast they are, how quick they can turn, what they can consume, etc. Additionally, they each have their own brain (explained below). When using diet view colour shows its diet:
- eats plants
- eats a mix of corpses and plants
- eats other creatures and corpses
The brains
Brains are a set of nodes and connections. Creatures are generated with a brain that is slightly mutated from it's parent's brains. Mutations can include adding/removing nodes, adding/removing connections, or changing the strength of existing connections. In this simulation brains have 32 inputs or "senses" and 3 outputs. You can hover over nodes on graph to see what each input/output is.
This type of "brain" architecture is called NEAT (NeuroEvolution of Augmenting Topologies), a genetic algorithm developed by Risto Miikkulainen and Kenneth Stanley. While I have strayed from their original implementation of NEAT slightly, the general principle remains the same.
Emergence
Creatures that survive long enough and acquire enough energy have babies, which inherit slightly changed brains and bodies. Over time more "fit" creatures become more common. This opens the door to the predator/prey arms race, as predators become more adept they increase the selection pressure on the rest of the population to become better at avoiding predators, which increases the pressure on the predator population to become better at catching prey, and so on.
The Vivarium
The vivarium is a 2D environment I generated for the creatures to live in. Coloured zones indicate different habitats (yellow=grassland, green=forest, blue=wetland, red=scrub), shaded patches are cover to hide from predators in, and the scattered dots are food pellets (brown) and corpses (dark red). The yellow ring is a drifting hotspot that spawns additional food pellets, adding a moving surplus of food to compete over.
The walls (black blocks) are occasionally interrupted by impassible terrain (yellow blocks), which become navigable for 500 ticks every 10000 ticks, allowing migration between habitats.
Enjoy
Click any creature to view its brain and stats. Maybe check in once in a while to see if any of them have figured out how to avoid running into walls for extended periods of time.
About
I had previously worked on similar "deskpet" style simulations but always ran into the brick wall of computation. I wanted a world with each creature running its own brain, but that meant computing each creature's brain state each tick, then completing their intention in the simulation engine, then refeeding the new inputs into all of the brains again.
By repurposing an old GTX 1050ti graphics card and 16GB of DDR3 RAM I can compute many times my previous limit of brains at the same time since GPUs are optimized to run the same calculation in parallel at a massive scale, making it the perfect platform to simulate my brains on. Overall this simulation runs relatively cheaply on the 1050ti at about a 400MB memory footprint with a population around 1000. This leaves plenty of room for further workloads on the GPU, such as local LLMs in the 9B parameter range or using it as a remote render server.