nengo / nengo-loihi

Run Nengo models on Intel's Loihi chip
https://www.nengo.ai/nengo-loihi/
Other
35 stars 12 forks source link

Custom processes #283

Closed Libardo1 closed 4 years ago

Libardo1 commented 4 years ago

Hi, I am trying to reproduce your tutorial Processes I have an issue with: Custom processes

class SimpleOscillator(nengo.Process):
    def make_state(self, shape_in, shape_out, dt, dtype=None):
        # return a dictionary mapping strings to their initial state
        return {"state": np.array([1., 0.])}

    def make_step(self, shape_in, shape_out, dt, rng, state):
        A = np.array([[-0.1, -1.], [1., -0.1]])
        s = state["state"]

        # define the step function, which will be called
        # by the node every time step
        def step(t):
            s[:] += dt * np.dot(A, s)
            return s

        return step  # return the step function

with nengo.Network() as model:
    a = nengo.Node(SimpleOscillator(), size_in=0, size_out=2)
    a_p = nengo.Probe(a)

with nengo.Simulator(model) as sim:
    sim.run(20.0)

plt.figure()
plt.plot(sim.trange(), sim.data[a_p])
plt.xlabel('time [s]');

I receive this error: TypeError: make_step() missing 1 required positional argument: 'state'

Any hint?, TIA.

hunse commented 4 years ago

Hello!

I think the problem is that you're using an older version of Nengo. You need at least Nengo 3.0.0 to use this feature. On Nengo 3.0.0, your code above works for me.

Libardo1 commented 4 years ago

Yes, you're rigth. It works fine. Thanks.