{"action":"created","comment":{"url":"https://api.github.com/repos/pfnet/chainer/pulls/comments/33837104","id":33837104,"diff_hunk":"@@ -0,0 +1,201 @@\n+import heapq\n+\n+from chainer import function\n+from chainer import variable\n+\n+\n+class DotNode(object):\n+    \"\"\"Node of computational graph, with utilities for dot language\n+\n+    This class represents a node of computational graph,\n+    with some utilities for dot language\n+    \"\"\"\n+\n+    def __init__(self, node):\n+        \"\"\"Initialize DotNode\n+\n+        Args:\n+            node: :class: `Variable` object or :class: `Function` object\n+        \"\"\"\n+\n+        assert isinstance(node, variable.Variable) or\\\n+            isinstance(node, function.Function)\n+        self.node = node\n+        self.id_ = id(node)\n+        self.attribute = {\n+            \"label\": self.node.label,\n+            \"shape\": self._shape()\n+        }\n+\n+    def _shape(self):\n+        \"\"\"Return shape type of node\n+\n+        \"\"\"\n+\n+        if isinstance(self.node, variable.Variable):\n+            return \"oval\"\n+        elif isinstance(self.node, function.Split):\n+            return \"hexagon\"\n+        else:\n+            return \"box\"\n+\n+    @property\n+    def label(self):\n+        \"\"\"Return label that represents its property\n+\n+        Returns:\n+            string: label that represents its id and attributes\n+        \"\"\"\n+\n+        attributes = [\"%s=\\\"%s\\\"\" % (k, v) for (k, v)\n+                      in self.attribute.items()]\n+        return \"%s [%s];\" % (self.id_, \",\".join(attributes))\n+\n+\n+class ComputationalGraph(object):\n+    \"\"\"Class that represents computational graph\n+\n+    .. note::\n+\n+      We assume that computational graph is directed and is a DAG.\n+    \"\"\"\n+\n+    def __init__(self, edges):\n+        \"\"\"Initialize computational graph","path":"chainer/computational_graph.py","position":64,"original_position":64,"commit_id":"019f2759df3d9423f0d28470cd792bc82aaf902d","original_commit_id":"019f2759df3d9423f0d28470cd792bc82aaf902d","user":{"login":"beam2d","id":392019,"avatar_url":"https://avatars.githubusercontent.com/u/392019?v=3","gravatar_id":"","url":"https://api.github.com/users/beam2d","html_url":"https://github.com/beam2d","followers_url":"https://api.github.com/users/beam2d/followers","following_url":"https://api.github.com/users/beam2d/following{/other_user}","gists_url":"https://api.github.com/users/beam2d/gists{/gist_id}","starred_url":"https://api.github.com/users/beam2d/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/beam2d/subscriptions","organizations_url":"https://api.github.com/users/beam2d/orgs","repos_url":"https://api.github.com/users/beam2d/repos","events_url":"https://api.github.com/users/beam2d/events{/privacy}","received_events_url":"https://api.github.com/users/beam2d/received_events","type":"User","site_admin":false},"body":"-> Initialize**s** **the** computational graph**.**","created_at":"2015-07-03T02:13:14Z","updated_at":"2015-07-03T02:13:14Z","html_url":"https://github.com/pfnet/chainer/pull/102#discussion_r33837104","pull_request_url":"https://api.github.com/repos/pfnet/chainer/pulls/102","_links":{"self":{"href":"https://api.github.com/repos/pfnet/chainer/pulls/comments/33837104"},"html":{"href":"https://github.com/pfnet/chainer/pull/102#discussion_r33837104"},"pull_request":{"href":"https://api.github.com/repos/pfnet/chainer/pulls/102"}}},"pull_request":{"url":"https://api.github.com/repos/pfnet/chainer/pulls/102","id":38746964,"html_url":"https://github.com/pfnet/chainer/pull/102","diff_url":"https://github.com/pfnet/chainer/pull/102.diff","patch_url":"https://github.com/pfnet/chainer/pull/102.patch","issue_url":"https://api.github.com/repos/pfnet/chainer/issues/102","number":102,"state":"open","locked":false,"title":"Visualize computational graph","user":{"login":"delta2323","id":407052,"avatar_url":"https://avatars.githubusercontent.com/u/407052?v=3","gravatar_id":"","url":"https://api.github.com/users/delta2323","html_url":"https://github.com/delta2323","followers_url":"https://api.github.com/users/delta2323/followers","following_url":"https://api.github.com/users/delta2323/following{/other_user}","gists_url":"https://api.github.com/users/delta2323/gists{/gist_id}","starred_url":"https://api.github.com/users/delta2323/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/delta2323/subscriptions","organizations_url":"https://api.github.com/users/delta2323/orgs","repos_url":"https://api.github.com/users/delta2323/repos","events_url":"https://api.github.com/users/delta2323/events{/privacy}","received_events_url":"https://api.github.com/users/delta2323/received_events","type":"User","site_admin":false},"body":"This PR is implementation of #2 \r\n\r\nBasic usage is as follows.\r\n```\r\nimport chainer.computational_graph as c\r\n...\r\nv1 = Variable(...)\r\nv2 = Variable(...)\r\n...\r\ng = c.computational_graph([v1, v2], remove_split=True)\r\nprint g\r\n```\r\n\r\n`c.computational_graph` generates an instance of `Computational Graph` which represents a graph whose nodes are `Function` and `Variable` that can be traced from variable lists(v1 and v2 in the previous example) as backpropagation does.\r\n`remove_split` option specifies if computational graph skip `Split` Functions. See `test/test_computational_graph.py` for details.\r\n\r\nSupposed use case is available in `example/mnist/train_mnist.py`.\r\n\r\nTODO\r\n- [x] Adjust to the coding style\r\n- [x] test `ComputationalGraph.__str__`\r\n- [ ] More flexible label of DOT nodes (e.g. change label according to `Function` type)\r\n- [ ] Support graph language other than DOT","created_at":"2015-06-29T07:15:37Z","updated_at":"2015-07-03T02:13:14Z","closed_at":null,"merged_at":null,"merge_commit_sha":"e21db8047c59999247af0a3df8de342873ffb083","assignee":{"login":"beam2d","id":392019,"avatar_url":"https://avatars.githubusercontent.com/u/392019?v=3","gravatar_id":"","url":"https://api.github.com/users/beam2d","html_url":"https://github.com/beam2d","followers_url":"https://api.github.com/users/beam2d/followers","following_url":"https://api.github.com/users/beam2d/following{/other_user}","gists_url":"https://api.github.com/users/beam2d/gists{/gist_id}","starred_url":"https://api.github.com/users/beam2d/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/beam2d/subscriptions","organizations_url":"https://api.github.com/users/beam2d/orgs","repos_url":"https://api.github.com/users/beam2d/repos","events_url":"https://api.github.com/users/beam2d/events{/privacy}","received_events_url":"https://api.github.com/users/beam2d/received_events","type":"User","site_admin":false},"milestone":{"url":"https://api.github.com/repos/pfnet/chainer/milestones/2","html_url":"https://github.com/pfnet/chainer/milestones/v1.1.0","labels_url":"https://api.github.com/repos/pfnet/chainer/milestones/2/labels","id":1158011,"number":2,"title":"v1.1.0","description":"","creator":{"login":"beam2d","id":392019,"avatar_url":"https://avatars.githubusercontent.com/u/392019?v=3","gravatar_id":"","url":"https://api.github.com/users/beam2d","html_url":"https://github.com/beam2d","followers_url":"https://api.github.com/users/beam2d/followers","following_url":"https://api.github.com/users/beam2d/following{/other_user}","gists_url":"https://api.github.com/users/beam2d/gists{/gist_id}","starred_url":"https://api.github.com/users/beam2d/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/beam2d/subscriptions","organizations_url":"https://api.github.com/users/beam2d/orgs","repos_url":"https://api.github.com/users/beam2d/repos","events_url":"https://api.github.com/users/beam2d/events{/privacy}","received_events_url":"https://api.github.com/users/beam2d/received_events","type":"User","site_admin":false},"open_issues":10,"closed_issues":16,"state":"open","created_at":"2015-06-10T06:48:11Z","updated_at":"2015-07-03T02:02:35Z","due_on":"2015-07-06T15:00:00Z","closed_at":null},"commits_url":"https://api.github.com/repos/pfnet/chainer/pulls/102/commits","review_comments_url":"https://api.github.com/repos/pfnet/chainer/pulls/102/comments","review_comment_url":"https://api.github.com/repos/pfnet/chainer/pulls/comments{/number}","comments_url":"https://api.github.com/repos/pfnet/chainer/issues/102/comments","statuses_url":"https://api.github.com/repos/pfnet/chainer/statuses/019f2759df3d9423f0d28470cd792bc82aaf902d","head":{"label":"pfnet:visualize_computational_graph","ref":"visualize_computational_graph","sha":"019f2759df3d9423f0d28470cd792bc82aaf902d","user":{"login":"pfnet","id":9739572,"avatar_url":"https://avatars.githubusercontent.com/u/9739572?v=3","gravatar_id":"","url":"https://api.github.com/users/pfnet","html_url":"https://github.com/pfnet","followers_url":"https://api.github.com/users/pfnet/followers","following_url":"https://api.github.com/users/pfnet/following{/other_user}","gists_url":"https://api.github.com/users/pfnet/gists{/gist_id}","starred_url":"https://api.github.com/users/pfnet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pfnet/subscriptions","organizations_url":"https://api.github.com/users/pfnet/orgs","repos_url":"https://api.github.com/users/pfnet/repos","events_url":"https://api.github.com/users/pfnet/events{/privacy}","received_events_url":"https://api.github.com/users/pfnet/received_events","type":"Organization","site_admin":false},"repo":{"id":36914478,"name":"chainer","full_name":"pfnet/chainer","owner":{"login":"pfnet","id":9739572,"avatar_url":"https://avatars.githubusercontent.com/u/9739572?v=3","gravatar_id":"","url":"https://api.github.com/users/pfnet","html_url":"https://github.com/pfnet","followers_url":"https://api.github.com/users/pfnet/followers","following_url":"https://api.github.com/users/pfnet/following{/other_user}","gists_url":"https://api.github.com/users/pfnet/gists{/gist_id}","starred_url":"https://api.github.com/users/pfnet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pfnet/subscriptions","organizations_url":"https://api.github.com/users/pfnet/orgs","repos_url":"https://api.github.com/users/pfnet/repos","events_url":"https://api.github.com/users/pfnet/events{/privacy}","received_events_url":"https://api.github.com/users/pfnet/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/pfnet/chainer","description":"A flexible framework of neural networks for deep learning","fork":false,"url":"https://api.github.com/repos/pfnet/chainer","forks_url":"https://api.github.com/repos/pfnet/chainer/forks","keys_url":"https://api.github.com/repos/pfnet/chainer/keys{/key_id}","collaborators_url":"https://api.github.com/repos/pfnet/chainer/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/pfnet/chainer/teams","hooks_url":"https://api.github.com/repos/pfnet/chainer/hooks","issue_events_url":"https://api.github.com/repos/pfnet/chainer/issues/events{/number}","events_url":"https://api.github.com/repos/pfnet/chainer/events","assignees_url":"https://api.github.com/repos/pfnet/chainer/assignees{/user}","branches_url":"https://api.github.com/repos/pfnet/chainer/branches{/branch}","tags_url":"https://api.github.com/repos/pfnet/chainer/tags","blobs_url":"https://api.github.com/repos/pfnet/chainer/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/pfnet/chainer/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/pfnet/chainer/git/refs{/sha}","trees_url":"https://api.github.com/repos/pfnet/chainer/git/trees{/sha}","statuses_url":"https://api.github.com/repos/pfnet/chainer/statuses/{sha}","languages_url":"https://api.github.com/repos/pfnet/chainer/languages","stargazers_url":"https://api.github.com/repos/pfnet/chainer/stargazers","contributors_url":"https://api.github.com/repos/pfnet/chainer/contributors","subscribers_url":"https://api.github.com/repos/pfnet/chainer/subscribers","subscription_url":"https://api.github.com/repos/pfnet/chainer/subscription","commits_url":"https://api.github.com/repos/pfnet/chainer/commits{/sha}","git_commits_url":"https://api.github.com/repos/pfnet/chainer/git/commits{/sha}","comments_url":"https://api.github.com/repos/pfnet/chainer/comments{/number}","issue_comment_url":"https://api.github.com/repos/pfnet/chainer/issues/comments{/number}","contents_url":"https://api.github.com/repos/pfnet/chainer/contents/{+path}","compare_url":"https://api.github.com/repos/pfnet/chainer/compare/{base}...{head}","merges_url":"https://api.github.com/repos/pfnet/chainer/merges","archive_url":"https://api.github.com/repos/pfnet/chainer/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/pfnet/chainer/downloads","issues_url":"https://api.github.com/repos/pfnet/chainer/issues{/number}","pulls_url":"https://api.github.com/repos/pfnet/chainer/pulls{/number}","milestones_url":"https://api.github.com/repos/pfnet/chainer/milestones{/number}","notifications_url":"https://api.github.com/repos/pfnet/chainer/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/pfnet/chainer/labels{/name}","releases_url":"https://api.github.com/repos/pfnet/chainer/releases{/id}","created_at":"2015-06-05T05:50:37Z","updated_at":"2015-07-03T01:13:25Z","pushed_at":"2015-07-03T02:02:45Z","git_url":"git://github.com/pfnet/chainer.git","ssh_url":"git@github.com:pfnet/chainer.git","clone_url":"https://github.com/pfnet/chainer.git","svn_url":"https://github.com/pfnet/chainer","homepage":"http://chainer.org","size":8343,"stargazers_count":468,"watchers_count":468,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":50,"mirror_url":null,"open_issues_count":39,"forks":50,"open_issues":39,"watchers":468,"default_branch":"master"}},"base":{"label":"pfnet:master","ref":"master","sha":"e2ee9d6a2f3aa914f6733f46128718311ebbd009","user":{"login":"pfnet","id":9739572,"avatar_url":"https://avatars.githubusercontent.com/u/9739572?v=3","gravatar_id":"","url":"https://api.github.com/users/pfnet","html_url":"https://github.com/pfnet","followers_url":"https://api.github.com/users/pfnet/followers","following_url":"https://api.github.com/users/pfnet/following{/other_user}","gists_url":"https://api.github.com/users/pfnet/gists{/gist_id}","starred_url":"https://api.github.com/users/pfnet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pfnet/subscriptions","organizations_url":"https://api.github.com/users/pfnet/orgs","repos_url":"https://api.github.com/users/pfnet/repos","events_url":"https://api.github.com/users/pfnet/events{/privacy}","received_events_url":"https://api.github.com/users/pfnet/received_events","type":"Organization","site_admin":false},"repo":{"id":36914478,"name":"chainer","full_name":"pfnet/chainer","owner":{"login":"pfnet","id":9739572,"avatar_url":"https://avatars.githubusercontent.com/u/9739572?v=3","gravatar_id":"","url":"https://api.github.com/users/pfnet","html_url":"https://github.com/pfnet","followers_url":"https://api.github.com/users/pfnet/followers","following_url":"https://api.github.com/users/pfnet/following{/other_user}","gists_url":"https://api.github.com/users/pfnet/gists{/gist_id}","starred_url":"https://api.github.com/users/pfnet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pfnet/subscriptions","organizations_url":"https://api.github.com/users/pfnet/orgs","repos_url":"https://api.github.com/users/pfnet/repos","events_url":"https://api.github.com/users/pfnet/events{/privacy}","received_events_url":"https://api.github.com/users/pfnet/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/pfnet/chainer","description":"A flexible framework of neural networks for deep learning","fork":false,"url":"https://api.github.com/repos/pfnet/chainer","forks_url":"https://api.github.com/repos/pfnet/chainer/forks","keys_url":"https://api.github.com/repos/pfnet/chainer/keys{/key_id}","collaborators_url":"https://api.github.com/repos/pfnet/chainer/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/pfnet/chainer/teams","hooks_url":"https://api.github.com/repos/pfnet/chainer/hooks","issue_events_url":"https://api.github.com/repos/pfnet/chainer/issues/events{/number}","events_url":"https://api.github.com/repos/pfnet/chainer/events","assignees_url":"https://api.github.com/repos/pfnet/chainer/assignees{/user}","branches_url":"https://api.github.com/repos/pfnet/chainer/branches{/branch}","tags_url":"https://api.github.com/repos/pfnet/chainer/tags","blobs_url":"https://api.github.com/repos/pfnet/chainer/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/pfnet/chainer/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/pfnet/chainer/git/refs{/sha}","trees_url":"https://api.github.com/repos/pfnet/chainer/git/trees{/sha}","statuses_url":"https://api.github.com/repos/pfnet/chainer/statuses/{sha}","languages_url":"https://api.github.com/repos/pfnet/chainer/languages","stargazers_url":"https://api.github.com/repos/pfnet/chainer/stargazers","contributors_url":"https://api.github.com/repos/pfnet/chainer/contributors","subscribers_url":"https://api.github.com/repos/pfnet/chainer/subscribers","subscription_url":"https://api.github.com/repos/pfnet/chainer/subscription","commits_url":"https://api.github.com/repos/pfnet/chainer/commits{/sha}","git_commits_url":"https://api.github.com/repos/pfnet/chainer/git/commits{/sha}","comments_url":"https://api.github.com/repos/pfnet/chainer/comments{/number}","issue_comment_url":"https://api.github.com/repos/pfnet/chainer/issues/comments{/number}","contents_url":"https://api.github.com/repos/pfnet/chainer/contents/{+path}","compare_url":"https://api.github.com/repos/pfnet/chainer/compare/{base}...{head}","merges_url":"https://api.github.com/repos/pfnet/chainer/merges","archive_url":"https://api.github.com/repos/pfnet/chainer/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/pfnet/chainer/downloads","issues_url":"https://api.github.com/repos/pfnet/chainer/issues{/number}","pulls_url":"https://api.github.com/repos/pfnet/chainer/pulls{/number}","milestones_url":"https://api.github.com/repos/pfnet/chainer/milestones{/number}","notifications_url":"https://api.github.com/repos/pfnet/chainer/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/pfnet/chainer/labels{/name}","releases_url":"https://api.github.com/repos/pfnet/chainer/releases{/id}","created_at":"2015-06-05T05:50:37Z","updated_at":"2015-07-03T01:13:25Z","pushed_at":"2015-07-03T02:02:45Z","git_url":"git://github.com/pfnet/chainer.git","ssh_url":"git@github.com:pfnet/chainer.git","clone_url":"https://github.com/pfnet/chainer.git","svn_url":"https://github.com/pfnet/chainer","homepage":"http://chainer.org","size":8343,"stargazers_count":468,"watchers_count":468,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":50,"mirror_url":null,"open_issues_count":39,"forks":50,"open_issues":39,"watchers":468,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/pfnet/chainer/pulls/102"},"html":{"href":"https://github.com/pfnet/chainer/pull/102"},"issue":{"href":"https://api.github.com/repos/pfnet/chainer/issues/102"},"comments":{"href":"https://api.github.com/repos/pfnet/chainer/issues/102/comments"},"review_comments":{"href":"https://api.github.com/repos/pfnet/chainer/pulls/102/comments"},"review_comment":{"href":"https://api.github.com/repos/pfnet/chainer/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/pfnet/chainer/pulls/102/commits"},"statuses":{"href":"https://api.github.com/repos/pfnet/chainer/statuses/019f2759df3d9423f0d28470cd792bc82aaf902d"}}}}