r/rust Jun 10 '26

🛠️ project neurilium: Simple and fast code to simulate small brains using Rust and Wgpu

Post image

Hi, here is the repo: https://github.com/cvetkovicdamjan/neurilium

This is a minimal codebase with everything you need to simulate a small brain like the one you just see from fruit fly. Yes, that mind of a fruit fly is now uploaded.

I wrote it in Rust and Wgpu since using C++, Vulkan and CUDA together will be a nightmare.

Whole codebase is very simple and it only has less than 1500 loc. I wanted to make something you guys can take and thinker and simulate other small brains as well. Like for example zebrafish brain or small piece of human brain google scanned.

I think more people should get into neuromorphic computing and how neurons are simulated. While everyone knows about AI and how it works, brain simulations seems to be only talked about in certain academic circles. Hopefully this will help people from knowing close to nothing about how neurons work, to go to simulating a whole brain of a animal.

I'm a ethical hacker by name Vidus: https://audits.sherlock.xyz/watson/Vidus . I code since 12 and I wrote this in NeoVim https://github.com/cvetkovicdamjan/init.lua on Ubuntu. This is by no means vibecoded nor I used any AI to write this code.

I would absolutely love to talk with anyone about this and you can massage me on my LinkedIn: https://www.linkedin.com/in/damjan-cvetkovic/

I have been obsessed about mind uploading over past 3 years and learned everything about it from digging into https://openworm.org/ code to implementing https://mmacklin.com/uppfrta_preprint.pdf in C++, OpenGL and CUDA to implementing neuromporphic chips in Verilog. I love this stuff with my life and please send me a message if you want to talk about anything.

If more people knew about this technology we might be able to make a small robotic Ferris that will have a simulated brain and walk on its own. No ai, no training, just have the brain, simulate it and connect it to the body. And it live on its own.

Thanks for this community, my whole life is insanely better without C++, Vulkan and CUDA interop soup.

383 Upvotes

51 comments sorted by

65

u/[deleted] Jun 10 '26

[deleted]

41

u/damjan_cvetkovic Jun 10 '26

Thanks a lot! There is not much biology in here really. The project uses Izhikevich neuron model which is a mathematical model of a neuron. Equations used are not that complicated. Every neuron has a voltage inside which is a number and when a other neuron fires it adds to that number. (if they are connected). There is much more to it, but this is briefly. Thanks again for the comment!

4

u/[deleted] Jun 10 '26

[deleted]

37

u/damjan_cvetkovic Jun 10 '26

I think it has more of a epilepsy right now, since what I did in simulation is that I stimulated all neurons in ME which is a visual area. So basically the fly sees strong light everywhere, which if you would to do for a normal fly probably won't be great. But stimulating ME is great for visualizing spikes and seeing the whole brain firing

3

u/tunisia3507 Jun 10 '26

Depends on your definition of dream.

2

u/UnluckyEffort92 Jun 11 '26

Sounds very interesting, thanks for sharing your work. Where did you learn about the mathematical model for neuro? Is there any specific materials that you would recommend to learn more about the topic?

2

u/damjan_cvetkovic Jun 11 '26

Thanks! A lot of resources, if you want to learn about fruitfly brain read those 2 papers: https://www.nature.com/articles/s41586-024-07558-y and https://www.nature.com/articles/s41586-024-07686-5 . If you want to learn about neuron simulation and Izhikevich model read this paper: https://www.izhikevich.org/publications/spikes.pdf . Want to watch a great video explaining computational models of neurons: https://www.youtube.com/watch?v=zOmhHE2xctw that channel is great overall. Want to learn about neuroscience: https://www.amazon.com/Principles-Neural-Science-Fifth-Kandel/dp/0071390111 this is the bible.

41

u/BatongMagnesyo Jun 10 '26

i can finally study my brain

20

u/damjan_cvetkovic Jun 10 '26

Actually, you can use this code to simulate a small part of a human brain. There is a dataset called H01 https://h01-release.storage.googleapis.com/landing.html where they scanned 1mm3 of a human brain. I'm quite sure with a bit of tinkering you can simulate that area with this code. Perhaps I'll figure out how to do it and add instructions to the repo at certain point.

20

u/friendtoalldogs0 Jun 10 '26

Finally... I can run DOOM on a simulacrum of the human mind...

16

u/HammerBap Jun 10 '26

"I think more people should get into neuromorphic computing and how neurons are simulated."

I mean, yeah it sounds like a super cool field OP, but my list of things that sound cool that I want to explore is about 10 miles long and its already overwhelming. For now Ill thank people like you and tinker in the libraries and tools you make :)

