{"action":"created","comment":{"url":"https://api.github.com/repos/project-rig/rig/pulls/comments/46093389","id":46093389,"diff_hunk":"@@ -1739,34 +1807,169 @@ def get_machine(self, x=0, y=0, default_num_cores=18):\n         chip_resource_exceptions = {}\n \n         # Discover dead links and cores\n-        for (x, y), p2p_route in iteritems(p2p_tables):\n-            if x <= max_x and y <= max_y:\n-                if p2p_route == consts.P2PTableEntry.none:\n+        for x in range(width):\n+            for y in range(height):\n+                chip_info = chips_info.get((x, y))\n+                if chip_info is None:\n                     dead_chips.add((x, y))\n                 else:\n-                    try:\n-                        num_working_cores = self.get_num_working_cores(x, y)\n-                        working_links = self.get_working_links(x, y)\n-\n-                        if num_working_cores < default_num_cores:\n-                            resource_exception = chip_resources.copy()\n-                            resource_exception[Cores] = min(default_num_cores,\n-                                                            num_working_cores)\n-                            chip_resource_exceptions[(x, y)] = \\\n-                                resource_exception\n-\n-                        for link in set(Links) - working_links:\n-                            dead_links.add((x, y, link))\n-                    except SCPError:\n-                        # The chip was listed in the P2P table but is not\n-                        # responding. Assume it is dead anyway.\n-                        dead_chips.add((x, y))\n+                    if chip_info.num_cores < default_num_cores:\n+                        resource_exception = chip_resources.copy()\n+                        resource_exception[Cores] = min(default_num_cores,\n+                                                        chip_info.num_cores)\n+                        chip_resource_exceptions[(x, y)] = \\\n+                            resource_exception\n \n-        return Machine(max_x + 1, max_y + 1,\n+                    for link in set(Links) - chip_info.working_links:\n+                        dead_links.add((x, y, link))\n+\n+        return Machine(width, height,\n                        chip_resources,\n                        chip_resource_exceptions,\n                        dead_chips, dead_links)\n \n+    @ContextMixin.use_contextual_arguments()\n+    def get_resource_constraints(self, machine,\n+                                 core_resource=Cores,\n+                                 sdram_resource=SDRAM,\n+                                 sram_resource=SRAM,\n+                                 _all_chips_info=None):\n+        \"\"\"Returns a set of place-and-route\n+        :py:class:`~rig.place_and_route.constraints` which reserves any cores\n+        and SDRAM that are already in use.\n+\n+        .. note::\n+            Most users will probably prefer to use\n+            :py:meth:`.get_machine_and_resource_constraints` which both gets a\n+            :py:class:`rig.machine.Machine` object and a set of place-and-route\n+            constraints with reduced overhead over calling both methods\n+            individually.\n+\n+        This method, like :py:meth:`get_machine`, is aimed at users of Rig's\n+        place-and-route tools and assumes that one resource type represents\n+        Cores while another represents SDRAM.\n+\n+        The returned set of\n+        :py:class:`~rig.place_and_route.constraints.ReserveResourceConstraint`s\n+        reserves all cores not in an Idle state (i.e. not a monitor and not\n+        already running an application).\n+\n+        This set also reserves ranges of SDRAM/SRAM starting at the top\n+        (highest address) to reduce the resource availability on each chip to\n+        approximately the amount actually available in the machine, accounting\n+        for any already-running applications. Note that due to memory\n+        fragmentation this constraint will make a conservative estimate based\n+        on the largest free block of SDRAM/SRAM in the heap.\n+\n+        Parameters\n+        ----------\n+        machine : :py:class:`~rig.machine.Machine`\n+            The :py:class:`~rig.machine.Machine` model of the current SpiNNaker\n+            machine (e.g. from :py:meth:`get_machine`).\n+        core_resource : resource (Default: :py:data:`~rig.machine.Cores`)\n+            The resource identifier used for cores. If using\n+            :py:meth:`get_machine`, the default correct.\n+        sdram_resource : resource (Default: :py:data:`~rig.machine.SDRAM`)\n+            The resource identifier used for SDRAM. If using\n+            :py:meth:`get_machine`, the default correct.\n+        sram_resource : resource (Default: :py:data:`~rig.machine.SRAM`)\n+            The resource identifier used for SRAM. If using\n+            :py:meth:`get_machine`, the default correct.\n+        _all_chips_info : None\n+            For internal use only. Users should leave this as None.\n+\n+        Returns\n+        -------\n+        [\\\n+        :py:class:`rig.place_and_route.constraints.ReserveResourceConstraint`,\\\n+        ...]\n+            A set of place-and-route constraints which reserves non-idle cores\n+            and SDRAM. The resource types given in the ``core_resource`` and\n+            ``sdram_resource`` arguments will be reserved accordingly.\n+        \"\"\"\n+        if _all_chips_info is not None:\n+            chips_info = _all_chips_info[2]\n+        else:\n+            chips_info = {}","path":"rig/machine_control/machine_controller.py","position":270,"original_position":270,"commit_id":"a109cb32f7e0c4ac46341dd375890f31eae9e554","original_commit_id":"a109cb32f7e0c4ac46341dd375890f31eae9e554","user":{"login":"mossblaser","id":193514,"avatar_url":"https://avatars.githubusercontent.com/u/193514?v=3","gravatar_id":"","url":"https://api.github.com/users/mossblaser","html_url":"https://github.com/mossblaser","followers_url":"https://api.github.com/users/mossblaser/followers","following_url":"https://api.github.com/users/mossblaser/following{/other_user}","gists_url":"https://api.github.com/users/mossblaser/gists{/gist_id}","starred_url":"https://api.github.com/users/mossblaser/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mossblaser/subscriptions","organizations_url":"https://api.github.com/users/mossblaser/orgs","repos_url":"https://api.github.com/users/mossblaser/repos","events_url":"https://api.github.com/users/mossblaser/events{/privacy}","received_events_url":"https://api.github.com/users/mossblaser/received_events","type":"User","site_admin":false},"body":"The factory function to a defaultdict doesn't get given any arguments so sadly this is not possible.","created_at":"2015-11-29T15:12:18Z","updated_at":"2015-11-29T15:12:18Z","html_url":"https://github.com/project-rig/rig/pull/206#discussion_r46093389","pull_request_url":"https://api.github.com/repos/project-rig/rig/pulls/206","_links":{"self":{"href":"https://api.github.com/repos/project-rig/rig/pulls/comments/46093389"},"html":{"href":"https://github.com/project-rig/rig/pull/206#discussion_r46093389"},"pull_request":{"href":"https://api.github.com/repos/project-rig/rig/pulls/206"}}},"pull_request":{"url":"https://api.github.com/repos/project-rig/rig/pulls/206","id":51896392,"html_url":"https://github.com/project-rig/rig/pull/206","diff_url":"https://github.com/project-rig/rig/pull/206.diff","patch_url":"https://github.com/project-rig/rig/pull/206.patch","issue_url":"https://api.github.com/repos/project-rig/rig/issues/206","number":206,"state":"open","locked":false,"title":"Only use idle cores","user":{"login":"mossblaser","id":193514,"avatar_url":"https://avatars.githubusercontent.com/u/193514?v=3","gravatar_id":"","url":"https://api.github.com/users/mossblaser","html_url":"https://github.com/mossblaser","followers_url":"https://api.github.com/users/mossblaser/followers","following_url":"https://api.github.com/users/mossblaser/following{/other_user}","gists_url":"https://api.github.com/users/mossblaser/gists{/gist_id}","starred_url":"https://api.github.com/users/mossblaser/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mossblaser/subscriptions","organizations_url":"https://api.github.com/users/mossblaser/orgs","repos_url":"https://api.github.com/users/mossblaser/repos","events_url":"https://api.github.com/users/mossblaser/events{/privacy}","received_events_url":"https://api.github.com/users/mossblaser/received_events","type":"User","site_admin":false},"body":"Following the suggestions in #202 adds a new `get_resource_constraints` command which produces a set of P&R constraints which reserves all in-use resources on the remote machine. As a result users will no-longer need to add a ReserveResourceConstraint to prevent core 0 being used by hand, nor worry about running multiple applications simultaneously on the machine.\r\n\r\n* [x] Add `get_chip_info` (using new SC&MP)\r\n* [x] Add `get_resource_constraints`\r\n* [x] Add `get_machine_and_resource_constraints` for efficiency\r\n* [x] ~~Make the P&R wrapper not add a monitor core reservation by default. (Breaking change!)~~ Deprecate old P&R `wrapper` function in place of a better-named, saner-defaulted `place_and_route_wrapper` function.\r\n\r\nAs a bonus, on a SpiNN-5 board the `get_machine()` command now runs in about 80% of the time it used to, the performance gains should become also more dramatic on larger machines. The combined `get_machine_and_resource_constraints` method uses exactly the same set of SCP commands as a single `get_machine`.\r\n\r\nOnce this PR is merged and released, I'll submit patches for other projects.\r\n  * Nengo SpiNNaker\r\n  * pinus_rigida\r\n  * network_tester\r\n  * rig_examples\r\n","created_at":"2015-11-26T10:38:51Z","updated_at":"2015-11-29T15:12:18Z","closed_at":null,"merged_at":null,"merge_commit_sha":"158af53e3b4fd5e36e425a86225a6fe89b5b3e4b","assignee":{"login":"mundya","id":3439837,"avatar_url":"https://avatars.githubusercontent.com/u/3439837?v=3","gravatar_id":"","url":"https://api.github.com/users/mundya","html_url":"https://github.com/mundya","followers_url":"https://api.github.com/users/mundya/followers","following_url":"https://api.github.com/users/mundya/following{/other_user}","gists_url":"https://api.github.com/users/mundya/gists{/gist_id}","starred_url":"https://api.github.com/users/mundya/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mundya/subscriptions","organizations_url":"https://api.github.com/users/mundya/orgs","repos_url":"https://api.github.com/users/mundya/repos","events_url":"https://api.github.com/users/mundya/events{/privacy}","received_events_url":"https://api.github.com/users/mundya/received_events","type":"User","site_admin":false},"milestone":{"url":"https://api.github.com/repos/project-rig/rig/milestones/1","html_url":"https://github.com/project-rig/rig/milestones/1.0","labels_url":"https://api.github.com/repos/project-rig/rig/milestones/1/labels","id":945495,"number":1,"title":"1.0","description":"A working release for use with Nengo/SpiNNaker.","creator":{"login":"mundya","id":3439837,"avatar_url":"https://avatars.githubusercontent.com/u/3439837?v=3","gravatar_id":"","url":"https://api.github.com/users/mundya","html_url":"https://github.com/mundya","followers_url":"https://api.github.com/users/mundya/followers","following_url":"https://api.github.com/users/mundya/following{/other_user}","gists_url":"https://api.github.com/users/mundya/gists{/gist_id}","starred_url":"https://api.github.com/users/mundya/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mundya/subscriptions","organizations_url":"https://api.github.com/users/mundya/orgs","repos_url":"https://api.github.com/users/mundya/repos","events_url":"https://api.github.com/users/mundya/events{/privacy}","received_events_url":"https://api.github.com/users/mundya/received_events","type":"User","site_admin":false},"open_issues":10,"closed_issues":115,"state":"open","created_at":"2015-01-21T16:25:41Z","updated_at":"2015-11-27T07:27:12Z","due_on":null,"closed_at":null},"commits_url":"https://api.github.com/repos/project-rig/rig/pulls/206/commits","review_comments_url":"https://api.github.com/repos/project-rig/rig/pulls/206/comments","review_comment_url":"https://api.github.com/repos/project-rig/rig/pulls/comments{/number}","comments_url":"https://api.github.com/repos/project-rig/rig/issues/206/comments","statuses_url":"https://api.github.com/repos/project-rig/rig/statuses/a109cb32f7e0c4ac46341dd375890f31eae9e554","head":{"label":"project-rig:only-use-idle-cores","ref":"only-use-idle-cores","sha":"a109cb32f7e0c4ac46341dd375890f31eae9e554","user":{"login":"project-rig","id":11227885,"avatar_url":"https://avatars.githubusercontent.com/u/11227885?v=3","gravatar_id":"","url":"https://api.github.com/users/project-rig","html_url":"https://github.com/project-rig","followers_url":"https://api.github.com/users/project-rig/followers","following_url":"https://api.github.com/users/project-rig/following{/other_user}","gists_url":"https://api.github.com/users/project-rig/gists{/gist_id}","starred_url":"https://api.github.com/users/project-rig/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/project-rig/subscriptions","organizations_url":"https://api.github.com/users/project-rig/orgs","repos_url":"https://api.github.com/users/project-rig/repos","events_url":"https://api.github.com/users/project-rig/events{/privacy}","received_events_url":"https://api.github.com/users/project-rig/received_events","type":"Organization","site_admin":false},"repo":{"id":29497314,"name":"rig","full_name":"project-rig/rig","owner":{"login":"project-rig","id":11227885,"avatar_url":"https://avatars.githubusercontent.com/u/11227885?v=3","gravatar_id":"","url":"https://api.github.com/users/project-rig","html_url":"https://github.com/project-rig","followers_url":"https://api.github.com/users/project-rig/followers","following_url":"https://api.github.com/users/project-rig/following{/other_user}","gists_url":"https://api.github.com/users/project-rig/gists{/gist_id}","starred_url":"https://api.github.com/users/project-rig/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/project-rig/subscriptions","organizations_url":"https://api.github.com/users/project-rig/orgs","repos_url":"https://api.github.com/users/project-rig/repos","events_url":"https://api.github.com/users/project-rig/events{/privacy}","received_events_url":"https://api.github.com/users/project-rig/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/project-rig/rig","description":"A collection of tools for developing SpiNNaker applications.","fork":false,"url":"https://api.github.com/repos/project-rig/rig","forks_url":"https://api.github.com/repos/project-rig/rig/forks","keys_url":"https://api.github.com/repos/project-rig/rig/keys{/key_id}","collaborators_url":"https://api.github.com/repos/project-rig/rig/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/project-rig/rig/teams","hooks_url":"https://api.github.com/repos/project-rig/rig/hooks","issue_events_url":"https://api.github.com/repos/project-rig/rig/issues/events{/number}","events_url":"https://api.github.com/repos/project-rig/rig/events","assignees_url":"https://api.github.com/repos/project-rig/rig/assignees{/user}","branches_url":"https://api.github.com/repos/project-rig/rig/branches{/branch}","tags_url":"https://api.github.com/repos/project-rig/rig/tags","blobs_url":"https://api.github.com/repos/project-rig/rig/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/project-rig/rig/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/project-rig/rig/git/refs{/sha}","trees_url":"https://api.github.com/repos/project-rig/rig/git/trees{/sha}","statuses_url":"https://api.github.com/repos/project-rig/rig/statuses/{sha}","languages_url":"https://api.github.com/repos/project-rig/rig/languages","stargazers_url":"https://api.github.com/repos/project-rig/rig/stargazers","contributors_url":"https://api.github.com/repos/project-rig/rig/contributors","subscribers_url":"https://api.github.com/repos/project-rig/rig/subscribers","subscription_url":"https://api.github.com/repos/project-rig/rig/subscription","commits_url":"https://api.github.com/repos/project-rig/rig/commits{/sha}","git_commits_url":"https://api.github.com/repos/project-rig/rig/git/commits{/sha}","comments_url":"https://api.github.com/repos/project-rig/rig/comments{/number}","issue_comment_url":"https://api.github.com/repos/project-rig/rig/issues/comments{/number}","contents_url":"https://api.github.com/repos/project-rig/rig/contents/{+path}","compare_url":"https://api.github.com/repos/project-rig/rig/compare/{base}...{head}","merges_url":"https://api.github.com/repos/project-rig/rig/merges","archive_url":"https://api.github.com/repos/project-rig/rig/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/project-rig/rig/downloads","issues_url":"https://api.github.com/repos/project-rig/rig/issues{/number}","pulls_url":"https://api.github.com/repos/project-rig/rig/pulls{/number}","milestones_url":"https://api.github.com/repos/project-rig/rig/milestones{/number}","notifications_url":"https://api.github.com/repos/project-rig/rig/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/project-rig/rig/labels{/name}","releases_url":"https://api.github.com/repos/project-rig/rig/releases{/id}","created_at":"2015-01-19T21:20:40Z","updated_at":"2015-05-03T15:04:13Z","pushed_at":"2015-11-27T07:27:26Z","git_url":"git://github.com/project-rig/rig.git","ssh_url":"git@github.com:project-rig/rig.git","clone_url":"https://github.com/project-rig/rig.git","svn_url":"https://github.com/project-rig/rig","homepage":"","size":1954,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":14,"forks":1,"open_issues":14,"watchers":0,"default_branch":"master"}},"base":{"label":"project-rig:master","ref":"master","sha":"00dd4877ea55466ffc794d2ef6174a8e944c264d","user":{"login":"project-rig","id":11227885,"avatar_url":"https://avatars.githubusercontent.com/u/11227885?v=3","gravatar_id":"","url":"https://api.github.com/users/project-rig","html_url":"https://github.com/project-rig","followers_url":"https://api.github.com/users/project-rig/followers","following_url":"https://api.github.com/users/project-rig/following{/other_user}","gists_url":"https://api.github.com/users/project-rig/gists{/gist_id}","starred_url":"https://api.github.com/users/project-rig/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/project-rig/subscriptions","organizations_url":"https://api.github.com/users/project-rig/orgs","repos_url":"https://api.github.com/users/project-rig/repos","events_url":"https://api.github.com/users/project-rig/events{/privacy}","received_events_url":"https://api.github.com/users/project-rig/received_events","type":"Organization","site_admin":false},"repo":{"id":29497314,"name":"rig","full_name":"project-rig/rig","owner":{"login":"project-rig","id":11227885,"avatar_url":"https://avatars.githubusercontent.com/u/11227885?v=3","gravatar_id":"","url":"https://api.github.com/users/project-rig","html_url":"https://github.com/project-rig","followers_url":"https://api.github.com/users/project-rig/followers","following_url":"https://api.github.com/users/project-rig/following{/other_user}","gists_url":"https://api.github.com/users/project-rig/gists{/gist_id}","starred_url":"https://api.github.com/users/project-rig/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/project-rig/subscriptions","organizations_url":"https://api.github.com/users/project-rig/orgs","repos_url":"https://api.github.com/users/project-rig/repos","events_url":"https://api.github.com/users/project-rig/events{/privacy}","received_events_url":"https://api.github.com/users/project-rig/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/project-rig/rig","description":"A collection of tools for developing SpiNNaker applications.","fork":false,"url":"https://api.github.com/repos/project-rig/rig","forks_url":"https://api.github.com/repos/project-rig/rig/forks","keys_url":"https://api.github.com/repos/project-rig/rig/keys{/key_id}","collaborators_url":"https://api.github.com/repos/project-rig/rig/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/project-rig/rig/teams","hooks_url":"https://api.github.com/repos/project-rig/rig/hooks","issue_events_url":"https://api.github.com/repos/project-rig/rig/issues/events{/number}","events_url":"https://api.github.com/repos/project-rig/rig/events","assignees_url":"https://api.github.com/repos/project-rig/rig/assignees{/user}","branches_url":"https://api.github.com/repos/project-rig/rig/branches{/branch}","tags_url":"https://api.github.com/repos/project-rig/rig/tags","blobs_url":"https://api.github.com/repos/project-rig/rig/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/project-rig/rig/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/project-rig/rig/git/refs{/sha}","trees_url":"https://api.github.com/repos/project-rig/rig/git/trees{/sha}","statuses_url":"https://api.github.com/repos/project-rig/rig/statuses/{sha}","languages_url":"https://api.github.com/repos/project-rig/rig/languages","stargazers_url":"https://api.github.com/repos/project-rig/rig/stargazers","contributors_url":"https://api.github.com/repos/project-rig/rig/contributors","subscribers_url":"https://api.github.com/repos/project-rig/rig/subscribers","subscription_url":"https://api.github.com/repos/project-rig/rig/subscription","commits_url":"https://api.github.com/repos/project-rig/rig/commits{/sha}","git_commits_url":"https://api.github.com/repos/project-rig/rig/git/commits{/sha}","comments_url":"https://api.github.com/repos/project-rig/rig/comments{/number}","issue_comment_url":"https://api.github.com/repos/project-rig/rig/issues/comments{/number}","contents_url":"https://api.github.com/repos/project-rig/rig/contents/{+path}","compare_url":"https://api.github.com/repos/project-rig/rig/compare/{base}...{head}","merges_url":"https://api.github.com/repos/project-rig/rig/merges","archive_url":"https://api.github.com/repos/project-rig/rig/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/project-rig/rig/downloads","issues_url":"https://api.github.com/repos/project-rig/rig/issues{/number}","pulls_url":"https://api.github.com/repos/project-rig/rig/pulls{/number}","milestones_url":"https://api.github.com/repos/project-rig/rig/milestones{/number}","notifications_url":"https://api.github.com/repos/project-rig/rig/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/project-rig/rig/labels{/name}","releases_url":"https://api.github.com/repos/project-rig/rig/releases{/id}","created_at":"2015-01-19T21:20:40Z","updated_at":"2015-05-03T15:04:13Z","pushed_at":"2015-11-27T07:27:26Z","git_url":"git://github.com/project-rig/rig.git","ssh_url":"git@github.com:project-rig/rig.git","clone_url":"https://github.com/project-rig/rig.git","svn_url":"https://github.com/project-rig/rig","homepage":"","size":1954,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":14,"forks":1,"open_issues":14,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/project-rig/rig/pulls/206"},"html":{"href":"https://github.com/project-rig/rig/pull/206"},"issue":{"href":"https://api.github.com/repos/project-rig/rig/issues/206"},"comments":{"href":"https://api.github.com/repos/project-rig/rig/issues/206/comments"},"review_comments":{"href":"https://api.github.com/repos/project-rig/rig/pulls/206/comments"},"review_comment":{"href":"https://api.github.com/repos/project-rig/rig/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/project-rig/rig/pulls/206/commits"},"statuses":{"href":"https://api.github.com/repos/project-rig/rig/statuses/a109cb32f7e0c4ac46341dd375890f31eae9e554"}}}}