Adding a custom neuron type operator to nengo DL

I am adding a custom neuron type operator (stpLIF) to the nengo_dl backend. I first add the regular nengo operator and then the operator builder that is needed for nengo_dl.

from nengo_dl import Builder, NengoBuilder
from nengo.neurons import LIF

class stpLIF(LIF):

@NengoBuilder.register(stpLIF)
def build_stpLIF(model, stplif, neurons):

from nengo_dl.neuron_builders import LIFBuilder

@Builder.register(stpLIF)
class stpLIFBuilder(LIFBuilder):

However while making changes to the “stpLIFBuilder” class they seemed to have no effect on the values of the neuron states. So I commented out the @Builder.register(stpLIF) to see what would happen and, well, nothing happened. When I comment out the same line for my learning rule operator I get an error that the class cannot be found. But leaving out the custom neuron builder that would do the tensorflow calculations makes no difference. Would anyone know why this is happening? Should I not get an error when leaving out the registration of this custom neuron type operator builder.

I am using Nengo 2.8.0 and Nengo DL 2.2.2

When you’re registering NengoDL builders, you need to register them with the Operator, rather than the neuron type (stpLIF). However, registering new Neuron builders works a bit differently, because all neurons have the same operator (SimNeurons). So if you look at neuron_builders.py, you’ll see that there is a single SimNeuronsBuilder class that is registered with the SimNeurons operator. So what you need to do is add your stpLIFBuilder to SimNeuronsBuilder, like

from nengo_dl.neuron_builders import SimNeuronsBuilder

SimNeuronsBuilder.TF_NEURON_IMPL[stpLIF] = stpLIFBuilder

The reason you don’t get an error if you don’t do the above is that NengoDL will fall back to using the pure python implementation (which, unless you added one, will just be the regular LIF python implementation, since your class inherits from LIF).

1 Like

Thank you very much. I figured something like this was the problem when looking at the documentation this morning but I could not figure out how to solve it.

Happy Easter!

That part definitely isn’t as intuitive/documented as it could be, I’ve added a TODO to make a better example of how to add new neuron types to Nengo DL.