{"action":"created","issue":{"url":"https://api.github.com/repos/nengo/nengo/issues/622","labels_url":"https://api.github.com/repos/nengo/nengo/issues/622/labels{/name}","comments_url":"https://api.github.com/repos/nengo/nengo/issues/622/comments","events_url":"https://api.github.com/repos/nengo/nengo/issues/622/events","html_url":"https://github.com/nengo/nengo/issues/622","id":54415545,"number":622,"title":"Possible proposal for an addition to the Node API","user":{"login":"tcstewar","id":2380772,"avatar_url":"https://avatars.githubusercontent.com/u/2380772?v=3","gravatar_id":"","url":"https://api.github.com/users/tcstewar","html_url":"https://github.com/tcstewar","followers_url":"https://api.github.com/users/tcstewar/followers","following_url":"https://api.github.com/users/tcstewar/following{/other_user}","gists_url":"https://api.github.com/users/tcstewar/gists{/gist_id}","starred_url":"https://api.github.com/users/tcstewar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tcstewar/subscriptions","organizations_url":"https://api.github.com/users/tcstewar/orgs","repos_url":"https://api.github.com/users/tcstewar/repos","events_url":"https://api.github.com/users/tcstewar/events{/privacy}","received_events_url":"https://api.github.com/users/tcstewar/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/nengo/nengo/labels/discussion","name":"discussion","color":"207de5"}],"state":"open","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/nengo/nengo/milestones/5","labels_url":"https://api.github.com/repos/nengo/nengo/milestones/5/labels","id":747892,"number":5,"title":"2.0.1 release","description":"For minor changes that won't affect model code.","creator":{"login":"tbekolay","id":203709,"avatar_url":"https://avatars.githubusercontent.com/u/203709?v=3","gravatar_id":"","url":"https://api.github.com/users/tbekolay","html_url":"https://github.com/tbekolay","followers_url":"https://api.github.com/users/tbekolay/followers","following_url":"https://api.github.com/users/tbekolay/following{/other_user}","gists_url":"https://api.github.com/users/tbekolay/gists{/gist_id}","starred_url":"https://api.github.com/users/tbekolay/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tbekolay/subscriptions","organizations_url":"https://api.github.com/users/tbekolay/orgs","repos_url":"https://api.github.com/users/tbekolay/repos","events_url":"https://api.github.com/users/tbekolay/events{/privacy}","received_events_url":"https://api.github.com/users/tbekolay/received_events","type":"User","site_admin":false},"open_issues":27,"closed_issues":4,"state":"open","created_at":"2014-08-08T17:42:10Z","updated_at":"2015-01-22T19:31:02Z","due_on":null,"closed_at":null},"comments":87,"created_at":"2015-01-15T06:01:14Z","updated_at":"2015-01-22T21:42:30Z","closed_at":null,"body":"As part of #616 and other previous verbal discussions, now and then it seems like people want to do something with the Node interface that isn't quite nicely supported by the current API.  Here is a proposal that I'm not sure I fully support, but I thought it might address some of the things people seem to want.\r\n\r\nCurrently, a Node's ```output``` value can either be a callable function or an array-like.  If it's an array-like, the Node always outputs that value.  If it's callable, then the backend should call the function regularly, passing in t (the current time) and optionally x (the sum of the inputs to the Node, if any).\r\n\r\nAs people have used Nodes for different things, there have been a few situations where people have wanted a little bit more power here.  Right now, there have been fairly straighforward workarounds, and so I'm not yet convinced that we need to add complexity to the Node API.  But, there have been three things people have expressed interest in:\r\n - responding in some way to reset() (which you can do right now by just detecting when t jumps back to 0)\r\n - getting access to the Simulator and Model object (which you can access now via manually passing it into the function)\r\n - getting access to the model's random number generator and/or seed (which you can access now via passing it into the function).\r\n\r\nOne way we could address all of this is by allowing people to set ```output``` to be a function factory instead of a function (or an arraylike).  That is, people could do this:\r\n\r\n```python\r\ndef noise_maker(sim, model, rng):\r\n    gain = rng.uniform(0, 1)\r\n    freq = rng.uniform(0.5, 80.0)\r\n    def my_func(t):\r\n        return gain * np.sin(freq * t)\r\n    return my_func\r\nnode = nengo.Node(noise_maker)\r\n```\r\n\r\nThe backend would, when a simulation starts (or when a reset occurs), call this function, and then use the function that it returns from then on.  In this particular case, the result is a sine wave of a different frequency and amplitude, based on the seed of the Simulator.\r\n\r\nThis seems like a relatively simple change to the Node API.  It does complicate matters a fair bit for the GUI when it goes in to modify Nodes to allow for controllable sliders overriding the Node input values, but I think it's doable, if we decide there's significant advantage to having something like this over the existing Node system.  That said, I don't know what the use cases are.  I think this might address some of the aspects of #616, but I also think those aspects can be addressed reasonably well with the existing Node system.  This proposal here might be a bit cleaner, but if that's all we get out of it then I don't think we should add the complexity.\r\n\r\nIn any case, I thought I'd put this idea out there and see what people think.  In particular\r\n - Does this cover use cases that people want that are difficult with the current Node API?  What are those use cases?\r\n - How should the Node builder detect that it has been given a generator rather than a normal function?\r\n - Are there other parameters that the builder should pass in?\r\n - Are there completely different other proposals?\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/nengo/nengo/issues/comments/71104786","html_url":"https://github.com/nengo/nengo/issues/622#issuecomment-71104786","issue_url":"https://api.github.com/repos/nengo/nengo/issues/622","id":71104786,"user":{"login":"tcstewar","id":2380772,"avatar_url":"https://avatars.githubusercontent.com/u/2380772?v=3","gravatar_id":"","url":"https://api.github.com/users/tcstewar","html_url":"https://github.com/tcstewar","followers_url":"https://api.github.com/users/tcstewar/followers","following_url":"https://api.github.com/users/tcstewar/following{/other_user}","gists_url":"https://api.github.com/users/tcstewar/gists{/gist_id}","starred_url":"https://api.github.com/users/tcstewar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tcstewar/subscriptions","organizations_url":"https://api.github.com/users/tcstewar/orgs","repos_url":"https://api.github.com/users/tcstewar/repos","events_url":"https://api.github.com/users/tcstewar/events{/privacy}","received_events_url":"https://api.github.com/users/tcstewar/received_events","type":"User","site_admin":false},"created_at":"2015-01-22T21:42:30Z","updated_at":"2015-01-22T21:42:30Z","body":"> Is there a reason why it wouldn't be possible to use just one node in case 4 if you really want to share the state?\r\n\r\nThat'd be my solution as well, I think."}}