import nengo
import numpy as np


class FlexibleDuration(nengo.Process):
    def __init__(self, incr, **kwargs):
        self.incr = incr
        self.index = 0
        super().__init__(default_size_in=0, default_size_out=1, **kwargs)

    def make_step(self, shape_in, shape_out, dt, rng, state):
        assert shape_in == (0,)
        assert shape_out == (1,)

        def step_presentinput(t):
            self.index += self.incr
            return self.index

        return step_presentinput


process_in = FlexibleDuration(1)
process_target = FlexibleDuration(2)

model = nengo.Network()

with model:

    inp = nengo.Node(process_in)
    target = nengo.Node(process_target)

    pi = nengo.Probe(inp)
    pt = nengo.Probe(target)

with nengo.Simulator(model) as sim:
    sim.run(0.01)

import matplotlib.pyplot as plt

plt.figure()
plt.plot(sim.trange(), sim.data[pi], label="process_inp (incr by 1)")
plt.plot(sim.trange(), sim.data[pt], label="process_target (incr by 2)")
plt.legend()
plt.show()
