Simulation··3 min read
Shapes That Flow
Mandatory blog post: the culmination of my PhD is sort of live. Go read it.
I’ve been explaining my work to my professor, to my fellow students, over coffee, to family members and to my friends from various online communities. It’s such a mixture of concepts and fields that my major challenge was not actually coding up the maths.
Nowadays most people I talk to are life, physical or computer scientists, and very few have an AI background, so I lead with this hook:
You know about language models, right? Do you ever find it strange that the people who make them can have a trillion learnable parameters to optimise? While if you have more than 10 parameters in your experiment, you’ll be trying them out till the heat death of the universe (or just a burnout).
Then I tell them how the AI/deep learning guys CHEAT with something called automatic differentiation.
A neural network is made of neurons, which are tiny functions with a few learnable parameters each. You feed it some input (are these pixels a dog or a bagel?), and the framework keeps track of every single operation that produces the output, in what’s called a computation graph. With that graph it can go backwards from how wrong the answer was, the loss, and answer the question ∂loss/∂parameters. So you tweak all of them simultaneously, and the next time you do the same forward computation the answer comes out slightly less incorrect.
You can write any maths or physics simulation the same way and get ∂loss/∂anything. With modern computers, all you need is a computation graph. Here’s an arbitrary formula, tanh(sin(x²) + 0.3x), with x as the only parameter:
The one objection I get from people who actually visualise this is “yeah, but now you’re tweaking the physics”. No, no. My learnable parameters aren’t neurons but whatever I have at the start: the shape of my device, the flow rate, the frequency of an AC generator.
Shape is the tricky one, because a normal CAD drawing is points and lines that get chopped into a mesh, and once it’s a mesh the pillar’s radius isn’t in the calculation any more, so you can’t take a derivative with respect to it. So I draw with signed distance functions instead, formulas that take a point and return how far it is from the nearest wall. A pillar is then one line of maths with its position and radius in it, and the drawing becomes the first step of the computation graph, followed by the flow (lattice Boltzmann, written in F# with DiffSharp) and the dye.
Here’s that graph with fifty pillars, an x, a y and a radius each, and a request for 80%, 80% and 20% dye at the three outlets:
Sourabh from my group made the chip, big thanks to him. He tested it under a microscope (it’s tiny, check my interactive paper to get a feeling for the scale), and it looks so close to the simulated one that I haven’t had a single person yet realise they’re looking at a real photograph :)
Marrying differentiable shape with differentiable physics is the whole point of Shapes That Flow. The same code also designed a mixer after I changed only the loss, and a heat sink after I swapped the flow solver for heat conduction. The rest of the rabbit hole is in the paper.
Next week I’m presenting it as a poster at MNE 2026 in Interlaken.
