{"action":"created","issue":{"url":"https://api.github.com/repos/brian-team/brian2/issues/721","repository_url":"https://api.github.com/repos/brian-team/brian2","labels_url":"https://api.github.com/repos/brian-team/brian2/issues/721/labels{/name}","comments_url":"https://api.github.com/repos/brian-team/brian2/issues/721/comments","events_url":"https://api.github.com/repos/brian-team/brian2/issues/721/events","html_url":"https://github.com/brian-team/brian2/issues/721","id":161182055,"number":721,"title":"Check monitored expressions for stateful functions","user":{"login":"mstimberg","id":1381982,"avatar_url":"https://avatars.githubusercontent.com/u/1381982?v=3","gravatar_id":"","url":"https://api.github.com/users/mstimberg","html_url":"https://github.com/mstimberg","followers_url":"https://api.github.com/users/mstimberg/followers","following_url":"https://api.github.com/users/mstimberg/following{/other_user}","gists_url":"https://api.github.com/users/mstimberg/gists{/gist_id}","starred_url":"https://api.github.com/users/mstimberg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mstimberg/subscriptions","organizations_url":"https://api.github.com/users/mstimberg/orgs","repos_url":"https://api.github.com/users/mstimberg/repos","events_url":"https://api.github.com/users/mstimberg/events{/privacy}","received_events_url":"https://api.github.com/users/mstimberg/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/brian-team/brian2/labels/enhancement","name":"enhancement","color":"207de5"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2016-06-20T12:18:14Z","updated_at":"2016-06-20T12:36:50Z","closed_at":null,"body":"The following is a not uncommon mistake:\r\n```Python\r\ngroup = NeuronGroup(1, '''dv/dt = (-v + I) / (10*ms) : 1\r\n                          I = rand() : 1''')\r\nmon = StateMonitor(group, 'I', record=True)\r\n```\r\nThe user expects that the `StateMonitor` records the same `I` that is used in the differential equations, but instead `rand()` will be evaluated twice, giving different values. We should detect this situation (the most general check seems to be to check for subexpressions involving \"stateful functions\" ) and raise a warning (or even error?). Alternatively, we could completely forbid to record subexpressions, but that would be quite annoying for all the cases where it is unproblematic.\r\n\r\nThe warning/error message should direct the user to the use of a parameter and `run_regularly`, or some new syntax as discussed in #720.\r\n"},"comment":{"url":"https://api.github.com/repos/brian-team/brian2/issues/comments/227130076","html_url":"https://github.com/brian-team/brian2/issues/721#issuecomment-227130076","issue_url":"https://api.github.com/repos/brian-team/brian2/issues/721","id":227130076,"user":{"login":"mstimberg","id":1381982,"avatar_url":"https://avatars.githubusercontent.com/u/1381982?v=3","gravatar_id":"","url":"https://api.github.com/users/mstimberg","html_url":"https://github.com/mstimberg","followers_url":"https://api.github.com/users/mstimberg/followers","following_url":"https://api.github.com/users/mstimberg/following{/other_user}","gists_url":"https://api.github.com/users/mstimberg/gists{/gist_id}","starred_url":"https://api.github.com/users/mstimberg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mstimberg/subscriptions","organizations_url":"https://api.github.com/users/mstimberg/orgs","repos_url":"https://api.github.com/users/mstimberg/repos","events_url":"https://api.github.com/users/mstimberg/events{/privacy}","received_events_url":"https://api.github.com/users/mstimberg/received_events","type":"User","site_admin":false},"created_at":"2016-06-20T12:36:50Z","updated_at":"2016-06-20T12:36:50Z","body":"Good points, you are right that there is nothing monitor-specific here, it is really about the use of stateful functions in a subexpression. I think our current behaviour related to this is inconsistent, IIRC (I did not double check) we substitute all subexpressions for the state update step but only evaluate them once in general code blocks (e.g. resets), with some logic of re-evaluating them if some of the variables they used change. Not sure we added anything to re-evaluate them unconditionally if they involve stateless functions.\r\n\r\nI think one fundamental problem in our syntax is that subexpressions look like statements but they are interpreted as functions of their variables."}}
{"actor":{"display_login":"mstimberg"}}