Using the functionality "delaying a connection with a node" to SPA

Dear all,
I try to get running the example nengo > nodes > delaying a connection with a node not just for a nengo.Ensemble but for a spa.State .

So: in earlier versions of the spa I got is running by using this class:

delay_t = 0.2   # 200 ms 

class Delay(object):
    def __init__(self, dimensions, timesteps=50):
        self.timesteps = timesteps
        self.dimensions = dimensions
        self.history = None
    def step(self, t, x):
        self.history = np.roll(self.history, -self.dimensions)
        self.history[-1] = x
        return self.history[0]
    def reset(self):
        self.history = np.zeros((self.timesteps, self.dimensions))

dt = 0.001       # 1 msec -> see simulations 
delay = Delay(dimensions = D, timesteps = int(delay_t / dt))

and later within the model:

model.delaynode = nengo.Node(delay.step, size_in=D, size_out=D)

but if I try to use model.delaynode as a spa.State buffer, for example in:

model.input_state >> model.delaynode, 

I get an error for this line:

SpaTypeError: <Connector<Node> (unlabeled) at 0x11cab4be0> was not registered as a SPA input.

I need help:
The problem seems to be, that I do not know, how to transform an array to a spa S-pointer.
Is that correct?
Even if I replace nengo.Node(...) by spa.Transcode(...), I still have with the same problem.


The SPA operators like >> cannot be used to connect to normal Nengo objects. This is because the SPA objects track their vocabularies of Semantic Pointers, but the Nengo objects do not. Thus, you would lose the information about the associated vocabulary if you connected directly to the Nengo node and NengoSPA could not warn you about non-matching vocubalaries or other problems with your code, for example.

There are a couple of variants to circumvent this:

Variant 1: Connect the underlying raw Nengo objects

nengo.Connection(model.input_state.state_ensembles.output, model.delaynode)

Varint 2: Use the Transcode module

NengoSPA provides the Transcode module which is the vocabulary-aware equivalent of a Nengo node.

transcode_module = spa.Transcode(delay.step, input_vocab=D, output_vocab=D)
model.input_state >> transcode_module

(You might need to adjust the Delay class. Its step function will receive SemanticPointer instances instead of raw arrays.)

Variant 3: Wrap your Delay node into a custom module

This usually makes only sense to group more complex functionality into a unit. You’ll find more information in the documentation.