Continues simulation for didactic project

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
while running:
    if buttonpress:
       # inject current
       neuron.dendrite.I = 0.22*nA

    # run one simulation step with dt

    # Output 

Ist hat possible and are there examples fort hat?



1 Like

Should be straight forward using: Using Interact — Jupyter Widgets 8.0.0rc0 documentation


1 Like

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 = '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

1 Like

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).

1 Like

Hi @mstimberg and @schmitts ,

thanks for your answers. looks very promissing, ill have a look into it.

Best, Cornelius