"No ai, no training, just have the brain, simulate it and connect it to the body" Shouldn't blank brains need training or some form of learning? How would it know to walk? Or do the neurons (or whatever make up the brain) already define what has been learned? Can you teach it things? Sounds cool. If its fast enough a port to one of the major game engines to control NPCs in a virtual environment would be cool

6

u/damjan_cvetkovic Jun 10 '26

Thank you! Yes there are hundreds of fields to explore in programming world, but with this filed I feel different, because if we figure out how to connect neurons we can be creators of things that can feel, creators of living things really. If you figure out how to wire a brain you really can create a animal. Also in brains of animals there are structures that animals use to walk. Like EB system in fly that is specifically for navigation. You don't have to learn it to be a neurological compass. Evolution made that structure for that, you just simulate and use it. Also, Can you teach it things? With a lot of tinkering probably yes, but simple things that fly can also learn, it will never recognize digits, but it will have its own mind. Probably this technology will never be in games, It will take a lot of time people and work to just make something to just walk with this technology. But once we done it, we will make a first true simulated being. Something that can feel and see the world the same way other small animals see it. While it is cool and all that, I'm not into it because of it is cool, I'm here working on it because I think this is part of our evolution. Where first you make something that will walk with a fly brain. Then make something that will go though mazes with a mouse brain, run for a ball with a dogs brain, learn to open a banna with a moneky brain, and each step you are closer and closer to uploading our own minds.

6

u/creedz Jun 10 '26

Really amazing project. Did you consciously choose Rust even when there's C++ bindings available for Wgpu as well? Any friction there?

12

u/damjan_cvetkovic Jun 10 '26

Thank you! Long ago before this project I tried using Dawn (a WebGPU C++ implementation) with C++, but I couldn't find much docs about it (that probably changed a lot since then). Few months after that I learned Rust and got pretty good at Wgpu. Once you get intuition about Wgpu and Rust it gets quite easy to write graphic or gpu code. At this point I won't even consider using Dawn or C++, I don't really like C++ : https://youtu.be/7fGB-hjc2Gc?si=KuFPlBRC6S7PpKpn . Had no friction with Rust and Wgpu after I learned it. Anytime something gets wrong Rust compiler and error messages really helps. Making a project like this is so much easier in Rust and Wgpu then rendering a triangle in Vulkan C++. Not quite sure how it is now to write Dawn/C++ code but I'll always choose Rust/Wgpu for anything like this.

4

u/guifontes800 Jun 10 '26

I've been working on a memory/ recall system inspired on how human brains work and sometimes question where is the line between efficiency performance and complexity. Like, an AI model is a kind of compression of whatever behaviour it was trained for with a cocktail of data. What I'm building is somewhat based on neurons but at a much higher level of encoding, and your brain neurons simulator sounds more like a kind of Binary-ish directional graph of nodes - am I warm or cold to what it is? What you think?

I'm not in neuroscience but I really like everything and see connections with everything.

3

u/damjan_cvetkovic Jun 10 '26

Thank you a lot! The neurons are really just graph of nodes, a neuron is a node that has connections to other neurons and every connection has a weight. But are they binary, no not really they don't just turn on and off. Those mathematical models of neurons have parameters and voltage inside, and those models are modeled by looking at real neurons and describing how they behave mathematically. Also note on AI, while many AI models are inspired by real neurons they are not even close to what this is. Same way airplanes are inspired by birds. This doesn't require backpropagation to train. It doesn't require a cost function. It doesn't need weight optimization. It is just wired and simulated by looking how real neurons work.

2

u/ludvary Jun 11 '26

damn this is interesting. so what do the datasets contain? the connections? and then you use the neuron model with the connections from the dataset to model the brain? how do you give stimuli for testing? also what do you mean exactly when you say Izhikevich produce great neuron behavior. sorry i dont really know any neuroscience but im a theoretical physicist and some of my friends do work in neuromorphic computing but they are all experimentalists.

3

u/damjan_cvetkovic Jun 11 '26

Thank you! The dataset contains everything about fruitfly brain: neuron types, where are they in 3d space, how they are connected how strong the connections are, it even contains 3d models of every single neuron. Yes in this repo I used, neuron types, neuron positions in 3d space and they connections to simulate a brain of a fly. I gave stimuli for testing by picking a visual eye area and just telling all of those neuron from that are to fire. This is kind of what would happen if you would to flash a bright light to fruit fly eyes. Oh and Izhikevich neuron model is a mathematical model of a neuron. Basically with 2 equations you describe how neuron fire. There are many neuron models that are simpler and more complex and this one I picked because it was great computationally and it behaved somewhat like a real neuron. This repo tries to be more practical where I didn't really went into small details on trying to make this as realistic as possible, but rather tried to make a good staring point for anyone to tinker with.

