nengo-1.4 icon indicating copy to clipboard operation
nengo-1.4 copied to clipboard

Rethinking SimpleNodes

Open tcstewar opened this issue 11 years ago • 0 comments

As a response to issues #389 and #385, I'm wanting a different interface for doing what SimpleNodes do now. Here's a quick sketch of what I'd like to be able to do:

class DelayNode(nef.Node):
    def __init__(self, name, steps, dimensions):
        nef.Node.__init__(self, name)
        self.steps = steps
        self.dimensions = dimensions

        # specify whatever inputs and outputs I want
        self.input = self.create_input('input', dimensions=dimensions, pstc=0.01)
        self.output = self.create_output('output', dimensions=dimensions)

    # this will automatically get called on reset, and also before the first tick()
    def start(self):
        self.delay = [[0] * self.dimensions for i in range(self.steps)]

    # use output.set() and input.get() to access origins and terminations
    def tick(self):
        self.output.set(self.delay[0])
        self.delay = self.delay[1:] + [self.input.get()]

Furthermore, to get a little fancier, I'd also like to be able to use the yield command to do generator functions. This could be handy for certain types of Nodes, such as this, which produces random data that changes every 0.1 seconds:

class YieldNode(node.Node):
  def __init__(self, name):
      node.Node.__init__(self, name)
      self.output = self.create_output('output', dimensions=1)

  def start(self):
      while True:
        self.output.set([random.uniform(-1,1)])
        yield 0.1

tcstewar avatar Apr 17 '13 06:04 tcstewar