Set membrane potential value

Hi Hamed,

This isn’t something we support through the API. However, for the default nengo backend (i.e. nengo.Simulator), you can set the value of the membrane voltage signal yourself.

import nengo
import numpy as np

with nengo.Network(seed=0) as net:
    ens = nengo.Ensemble(
        5, 1, gain=nengo.dists.Choice([1.0]), bias=nengo.dists.Choice([0.0])
    )
    probe = nengo.Probe(ens.neurons, "voltage")

with nengo.Simulator(net) as sim:
    # get the signal that contains the voltage for the ensemble
    signal = sim.model.sig[ens.neurons]["voltage"]
    # manually change its initial value in the simulator. Here I use a linear range of values for the
    # voltages, but you can set them to whatever you want. Note that for most of our neuron types, 
    # the voltages lie between 0 and 1, so you should choose values in this range (the LIF neuron
    # type does have a `min_voltage` parameter that you can use to allow negative voltages).
    sim.signals[signal][:] = np.linspace(0, 0.99, signal.size)

    sim.run_steps(10)

print(sim.data[probe][:10])

When you run this code, you should get something like this

[[0.         0.23542928 0.47085857 0.70628785 0.94171713]
 [0.         0.22394726 0.44789452 0.67184178 0.89578904]
 [0.         0.21302522 0.42605045 0.63907567 0.8521009 ]
 [0.         0.20263586 0.40527172 0.60790758 0.81054345]
 [0.         0.19275319 0.38550639 0.57825958 0.77101278]
 [0.         0.18335251 0.36670502 0.55005753 0.73341004]
 [0.         0.1744103  0.3488206  0.52323091 0.69764121]
 [0.         0.16590421 0.33180842 0.49771263 0.66361685]
 [0.         0.15781297 0.31562594 0.4734389  0.63125187]
 [0.         0.15011634 0.30023268 0.45034901 0.60046535]]

where each column is a different neuron’s voltage, and each row is a different timestep. You can see that the voltages start around the values I set, and then they decay because due to the LIF neuron’s “leak” (they actually start at exactly the values I set, but the first row shows the voltages after they have already decayed for one timestep).

Note that this is not guaranteed to work with other backends (e.g. nengo_dl, nengo_loihi), in fact it most likely will not.