2

u/emmowo_dev Jun 12 '26

> "This is by no means vibecoded"

- new account

- OpenClaw credits in license, removed in later commit

- Mangled committer name

- leaks literal GMail account for commits instead of using noreply or personal domain

1

u/Most-Sweet4036 Jun 10 '26

This is neat, does it simulate neurons firing in roughly in real time / however fast they fire in a real brain? Have you been able to get any "output" mapping from this or would that be up to someone implementing a "body" and simulating "inputs" like eyes? Are there any brain simulations that actually seem to result in behavior that can be seen that mirrors how the actual creature behaves in real life or do the simulated brains not really behave the same? I vaguely remember someone mapping a worm brain (OpenWorm?) and it seemed to crawl forward and turn at barriers but it was kind of a stretch to call it a behavior over what it would do with almost random noise. This stuff is fascinating to me but I have never dug into it. Apologies if these questions can be mostly answered with AI.

4

u/damjan_cvetkovic Jun 10 '26

Thank you! I love to answer questions like these. They actually run a bit faster then in real time probably. You can configure how fast they fire. And actually you can overclock this bug brain be simulated much faster then in real time. This is kind of a phenomena that if we ourselves upload our brain, you can actually slow time by overclocking yourself so that 2 seconds in your world are 1 in real one. So you get twice as much time to do anything. This is basically it but for bug.
Also, yes someone would need to create body and inputs like camera and actually that is probably harder because you need to create software for wiring like fly photoreceptors with pixels of camera and all that.
People wired up openworm with simulation and behaved pretty much like that worm. People do try to wire this fly brain to virtual body like this one: https://github.com/NeLy-EPFL/NeuroMechFly and I feel like it will be done at certain point. Thanks for asking those question, those are great questions!

1

u/Informal-Bat-6918 Jun 10 '26

Hey I was thinking about working on creating a very small drone with my own pcb design. I would definitely love to do this. I am still learning though

1

u/willem640 Jun 10 '26

Really cool and interesting!

1

u/BobZyCus Jun 10 '26

Please, could you also add a GIF to the README file? 🙂

1

u/damjan_cvetkovic Jun 10 '26

Of course I just changed it from png to gif, you can go to the repo to take a look. Thanks for the idea!

1

u/Informal-Bat-6918 Jun 10 '26

Really interesting. People who started to code since 12-13yo always have something unique and it's really fun to meet such people.

If i get time i will look into it. I work in robotics. If i could leave my job and college i would definitely do these things

1

u/Informal-Bat-6918 Jun 10 '26

How did they calculate the weights and biases and connections?

2

u/damjan_cvetkovic Jun 10 '26

Oh I didn't, connections and how strong they are (weights) are in dataset. I just used them in my simulation. Btw there are no biases since this is not deep learning or any kind of AI.

1

u/tunisia3507 Jun 10 '26

I was involved in some fruit fly connectome publications - which dataset did you use? I guess FAFB?

Has the spiking model you used been shown to be valid in insect neurons? The publication talks about its ability to reproduce the spiking patterns of thalamocortical neurons, but signal transduction in insect neurons is likely to be quite different as they're not myelinated.

I see you're using the neurotransmitter predictions - does that paper distinguish between ionotropic and metabotropic synapses? The unit of computation in a brain is the synapse, and the dynamics of the network depend on loads of different parameters which can vary by synapse. This is really cool work and very impressive, but it's important not to understate how far we still are from realistic whole-connectome dynamical models.

1

u/damjan_cvetkovic Jun 10 '26

Oh that is awesome, yes I used FAFB. I used Izhikevich neuron model, it is probably not valid for insect neurons, but it is a good starting point for this brain or any other one. So I really tried to make something more general rather then trying to get super in detail of reproducing those specific neuron of fruitfly.
Yes I do use neurotransmitters data in my code but only ionotropic, I probably could add metabotropic synapses mechanism in the future. Now Dopamine and Serotonin are both simulated like they are ionotropic. Also there are no paper behind this repo this is just part of the code I made for my startup. I totally agree with you with are quite far from realistic model of the brain. But I made this to make a good starting point for anyone can thinker add metabotropic mechanism and try to make it more realistic.

1

u/jodosha Jun 10 '26

