brainpy / BrainPy

Brain Dynamics Programming in Python
https://brainpy.readthedocs.io/
GNU General Public License v3.0
536 stars 94 forks source link

Interaction with NEURON models #446

Open chaoming0625 opened 1 year ago

chaoming0625 commented 1 year ago

Please:

NEURON simulator has a vast database of template models. It is essential to make it easy to switch models in the NEURON simulator into the BrainPy.

CloudyDory commented 1 year ago

Hi, thanks for the time and effort in developing Brainpy! It's a great and convenient tool.

I have tried to port a NEURON model into Brainpy for a while, and would like to share some of my personal experiences on the differences between the two simulators. Hope it will be helpful for someone who wishes to do the same.

NEURON is fundamentally a physical, multi-compartment neuron simulator. As far as I know, even the simplest model in NEURON has length, diameter, the corresponding surface area, and axial resistance. As a consequence, in NEURON, we should take care of the difference between "point process" and "density mechanism". For example, external injection current and synaptic input current are usually described as "point process", and the values are usually the total amount of current flow into the cell. Membrane capacitance and ionic current are usually described as "density mechanism", and the values are usually normalized by the surface area.

Brainpy, in its current version, does not have the concept of compartment. Many of the example HH neuron code in Brainpy's documentation does not specify the cell's length and diameter. In the documentation of Brainpy's synapse module, I also don't see a reminder on whether the synaptic currents are described in total amount or per-surface area. Besides, some Brainpy's internal code seems to implicitly rely on a point-neuron model. For example, the "AMPA" synapse requires the post-synaptic neurons to have the attribute "V", but in multi-compartment case we should specify the "V" of which compartment, and this may require some custom modifications on Brainpy's code.

Yet, we can still build multiple-compartment neuron models in Brainpy. Ultimately, these models just mean more differential equations to solve. But the conceptual difference is important. It really confuses me when comparing the code between NEURON and Brainpy, since some model parameters are not needed in Brainpy, and some are expressed differently. Therefore, if one decides to port a NEURON model into Brainpy, it would be very helpful to first know how neurons are treated differently in the two software.

Besides, it would also be helpful to cross-check between the numerical integration results of NEURON and Brainpy. The numerical integration result heavily depends on the initial conditions, the numerical integration method, and (to a lesser extent) the precision of floating-point numbers (float32 or float64). From my limited experience, in general, Brainpy's "exp-euler" solver can produce similar results as NEURON's "cnexp" and "derivimplicit" solvers. However, for some models with very stiff ODEs (for example, the Mainen & Sejnowski's 1996 Nature paper, in which the Na+ conductance is as large as 30000 pS/um^2), NEURON's solvers seem to be more stable and efficient. I have once needed to set dt=0.00001 ms in Brainpy to get similar result as in NEURON (with dt=0.01 ms). Properly setting the initial conditions (on both the membrane potential and gating variables) is also important, as the behavior of some model can change a lot even if the initial value changes only a tiny bit.

chaoming0625 commented 1 year ago

So many thanks for your report! It's an excellent feedback for us.

PikaPei commented 8 months ago

Hello @CloudyDory! I am learning both NEURON and BrainPy right now. I'd also like to apply some NEURON models to BrainPy. Specifically, I want to transform *.mod files into IonChannel. It seems that you had already put some effort. I'm very appreciate your comments above. May I ask what have you tried/done if you have time?

CloudyDory commented 8 months ago

Hi @PikaPei,

I have implemented some customed two-compartment neuron models and synapses. I have not used the IonChannel before, but write all differential equations in one class, and use BrainPy as an numerical integrator.

Be very specific about the units in BrainPy and NEURON. Once we get them correct, we should get very similar results in both simulators. There may be some remaining small difference because the two softwares use different numerical integrators.

chaoming0625 commented 8 months ago

Unit checking is on the way. @Routhleck

PikaPei commented 8 months ago

Thank you @CloudyDory for your reply, it's great to hear your experience again.

Also looking forward to the unit checking!