Petri nets, from water to a lizard that heals
A Petri net is a drawing of a process that you can run. It has two kinds of node and one rule, and that is enough to describe chemistry, factory lines, network protocols and, as it turns out, a lizard that grows back when you cut it.
Carl Adam Petri set them out in his 1962 doctoral thesis, Kommunikation mit Automaten. By his own account he had first sketched them as a teenager, to keep track of chemical reactions. That origin shows: a Petri net is at heart a way of counting stuff as it turns into other stuff.
The parts
- Places are circles. They hold tokens, drawn as dots. A token is one unit of whatever the place stands for: a molecule, a part on a conveyor, a free slot in a buffer.
- Transitions are bars. They are the things that can happen.
- Arcs connect places to transitions and transitions to places, never place to place or bar to bar. An arc can carry a weight, the number of tokens it moves at once.
The tokens sitting in each place at a given moment are the net’s marking. The marking is the whole state of the system.
The rule
A transition is enabled when every place feeding it holds at least as many tokens as its arc asks for. An enabled transition may fire: it removes tokens from its input places and adds tokens to its output places, as the arc weights say.
That is the only rule. Nothing says which enabled transition fires next, or when.
Making water
The picture at the top is one reaction, 2 H₂ + O₂ → 2 H₂O, as a net. The arc from H₂ has weight 2, the arc from O₂ has weight 1 and the arc into H₂O has weight 2.
| Marking | H₂ | O₂ | H₂O |
|---|---|---|---|
| Start | 4 | 2 | 0 |
| After one firing | 2 | 1 | 2 |
| After two firings | 0 | 0 | 4 |
After two firings neither input place has enough tokens, so the transition is no longer enabled and the net stops. Hydrogen atoms are conserved on every step: four H₂ give eight hydrogen atoms, and so do four H₂O. Properties like this, quantities that no firing can change, are called invariants, and you can read them straight off the arc weights without running anything.
Concurrency and conflict
Two transitions that share no input places can fire in either order, or at the same time, with the same result. That is concurrency, and Petri nets show it for free, which is a big part of why they became a standard tool for distributed systems.
Two transitions that both need the last token in a shared place are in conflict: whichever fires first disables the other. A mutex is a single place with one token and two processes reaching for it.
Most of the classic questions about a net are about where it can go:
- Reachability: can the net ever get from this marking to that one?
- Boundedness: can a place grow without limit, like a queue that is never drained?
- Liveness: can every transition always fire again eventually, or can the net deadlock?
From counting to chemistry
Give a net a lot of tokens and let transitions fire at random, at a rate proportional to the product of their input counts. That is mass action, the same rate law textbook chemistry uses. With enough tokens the counts behave like concentrations, and the net becomes a set of chemical rate equations.
Physics adds one more constraint. If every transition has a reverse and the rates obey detailed balance, the net always relaxes to equilibrium: a single dull marking where every forward step is matched by its reverse. To hold a pattern away from that, something has to keep paying, the way a living cell burns fuel.
A lizard on a lattice
The Mirages page puts that to work. It is a 40 × 40 lattice with the same small Petri net at every site. Each net has places for ink (the picture), for blank paper, for four signalling tokens called morphogens, and for seed tokens. Tokens hop between neighbouring sites. Every site shares one set of rate constants, and a constant supply of chemical fuel drives the whole thing.
The rates were trained so that, starting from a seed, the lattice draws a lizard.
You can do three things to it:
- Wound it. Click or drag to wipe a disc back to blank. The wound resets ink, blank and the four morphogens to their equilibrium counts, but leaves the seed tokens alone because no transition consumes them. The rates are frozen and the fuel is still flowing, so the net redraws the patch.
- Take the seeds too. Tick the box that makes wounds also remove seed tokens and wound it again. Now the positional information is gone and the patch stays blank.
- Cut the fuel. Slide the fuel drive to zero. Every transition still follows the same rate law, but with no free energy the lattice relaxes to equilibrium paper, about 4.7% ink everywhere, and the fuel-burned counter reads zero. Slide it back up and the lizard returns.
The fuel counter is in kT per site per time unit, so you can see what the picture costs to keep.
The built-in model is a short run trained on a CPU, which is why the lizard is blurry. The page can load a better trained model from a JSON file.
Why bother
A neural network could draw a lizard more sharply. The point of doing it with a Petri net is that every step is a reaction that could, in principle, happen in a test tube. Each step conserves what it should, obeys a real rate law and pays its thermodynamic bill, and you can audit all three. The same picture of places, transitions and tokens that balances an equation for water also says exactly what a self-repairing pattern needs: something to remember where it is, and a steady supply of fuel.