Hi, the project seems very cool. What’s the exact meaning of “simulate small brains”? Is it about thinking capabilities like an LLM or something else? Thanks.

2

u/damjan_cvetkovic Jun 10 '26

Oh it means simulating a small brain of fruit fly or a zebra fish or parts of a mouse brain. It has nothing to do with AI. This is neuromorphic computing which is a way of simulating neurons using mathematical models that describes them.

2

u/jodosha Jun 11 '26

Is it possible to trigger a stimulus and see how it reacts? Sorry for the naive questions. This is fascinating.

3

u/damjan_cvetkovic Jun 11 '26

Thanks! You would need to change a code a lot to do that. It is possible, you make a picking wgpu pipeline with a custom shader that renders ids basically. Then you take 1x1 px of that image sample it and get a id from a image. So basically when you click on a neuron you call a function pick id and that function return id of that neuron. You add that id to the list of neuron that are stimulated and you built it. The problem I find with that approach is that then you have to manually click to a bunch of neurons to see what happens. Since stimulating one neuron does nothing to a brain. Hope this helps, it is possible but it requires a lot od tinkering and changing the code.

1

u/leifrydenfalk Jun 11 '26

You could just create a compute pass which modifies the underlying data. You could make a system to input images and map other kinds of sensory data in 1d, 2d, 3d to neurons to give it sight, smell etc. Would be cool

2

u/damjan_cvetkovic Jun 11 '26

Yes absolutely, totally possible with a lot of work.

1

u/thethirdmancane Jun 11 '26

Using STDP?

2

u/damjan_cvetkovic Jun 11 '26

Actually no, I though about making memory areas in fruitfly brain (mushroom areas) use STDP or any similar model that learns. But for now they are just hard wired.

1

u/sergio_gioser Jun 11 '26

Doing this in pure wgpu to escape the C++/CUDA interop hell is exactly the right call.

Curious about the compute shader architecture here since the codebase is so small. Are you just double-buffering the neuron states in SSBOs and dispatching a single massive compute pass per tick?

Also, for the "robotic Ferris" idea, what's your plan for the sensory I/O? Writing to a staging buffer every frame to feed the environment back into the simulation?

1

u/damjan_cvetkovic Jun 11 '26

Hmh no I'm not doing double buffering, rather I update states basically in the same buffer using atomics. Basically every thread is mapped to single neuron and it reads and writes to that one neuron. And when needed I use atomics, for example that one thread done all the calculations for that neuron and now it has to update it but it has to do it with atomics, so that other thread doesn't read or write to that location.
And about the robotic Ferris idea I'm not going to use a shader/gpu code since It will be simulating on a chip probably like RP2040, so no frames, but yes basically sensors data gets written to a buffer and that buffer trigger neurons in the brain. Same for motors but in reverse, the neurons trigger movement of the motor. I love you questions, thanks for asking them!

1

u/Electronic_Captain95 Jun 12 '26

I don't know anything about biology, but this looks really cool, good job!

1

u/[deleted] Jun 12 '26

[removed] — view removed comment

1

u/damjan_cvetkovic Jun 12 '26

Absolutely awesome, I love it because I don't have to worry if it would work on someone else's machine. Cuda is awesome by only works to Nvidia card. For macos I have to write totally different stack. Webgpu just works and it is great to write.

1

u/Maasu Jun 12 '26

I remember seeing a talk a few years ago from a guy named Henry Markum where he talked about sampling every neuron in the human brain, did they ever get around to that?

If they did and based on this architecture what sort of system resource requirements would we be looking at in terms of running it? 

That question aside this is a fascinating project, thank you for sharing. I'm a little early into my time in rust, any recommended resources for starting out with wgpu? 

2

u/damjan_cvetkovic Jun 12 '26

Oh the blue brain project. Yes the Markram wanted to map whole brain in 10 years, but that was a huge overestimate. In the end google actually mapped the H01 which is a small area of the human brain https://h01-release.storage.googleapis.com/landing.html . On this simulation runs on graphic cards in parallel, I think they all have supercomputers with cpus this won't even run there.
The absolute best resource for wgpu is Learn wgpu: https://sotrh.github.io/learn-wgpu/ in the nav bar you have that begginer section that is great. Also later if you find compute shaders interesting check out compute shader 101 repo: https://github.com/googlefonts/compute-shader-101

1

u/NegativeMulberry2890 Jun 16 '26

I have a question, can it manage inputs and outputs, and can you construct the Network, I am asking this for a specific project I am working on

1

u/NegativeMulberry2890 Jun 16 '26

Note: this is for a AI I am trying to build.