i would like to use brian2 in a didactic project where the membrane potential of a neuron is dynamically represented and can be actively changed. For that i would like to run an endless simulation and get the membrane potential values for every step while running.
Basically instead of running a simulation for a given time, i would like to run the simulation stepwise (and continues) and interact with the model during the loop.
Pseudocode would look like:
neuron = SpatialNeuron()
defaultclock.dt = 0.05*ms
# inject current
neuron.dendrite.I = 0.22*nA
# run one simulation step with dt
Ist hat possible and are there examples fort hat?
Hi @cornelius. A general comment this kind of loop: running the simulation for a single time step is very inefficient, since every
run call does some setup (a bit less when you use
prefs.codegen.target = 'numpy', and there are ways to make this more efficient with C++ standalone mode as well – but not straightforward). Instead, it would be better to use a
network_operation that regularly (but not every time step) checks for interaction. Assuming you do not want to actually run the simulation in a very slow, step-by-step way (e.g. for debugging), of course.
As @schmitts mentioned, you can build nice interactivity with Jupyter widgets. We actually made an interactive version of one of the examples of our paper (Brian 2, an intuitive and efficient neural simulator | eLife). You can find it here: brian2_paper_examples/example_2_eye_movements_interactive.ipynb at master · brian-team/brian2_paper_examples · GitHub
The best is to run it locally, but you can also try it out online on the Binder infrastructure: Binder
Minor correction to my comment above, the correct link is this one: brian2_paper_examples/example_2_eye_movements_interactive_matplotlib.ipynb at master · brian-team/brian2_paper_examples · GitHub
(the version I linked to uses plotly which is not ideal for this kind of plot).
Hi @mstimberg and @schmitts ,
thanks for your answers. looks very promissing, ill have a look into it.