{"action":"created","comment":{"url":"https://api.github.com/repos/nest/nest-simulator/pulls/comments/42240052","id":42240052,"diff_hunk":"@@ -0,0 +1,162 @@\n+# -*- coding: utf-8 -*-\n+#\n+# test_parrot_neuron.py\n+#\n+# This file is part of NEST.\n+#\n+# Copyright (C) 2004 The NEST Initiative\n+#\n+# NEST is free software: you can redistribute it and/or modify\n+# it under the terms of the GNU General Public License as published by\n+# the Free Software Foundation, either version 2 of the License, or\n+# (at your option) any later version.\n+#\n+# NEST is distributed in the hope that it will be useful,\n+# but WITHOUT ANY WARRANTY; without even the implied warranty of\n+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+# GNU General Public License for more details.\n+#\n+# You should have received a copy of the GNU General Public License\n+# along with NEST.  If not, see <http://www.gnu.org/licenses/>.\n+\n+# This script tests the parrot_neuron in NEST.\n+\n+import nest\n+import unittest\n+\n+\n+@nest.check_stack\n+class ParrotNeuronTestCase(unittest.TestCase):\n+    \"\"\"Check parrot_neuron spike repetition properties\"\"\"\n+\n+    def setUp(self):\n+        nest.set_verbosity(100)\n+        nest.ResetKernel()\n+\n+        # set up source spike generator, as well as parrot neurons\n+        self.spike_time = 1.\n+        self.source = nest.Create(\"spike_generator\", 1, {\"spike_times\": [self.spike_time]})\n+        self.parrot = nest.Create('parrot_neuron')\n+        self.spikes = nest.Create(\"spike_detector\")\n+\n+        # record source and parrot spikes\n+        nest.Connect(self.source, self.spikes)\n+        nest.Connect(self.parrot, self.spikes)\n+\n+        self.gid_source = nest.GetStatus(self.source)[0][\"global_id\"]\n+        self.gid_parrot = nest.GetStatus(self.parrot)[0][\"global_id\"]\n+\n+    def test_ParrotNeuronRepeatSpike(self):\n+        \"\"\"Check parrot_neuron repeats spikes on port 0\"\"\"\n+\n+        # connect with arbitrary delay\n+        delay = .7\n+        nest.Connect(self.source, self.parrot, syn_spec={\"delay\": delay})\n+\n+        nest.Simulate(3.)\n+\n+        # get spike from parrot neuron\n+        events = nest.GetStatus(self.spikes)[0][\"events\"]\n+        post_time = events['times'][events['senders'] == self.gid_parrot]\n+\n+        # assert spike was repeated at correct time\n+        assert post_time, \"Parrot neuron failed to repeat spike.\"\n+        assert self.spike_time + delay == post_time, \"Parrot neuron repeated spike at wrong delay\"\n+\n+    def test_ParrotNeuronIgnoreSpike(self):\n+        \"\"\"Check parrot_neuron ignores spikes on port 1\"\"\"\n+\n+        # connect with arbitrary delay to port 1\n+        nest.Connect(self.source, self.parrot, syn_spec={\"receptor_type\": 1})\n+        nest.Simulate(3.)\n+\n+        # get spike from parrot neuron, assert it was ignored\n+        events = nest.GetStatus(self.spikes)[0][\"events\"]\n+        post_time = events['times'][events['senders'] == self.gid_parrot]\n+        assert len(post_time) == 0, \"Parrot neuron failed to ignore spike arriving on port 1\"\n+\n+\n+@nest.check_stack\n+class ParrotNeuronSTDPTestCase(unittest.TestCase):\n+    \"\"\"\n+    Check STDP protocol between two parrot_neurons connected by a stdp_synapse.\n+    Exact pre- and post-synaptic spike times are set by spike_generators\n+    connected to each parrot neuron. Additional spikes sent through the\n+    stdp_synapse are explicitly ignored in the postsynaptic parrot_neuron\n+    by setting the stdp_synapse to connect to port 1.\n+    \"\"\"\n+\n+    def test_ParrotNeuronSTDPProtocol(self):\n+        \"\"\"Check STDP between parrot_neurons changes weights, ignores transmitted spikes\"\"\"\n+\n+        nest.set_verbosity(\"M_WARNING\")\n+        nest.ResetKernel()\n+\n+        # set pre and postsynaptic spike times\n+        dt = 5.\n+        delay = 1.  # delay for connections\n+\n+        pre_times = [100., 300., 500., 700., 900.]\n+        pre_times = [k-delay for k in pre_times]  # set the correct real spike times\n+        post_times = [k+dt for k in pre_times]\n+\n+        # create spike_generators with these times\n+        pre_spikes = nest.Create(\"spike_generator\", 1, {\"spike_times\": pre_times})\n+        post_spikes = nest.Create(\"spike_generator\", 1, {\"spike_times\": post_times})\n+\n+        # create parrot neurons and connect spike_generators\n+        pre_parrot = nest.Create(\"parrot_neuron\", 1)\n+        post_parrot = nest.Create(\"parrot_neuron\", 1)\n+        nest.Connect(pre_spikes, pre_parrot, syn_spec={\"delay\": delay})\n+        nest.Connect(post_spikes, post_parrot, syn_spec={\"delay\": delay})\n+\n+        # create spike detector\n+        spikes = nest.Create(\"spike_detector\")\n+        nest.Connect(post_parrot, spikes)\n+\n+        # connect both parrot neurons with a stdp synapse onto port 1\n+        # thereby spikes transmitted through the stdp connection are\n+        # not repeated postsynaptically.\n+        syn_spec = {\n+           \"model\": \"stdp_synapse\",\n+           \"receptor_type\": 1,  # set receptor 1 postsynaptically, to not generate extra spikes\n+        }\n+        conn_spec = {\n+           \"rule\": \"one_to_one\",\n+        }\n+        nest.Connect(pre_parrot, post_parrot, syn_spec=syn_spec, conn_spec=conn_spec)\n+\n+        # get STDP synapse and initial weight\n+        syn = nest.GetConnections(source=pre_parrot, synapse_model=\"stdp_synapse\")\n+        initial_weight = nest.GetStatus(syn)[0]['weight']\n+\n+        nest.Simulate(1000)\n+\n+        # check that the STDP protocol has elicited a weight change.","path":"pynest/nest/tests/test_parrot_neuron.py","position":135,"original_position":135,"commit_id":"0c20ff3b64911dce25515ad0351b6ecbc51d3cab","original_commit_id":"0c20ff3b64911dce25515ad0351b6ecbc51d3cab","user":{"login":"abigailm","id":10513829,"avatar_url":"https://avatars.githubusercontent.com/u/10513829?v=3","gravatar_id":"","url":"https://api.github.com/users/abigailm","html_url":"https://github.com/abigailm","followers_url":"https://api.github.com/users/abigailm/followers","following_url":"https://api.github.com/users/abigailm/following{/other_user}","gists_url":"https://api.github.com/users/abigailm/gists{/gist_id}","starred_url":"https://api.github.com/users/abigailm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/abigailm/subscriptions","organizations_url":"https://api.github.com/users/abigailm/orgs","repos_url":"https://api.github.com/users/abigailm/repos","events_url":"https://api.github.com/users/abigailm/events{/privacy}","received_events_url":"https://api.github.com/users/abigailm/received_events","type":"User","site_admin":false},"body":"I would prefer that it checks that it is the correct weight change, to make sure the delays are properly accounted for etc. ","created_at":"2015-10-16T13:10:51Z","updated_at":"2015-10-16T13:10:51Z","html_url":"https://github.com/nest/nest-simulator/pull/118#discussion_r42240052","pull_request_url":"https://api.github.com/repos/nest/nest-simulator/pulls/118","_links":{"self":{"href":"https://api.github.com/repos/nest/nest-simulator/pulls/comments/42240052"},"html":{"href":"https://github.com/nest/nest-simulator/pull/118#discussion_r42240052"},"pull_request":{"href":"https://api.github.com/repos/nest/nest-simulator/pulls/118"}}},"pull_request":{"url":"https://api.github.com/repos/nest/nest-simulator/pulls/118","id":46711316,"html_url":"https://github.com/nest/nest-simulator/pull/118","diff_url":"https://github.com/nest/nest-simulator/pull/118.diff","patch_url":"https://github.com/nest/nest-simulator/pull/118.patch","issue_url":"https://api.github.com/repos/nest/nest-simulator/issues/118","number":118,"state":"open","locked":false,"title":"Extended parrot_neuron to allow connections onto port 0 and 1, not repeating spikes on port 1","user":{"login":"flinz","id":97735,"avatar_url":"https://avatars.githubusercontent.com/u/97735?v=3","gravatar_id":"","url":"https://api.github.com/users/flinz","html_url":"https://github.com/flinz","followers_url":"https://api.github.com/users/flinz/followers","following_url":"https://api.github.com/users/flinz/following{/other_user}","gists_url":"https://api.github.com/users/flinz/gists{/gist_id}","starred_url":"https://api.github.com/users/flinz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/flinz/subscriptions","organizations_url":"https://api.github.com/users/flinz/orgs","repos_url":"https://api.github.com/users/flinz/repos","events_url":"https://api.github.com/users/flinz/events{/privacy}","received_events_url":"https://api.github.com/users/flinz/received_events","type":"User","site_admin":false},"body":"This allows setting pre- and postsynaptic spike times for STDP protocols by connecting two parrot neurons onto port 1 postsynaptically by, e.g., a stdp_synapse. Thanks to @heplesser for your advice.\r\n\r\nHere is a short test/demonstration\r\n```python\r\nimport nest\r\nimport pylab as pl\r\nimport numpy as np\r\nnest.set_verbosity(\"M_WARNING\")\r\nnest.ResetKernel()\r\n\r\n# set pre and postsynaptic spike times\r\ndt = 50.\r\npre_times = np.arange(100, 1101, 200., float)\r\npost_times = pre_times + dt\r\n\r\n# create spike_generators with these times\r\npre_spikes = nest.Create(\"spike_generator\", 1, {\"spike_times\": pre_times})\r\npost_spikes = nest.Create(\"spike_generator\", 1, {\"spike_times\": post_times})\r\n\r\n# create parrot neurons and connect spike_generators\r\npre_parrot = nest.Create(\"parrot_neuron\", 1)\r\npost_parrot = nest.Create(\"parrot_neuron\", 1)\r\nnest.Connect(pre_spikes, pre_parrot)\r\nnest.Connect(post_spikes, post_parrot)\r\n\r\n# connect both parrot neurons with a stdp synapse onto port 1\r\n# thereby spikes transmitted through the stdp connection are\r\n# not repeated postsynaptically.\r\nsyn_spec = {\r\n   \"model\": \"stdp_synapse\",\r\n   \"receptor_type\": 1  # set receptor 1 postsynaptically, to not generate extra spikes\r\n}\r\nconn_spec = {\r\n   \"rule\": \"one_to_one\",\r\n}\r\nnest.Connect(pre_parrot, post_parrot, syn_spec=syn_spec, conn_spec=conn_spec)\r\n\r\n# simulate for ~1s and print connection weights every 100ms\r\nnest.Simulate(75)\r\nfor _ in range(5):\r\n   nest.Simulate(200)\r\n   print nest.GetStatus(nest.GetConnections(source=pre_parrot))[0]['weight']\r\n```\r\n","created_at":"2015-10-03T19:16:06Z","updated_at":"2015-10-16T13:10:51Z","closed_at":null,"merged_at":null,"merge_commit_sha":"7470f961feff460a57f88490c51bd2937148d325","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/nest/nest-simulator/pulls/118/commits","review_comments_url":"https://api.github.com/repos/nest/nest-simulator/pulls/118/comments","review_comment_url":"https://api.github.com/repos/nest/nest-simulator/pulls/comments{/number}","comments_url":"https://api.github.com/repos/nest/nest-simulator/issues/118/comments","statuses_url":"https://api.github.com/repos/nest/nest-simulator/statuses/0c20ff3b64911dce25515ad0351b6ecbc51d3cab","head":{"label":"flinz:parrot-multiport","ref":"parrot-multiport","sha":"0c20ff3b64911dce25515ad0351b6ecbc51d3cab","user":{"login":"flinz","id":97735,"avatar_url":"https://avatars.githubusercontent.com/u/97735?v=3","gravatar_id":"","url":"https://api.github.com/users/flinz","html_url":"https://github.com/flinz","followers_url":"https://api.github.com/users/flinz/followers","following_url":"https://api.github.com/users/flinz/following{/other_user}","gists_url":"https://api.github.com/users/flinz/gists{/gist_id}","starred_url":"https://api.github.com/users/flinz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/flinz/subscriptions","organizations_url":"https://api.github.com/users/flinz/orgs","repos_url":"https://api.github.com/users/flinz/repos","events_url":"https://api.github.com/users/flinz/events{/privacy}","received_events_url":"https://api.github.com/users/flinz/received_events","type":"User","site_admin":false},"repo":{"id":43309874,"name":"nest-simulator","full_name":"flinz/nest-simulator","owner":{"login":"flinz","id":97735,"avatar_url":"https://avatars.githubusercontent.com/u/97735?v=3","gravatar_id":"","url":"https://api.github.com/users/flinz","html_url":"https://github.com/flinz","followers_url":"https://api.github.com/users/flinz/followers","following_url":"https://api.github.com/users/flinz/following{/other_user}","gists_url":"https://api.github.com/users/flinz/gists{/gist_id}","starred_url":"https://api.github.com/users/flinz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/flinz/subscriptions","organizations_url":"https://api.github.com/users/flinz/orgs","repos_url":"https://api.github.com/users/flinz/repos","events_url":"https://api.github.com/users/flinz/events{/privacy}","received_events_url":"https://api.github.com/users/flinz/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/flinz/nest-simulator","description":"The NEST simulator","fork":true,"url":"https://api.github.com/repos/flinz/nest-simulator","forks_url":"https://api.github.com/repos/flinz/nest-simulator/forks","keys_url":"https://api.github.com/repos/flinz/nest-simulator/keys{/key_id}","collaborators_url":"https://api.github.com/repos/flinz/nest-simulator/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/flinz/nest-simulator/teams","hooks_url":"https://api.github.com/repos/flinz/nest-simulator/hooks","issue_events_url":"https://api.github.com/repos/flinz/nest-simulator/issues/events{/number}","events_url":"https://api.github.com/repos/flinz/nest-simulator/events","assignees_url":"https://api.github.com/repos/flinz/nest-simulator/assignees{/user}","branches_url":"https://api.github.com/repos/flinz/nest-simulator/branches{/branch}","tags_url":"https://api.github.com/repos/flinz/nest-simulator/tags","blobs_url":"https://api.github.com/repos/flinz/nest-simulator/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/flinz/nest-simulator/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/flinz/nest-simulator/git/refs{/sha}","trees_url":"https://api.github.com/repos/flinz/nest-simulator/git/trees{/sha}","statuses_url":"https://api.github.com/repos/flinz/nest-simulator/statuses/{sha}","languages_url":"https://api.github.com/repos/flinz/nest-simulator/languages","stargazers_url":"https://api.github.com/repos/flinz/nest-simulator/stargazers","contributors_url":"https://api.github.com/repos/flinz/nest-simulator/contributors","subscribers_url":"https://api.github.com/repos/flinz/nest-simulator/subscribers","subscription_url":"https://api.github.com/repos/flinz/nest-simulator/subscription","commits_url":"https://api.github.com/repos/flinz/nest-simulator/commits{/sha}","git_commits_url":"https://api.github.com/repos/flinz/nest-simulator/git/commits{/sha}","comments_url":"https://api.github.com/repos/flinz/nest-simulator/comments{/number}","issue_comment_url":"https://api.github.com/repos/flinz/nest-simulator/issues/comments{/number}","contents_url":"https://api.github.com/repos/flinz/nest-simulator/contents/{+path}","compare_url":"https://api.github.com/repos/flinz/nest-simulator/compare/{base}...{head}","merges_url":"https://api.github.com/repos/flinz/nest-simulator/merges","archive_url":"https://api.github.com/repos/flinz/nest-simulator/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/flinz/nest-simulator/downloads","issues_url":"https://api.github.com/repos/flinz/nest-simulator/issues{/number}","pulls_url":"https://api.github.com/repos/flinz/nest-simulator/pulls{/number}","milestones_url":"https://api.github.com/repos/flinz/nest-simulator/milestones{/number}","notifications_url":"https://api.github.com/repos/flinz/nest-simulator/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/flinz/nest-simulator/labels{/name}","releases_url":"https://api.github.com/repos/flinz/nest-simulator/releases{/id}","created_at":"2015-09-28T15:38:01Z","updated_at":"2015-09-28T15:38:05Z","pushed_at":"2015-10-09T15:25:57Z","git_url":"git://github.com/flinz/nest-simulator.git","ssh_url":"git@github.com:flinz/nest-simulator.git","clone_url":"https://github.com/flinz/nest-simulator.git","svn_url":"https://github.com/flinz/nest-simulator","homepage":null,"size":17801,"stargazers_count":0,"watchers_count":0,"language":"C++","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"nest:master","ref":"master","sha":"ed3cab678a08750c7787f202da7f7cb6d2c87fe6","user":{"login":"nest","id":2377019,"avatar_url":"https://avatars.githubusercontent.com/u/2377019?v=3","gravatar_id":"","url":"https://api.github.com/users/nest","html_url":"https://github.com/nest","followers_url":"https://api.github.com/users/nest/followers","following_url":"https://api.github.com/users/nest/following{/other_user}","gists_url":"https://api.github.com/users/nest/gists{/gist_id}","starred_url":"https://api.github.com/users/nest/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nest/subscriptions","organizations_url":"https://api.github.com/users/nest/orgs","repos_url":"https://api.github.com/users/nest/repos","events_url":"https://api.github.com/users/nest/events{/privacy}","received_events_url":"https://api.github.com/users/nest/received_events","type":"Organization","site_admin":false},"repo":{"id":33933892,"name":"nest-simulator","full_name":"nest/nest-simulator","owner":{"login":"nest","id":2377019,"avatar_url":"https://avatars.githubusercontent.com/u/2377019?v=3","gravatar_id":"","url":"https://api.github.com/users/nest","html_url":"https://github.com/nest","followers_url":"https://api.github.com/users/nest/followers","following_url":"https://api.github.com/users/nest/following{/other_user}","gists_url":"https://api.github.com/users/nest/gists{/gist_id}","starred_url":"https://api.github.com/users/nest/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nest/subscriptions","organizations_url":"https://api.github.com/users/nest/orgs","repos_url":"https://api.github.com/users/nest/repos","events_url":"https://api.github.com/users/nest/events{/privacy}","received_events_url":"https://api.github.com/users/nest/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/nest/nest-simulator","description":"The NEST simulator","fork":false,"url":"https://api.github.com/repos/nest/nest-simulator","forks_url":"https://api.github.com/repos/nest/nest-simulator/forks","keys_url":"https://api.github.com/repos/nest/nest-simulator/keys{/key_id}","collaborators_url":"https://api.github.com/repos/nest/nest-simulator/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/nest/nest-simulator/teams","hooks_url":"https://api.github.com/repos/nest/nest-simulator/hooks","issue_events_url":"https://api.github.com/repos/nest/nest-simulator/issues/events{/number}","events_url":"https://api.github.com/repos/nest/nest-simulator/events","assignees_url":"https://api.github.com/repos/nest/nest-simulator/assignees{/user}","branches_url":"https://api.github.com/repos/nest/nest-simulator/branches{/branch}","tags_url":"https://api.github.com/repos/nest/nest-simulator/tags","blobs_url":"https://api.github.com/repos/nest/nest-simulator/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/nest/nest-simulator/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/nest/nest-simulator/git/refs{/sha}","trees_url":"https://api.github.com/repos/nest/nest-simulator/git/trees{/sha}","statuses_url":"https://api.github.com/repos/nest/nest-simulator/statuses/{sha}","languages_url":"https://api.github.com/repos/nest/nest-simulator/languages","stargazers_url":"https://api.github.com/repos/nest/nest-simulator/stargazers","contributors_url":"https://api.github.com/repos/nest/nest-simulator/contributors","subscribers_url":"https://api.github.com/repos/nest/nest-simulator/subscribers","subscription_url":"https://api.github.com/repos/nest/nest-simulator/subscription","commits_url":"https://api.github.com/repos/nest/nest-simulator/commits{/sha}","git_commits_url":"https://api.github.com/repos/nest/nest-simulator/git/commits{/sha}","comments_url":"https://api.github.com/repos/nest/nest-simulator/comments{/number}","issue_comment_url":"https://api.github.com/repos/nest/nest-simulator/issues/comments{/number}","contents_url":"https://api.github.com/repos/nest/nest-simulator/contents/{+path}","compare_url":"https://api.github.com/repos/nest/nest-simulator/compare/{base}...{head}","merges_url":"https://api.github.com/repos/nest/nest-simulator/merges","archive_url":"https://api.github.com/repos/nest/nest-simulator/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/nest/nest-simulator/downloads","issues_url":"https://api.github.com/repos/nest/nest-simulator/issues{/number}","pulls_url":"https://api.github.com/repos/nest/nest-simulator/pulls{/number}","milestones_url":"https://api.github.com/repos/nest/nest-simulator/milestones{/number}","notifications_url":"https://api.github.com/repos/nest/nest-simulator/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/nest/nest-simulator/labels{/name}","releases_url":"https://api.github.com/repos/nest/nest-simulator/releases{/id}","created_at":"2015-04-14T13:39:12Z","updated_at":"2015-10-16T09:57:31Z","pushed_at":"2015-10-16T10:48:34Z","git_url":"git://github.com/nest/nest-simulator.git","ssh_url":"git@github.com:nest/nest-simulator.git","clone_url":"https://github.com/nest/nest-simulator.git","svn_url":"https://github.com/nest/nest-simulator","homepage":null,"size":19048,"stargazers_count":55,"watchers_count":55,"language":"C++","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":50,"mirror_url":null,"open_issues_count":31,"forks":50,"open_issues":31,"watchers":55,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/nest/nest-simulator/pulls/118"},"html":{"href":"https://github.com/nest/nest-simulator/pull/118"},"issue":{"href":"https://api.github.com/repos/nest/nest-simulator/issues/118"},"comments":{"href":"https://api.github.com/repos/nest/nest-simulator/issues/118/comments"},"review_comments":{"href":"https://api.github.com/repos/nest/nest-simulator/pulls/118/comments"},"review_comment":{"href":"https://api.github.com/repos/nest/nest-simulator/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/nest/nest-simulator/pulls/118/commits"},"statuses":{"href":"https://api.github.com/repos/nest/nest-simulator/statuses/0c20ff3b64911dce25515ad0351b6ecbc51d3cab"}}}}