{"action":"created","comment":{"url":"https://api.github.com/repos/quantumlib/OpenFermion/pulls/comments/199005945","pull_request_review_id":133041123,"id":199005945,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDE5OTAwNTk0NQ==","diff_hunk":"@@ -190,3 +191,56 @@ def test_rank_reduction(self):\n                 decomposed_operator - fermion_hamiltonian)\n             errors += [difference.induced_norm()]\n         self.assertTrue(errors[3] <= errors[2] <= errors[1] <= errors[0])\n+\n+    def test_one_body_square_decomposition(self):\n+\n+        # Initialize a random two-body FermionOperator.\n+        n_qubits = 4\n+        random_operator = get_fermion_operator(\n+            random_interaction_operator(n_qubits))\n+\n+        # Convert to chemist tensor.\n+        constant, one_body_coefficients, chemist_tensor = \\\n+            get_chemist_two_body_coefficients(random_operator)\n+\n+        # Perform decomposition.\n+        eigenvalues, one_body_squares, trunc_error = \\\n+            low_rank_two_body_decomposition(chemist_tensor)\n+\n+        # Build back two-body component.\n+        for l in range(n_qubits ** 2):\n+\n+            # Get the squared one-body operator.\n+            one_body_operator = FermionOperator()\n+            for p, q in itertools.product(range(n_qubits), repeat=2):\n+                term = ((p, 1), (q, 0))\n+                coefficient = one_body_squares[l, p, q]\n+                one_body_operator += FermionOperator(term, coefficient)\n+            one_body_squared = one_body_operator ** 2\n+\n+            # Get the squared one-body operator via one-body decomposition.\n+            density_density_matrix, basis_transformation_matrix = \\\n+                prepare_one_body_squared_evolution(one_body_squares[l])\n+            two_body_operator = FermionOperator()\n+            for p, q in itertools.product(range(n_qubits), repeat=2):\n+                term = ((p, 1), (p, 0), (q, 1), (q, 0))\n+                coefficient = density_density_matrix[p, q]\n+                two_body_operator += FermionOperator(term, coefficient)\n+\n+            # Confirm that the rotations diagonalize the one-body squares.\n+            hopefully_diagonal = basis_transformation_matrix.dot(\n+                numpy.dot(one_body_squares[l],\n+                          numpy.transpose(numpy.conjugate(\n+                              basis_transformation_matrix))))\n+            diagonal = numpy.diag(hopefully_diagonal)\n+            difference = hopefully_diagonal - numpy.diag(diagonal)\n+            self.assertAlmostEqual(0., numpy.amax(numpy.absolute(difference)))\n+            density_density_alternative = numpy.outer(diagonal, diagonal)\n+            difference = density_density_alternative - density_density_matrix\n+            self.assertAlmostEqual(0., numpy.amax(numpy.absolute(difference)))\n+\n+            # Test spectra.\n+            one_body_squared_spectrum = eigenspectrum(one_body_squared)\n+            two_body_spectrum = eigenspectrum(two_body_operator)\n+            difference = two_body_spectrum - one_body_squared_spectrum\n+            self.assertAlmostEqual(0., numpy.amax(numpy.absolute(difference)))","path":"src/openfermion/utils/_low_rank_test.py","position":70,"original_position":70,"commit_id":"57c4a5ba8201fe4b2480541dc9a819cf674dba22","original_commit_id":"57c4a5ba8201fe4b2480541dc9a819cf674dba22","user":{"login":"jarrodmcc","id":7718204,"node_id":"MDQ6VXNlcjc3MTgyMDQ=","avatar_url":"https://avatars2.githubusercontent.com/u/7718204?v=4","gravatar_id":"","url":"https://api.github.com/users/jarrodmcc","html_url":"https://github.com/jarrodmcc","followers_url":"https://api.github.com/users/jarrodmcc/followers","following_url":"https://api.github.com/users/jarrodmcc/following{/other_user}","gists_url":"https://api.github.com/users/jarrodmcc/gists{/gist_id}","starred_url":"https://api.github.com/users/jarrodmcc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jarrodmcc/subscriptions","organizations_url":"https://api.github.com/users/jarrodmcc/orgs","repos_url":"https://api.github.com/users/jarrodmcc/repos","events_url":"https://api.github.com/users/jarrodmcc/events{/privacy}","received_events_url":"https://api.github.com/users/jarrodmcc/received_events","type":"User","site_admin":false},"body":"If we expect the resulting normal ordered operators to be the same also, maybe we can test that as well? Or is that too onerous?","created_at":"2018-06-28T22:27:59Z","updated_at":"2018-06-28T22:29:00Z","html_url":"https://github.com/quantumlib/OpenFermion/pull/378#discussion_r199005945","pull_request_url":"https://api.github.com/repos/quantumlib/OpenFermion/pulls/378","author_association":"COLLABORATOR","_links":{"self":{"href":"https://api.github.com/repos/quantumlib/OpenFermion/pulls/comments/199005945"},"html":{"href":"https://github.com/quantumlib/OpenFermion/pull/378#discussion_r199005945"},"pull_request":{"href":"https://api.github.com/repos/quantumlib/OpenFermion/pulls/378"}}},"pull_request":{"url":"https://api.github.com/repos/quantumlib/OpenFermion/pulls/378","id":197871685,"node_id":"MDExOlB1bGxSZXF1ZXN0MTk3ODcxNjg1","html_url":"https://github.com/quantumlib/OpenFermion/pull/378","diff_url":"https://github.com/quantumlib/OpenFermion/pull/378.diff","patch_url":"https://github.com/quantumlib/OpenFermion/pull/378.patch","issue_url":"https://api.github.com/repos/quantumlib/OpenFermion/issues/378","number":378,"state":"open","locked":false,"title":"Low rank circuits","user":{"login":"babbush","id":14242687,"node_id":"MDQ6VXNlcjE0MjQyNjg3","avatar_url":"https://avatars2.githubusercontent.com/u/14242687?v=4","gravatar_id":"","url":"https://api.github.com/users/babbush","html_url":"https://github.com/babbush","followers_url":"https://api.github.com/users/babbush/followers","following_url":"https://api.github.com/users/babbush/following{/other_user}","gists_url":"https://api.github.com/users/babbush/gists{/gist_id}","starred_url":"https://api.github.com/users/babbush/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/babbush/subscriptions","organizations_url":"https://api.github.com/users/babbush/orgs","repos_url":"https://api.github.com/users/babbush/repos","events_url":"https://api.github.com/users/babbush/events{/privacy}","received_events_url":"https://api.github.com/users/babbush/received_events","type":"User","site_admin":false},"body":"Adding final function that will go in OpenFermion core to help assist with low rank circuit simulation.","created_at":"2018-06-27T22:34:47Z","updated_at":"2018-06-28T22:29:00Z","closed_at":null,"merged_at":null,"merge_commit_sha":"e728a55aae4681078bf4a53d40d56b157c11cf17","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[{"id":923815919,"node_id":"MDU6TGFiZWw5MjM4MTU5MTk=","url":"https://api.github.com/repos/quantumlib/OpenFermion/labels/cla:%20yes","name":"cla: yes","color":"0e8a16","default":false}],"milestone":null,"commits_url":"https://api.github.com/repos/quantumlib/OpenFermion/pulls/378/commits","review_comments_url":"https://api.github.com/repos/quantumlib/OpenFermion/pulls/378/comments","review_comment_url":"https://api.github.com/repos/quantumlib/OpenFermion/pulls/comments{/number}","comments_url":"https://api.github.com/repos/quantumlib/OpenFermion/issues/378/comments","statuses_url":"https://api.github.com/repos/quantumlib/OpenFermion/statuses/57c4a5ba8201fe4b2480541dc9a819cf674dba22","head":{"label":"babbush:low_rank_circuits","ref":"low_rank_circuits","sha":"57c4a5ba8201fe4b2480541dc9a819cf674dba22","user":{"login":"babbush","id":14242687,"node_id":"MDQ6VXNlcjE0MjQyNjg3","avatar_url":"https://avatars2.githubusercontent.com/u/14242687?v=4","gravatar_id":"","url":"https://api.github.com/users/babbush","html_url":"https://github.com/babbush","followers_url":"https://api.github.com/users/babbush/followers","following_url":"https://api.github.com/users/babbush/following{/other_user}","gists_url":"https://api.github.com/users/babbush/gists{/gist_id}","starred_url":"https://api.github.com/users/babbush/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/babbush/subscriptions","organizations_url":"https://api.github.com/users/babbush/orgs","repos_url":"https://api.github.com/users/babbush/repos","events_url":"https://api.github.com/users/babbush/events{/privacy}","received_events_url":"https://api.github.com/users/babbush/received_events","type":"User","site_admin":false},"repo":{"id":105316591,"node_id":"MDEwOlJlcG9zaXRvcnkxMDUzMTY1OTE=","name":"OpenFermion","full_name":"babbush/OpenFermion","owner":{"login":"babbush","id":14242687,"node_id":"MDQ6VXNlcjE0MjQyNjg3","avatar_url":"https://avatars2.githubusercontent.com/u/14242687?v=4","gravatar_id":"","url":"https://api.github.com/users/babbush","html_url":"https://github.com/babbush","followers_url":"https://api.github.com/users/babbush/followers","following_url":"https://api.github.com/users/babbush/following{/other_user}","gists_url":"https://api.github.com/users/babbush/gists{/gist_id}","starred_url":"https://api.github.com/users/babbush/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/babbush/subscriptions","organizations_url":"https://api.github.com/users/babbush/orgs","repos_url":"https://api.github.com/users/babbush/repos","events_url":"https://api.github.com/users/babbush/events{/privacy}","received_events_url":"https://api.github.com/users/babbush/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/babbush/OpenFermion","description":"OpenFermion: the electronic structure package for quantum computers.","fork":true,"url":"https://api.github.com/repos/babbush/OpenFermion","forks_url":"https://api.github.com/repos/babbush/OpenFermion/forks","keys_url":"https://api.github.com/repos/babbush/OpenFermion/keys{/key_id}","collaborators_url":"https://api.github.com/repos/babbush/OpenFermion/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/babbush/OpenFermion/teams","hooks_url":"https://api.github.com/repos/babbush/OpenFermion/hooks","issue_events_url":"https://api.github.com/repos/babbush/OpenFermion/issues/events{/number}","events_url":"https://api.github.com/repos/babbush/OpenFermion/events","assignees_url":"https://api.github.com/repos/babbush/OpenFermion/assignees{/user}","branches_url":"https://api.github.com/repos/babbush/OpenFermion/branches{/branch}","tags_url":"https://api.github.com/repos/babbush/OpenFermion/tags","blobs_url":"https://api.github.com/repos/babbush/OpenFermion/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/babbush/OpenFermion/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/babbush/OpenFermion/git/refs{/sha}","trees_url":"https://api.github.com/repos/babbush/OpenFermion/git/trees{/sha}","statuses_url":"https://api.github.com/repos/babbush/OpenFermion/statuses/{sha}","languages_url":"https://api.github.com/repos/babbush/OpenFermion/languages","stargazers_url":"https://api.github.com/repos/babbush/OpenFermion/stargazers","contributors_url":"https://api.github.com/repos/babbush/OpenFermion/contributors","subscribers_url":"https://api.github.com/repos/babbush/OpenFermion/subscribers","subscription_url":"https://api.github.com/repos/babbush/OpenFermion/subscription","commits_url":"https://api.github.com/repos/babbush/OpenFermion/commits{/sha}","git_commits_url":"https://api.github.com/repos/babbush/OpenFermion/git/commits{/sha}","comments_url":"https://api.github.com/repos/babbush/OpenFermion/comments{/number}","issue_comment_url":"https://api.github.com/repos/babbush/OpenFermion/issues/comments{/number}","contents_url":"https://api.github.com/repos/babbush/OpenFermion/contents/{+path}","compare_url":"https://api.github.com/repos/babbush/OpenFermion/compare/{base}...{head}","merges_url":"https://api.github.com/repos/babbush/OpenFermion/merges","archive_url":"https://api.github.com/repos/babbush/OpenFermion/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/babbush/OpenFermion/downloads","issues_url":"https://api.github.com/repos/babbush/OpenFermion/issues{/number}","pulls_url":"https://api.github.com/repos/babbush/OpenFermion/pulls{/number}","milestones_url":"https://api.github.com/repos/babbush/OpenFermion/milestones{/number}","notifications_url":"https://api.github.com/repos/babbush/OpenFermion/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/babbush/OpenFermion/labels{/name}","releases_url":"https://api.github.com/repos/babbush/OpenFermion/releases{/id}","deployments_url":"https://api.github.com/repos/babbush/OpenFermion/deployments","created_at":"2017-09-29T20:58:43Z","updated_at":"2018-06-27T21:29:43Z","pushed_at":"2018-06-28T22:07:43Z","git_url":"git://github.com/babbush/OpenFermion.git","ssh_url":"git@github.com:babbush/OpenFermion.git","clone_url":"https://github.com/babbush/OpenFermion.git","svn_url":"https://github.com/babbush/OpenFermion","homepage":"","size":3630,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0","node_id":"MDc6TGljZW5zZTI="},"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"quantumlib:master","ref":"master","sha":"69f773da409b4eba58814013a180ec5580dd25e4","user":{"login":"quantumlib","id":31279789,"node_id":"MDEyOk9yZ2FuaXphdGlvbjMxMjc5Nzg5","avatar_url":"https://avatars1.githubusercontent.com/u/31279789?v=4","gravatar_id":"","url":"https://api.github.com/users/quantumlib","html_url":"https://github.com/quantumlib","followers_url":"https://api.github.com/users/quantumlib/followers","following_url":"https://api.github.com/users/quantumlib/following{/other_user}","gists_url":"https://api.github.com/users/quantumlib/gists{/gist_id}","starred_url":"https://api.github.com/users/quantumlib/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/quantumlib/subscriptions","organizations_url":"https://api.github.com/users/quantumlib/orgs","repos_url":"https://api.github.com/users/quantumlib/repos","events_url":"https://api.github.com/users/quantumlib/events{/privacy}","received_events_url":"https://api.github.com/users/quantumlib/received_events","type":"Organization","site_admin":false},"repo":{"id":104403768,"node_id":"MDEwOlJlcG9zaXRvcnkxMDQ0MDM3Njg=","name":"OpenFermion","full_name":"quantumlib/OpenFermion","owner":{"login":"quantumlib","id":31279789,"node_id":"MDEyOk9yZ2FuaXphdGlvbjMxMjc5Nzg5","avatar_url":"https://avatars1.githubusercontent.com/u/31279789?v=4","gravatar_id":"","url":"https://api.github.com/users/quantumlib","html_url":"https://github.com/quantumlib","followers_url":"https://api.github.com/users/quantumlib/followers","following_url":"https://api.github.com/users/quantumlib/following{/other_user}","gists_url":"https://api.github.com/users/quantumlib/gists{/gist_id}","starred_url":"https://api.github.com/users/quantumlib/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/quantumlib/subscriptions","organizations_url":"https://api.github.com/users/quantumlib/orgs","repos_url":"https://api.github.com/users/quantumlib/repos","events_url":"https://api.github.com/users/quantumlib/events{/privacy}","received_events_url":"https://api.github.com/users/quantumlib/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/quantumlib/OpenFermion","description":"OpenFermion: The Electronic Structure Package For Quantum Computers.","fork":false,"url":"https://api.github.com/repos/quantumlib/OpenFermion","forks_url":"https://api.github.com/repos/quantumlib/OpenFermion/forks","keys_url":"https://api.github.com/repos/quantumlib/OpenFermion/keys{/key_id}","collaborators_url":"https://api.github.com/repos/quantumlib/OpenFermion/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/quantumlib/OpenFermion/teams","hooks_url":"https://api.github.com/repos/quantumlib/OpenFermion/hooks","issue_events_url":"https://api.github.com/repos/quantumlib/OpenFermion/issues/events{/number}","events_url":"https://api.github.com/repos/quantumlib/OpenFermion/events","assignees_url":"https://api.github.com/repos/quantumlib/OpenFermion/assignees{/user}","branches_url":"https://api.github.com/repos/quantumlib/OpenFermion/branches{/branch}","tags_url":"https://api.github.com/repos/quantumlib/OpenFermion/tags","blobs_url":"https://api.github.com/repos/quantumlib/OpenFermion/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/quantumlib/OpenFermion/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/quantumlib/OpenFermion/git/refs{/sha}","trees_url":"https://api.github.com/repos/quantumlib/OpenFermion/git/trees{/sha}","statuses_url":"https://api.github.com/repos/quantumlib/OpenFermion/statuses/{sha}","languages_url":"https://api.github.com/repos/quantumlib/OpenFermion/languages","stargazers_url":"https://api.github.com/repos/quantumlib/OpenFermion/stargazers","contributors_url":"https://api.github.com/repos/quantumlib/OpenFermion/contributors","subscribers_url":"https://api.github.com/repos/quantumlib/OpenFermion/subscribers","subscription_url":"https://api.github.com/repos/quantumlib/OpenFermion/subscription","commits_url":"https://api.github.com/repos/quantumlib/OpenFermion/commits{/sha}","git_commits_url":"https://api.github.com/repos/quantumlib/OpenFermion/git/commits{/sha}","comments_url":"https://api.github.com/repos/quantumlib/OpenFermion/comments{/number}","issue_comment_url":"https://api.github.com/repos/quantumlib/OpenFermion/issues/comments{/number}","contents_url":"https://api.github.com/repos/quantumlib/OpenFermion/contents/{+path}","compare_url":"https://api.github.com/repos/quantumlib/OpenFermion/compare/{base}...{head}","merges_url":"https://api.github.com/repos/quantumlib/OpenFermion/merges","archive_url":"https://api.github.com/repos/quantumlib/OpenFermion/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/quantumlib/OpenFermion/downloads","issues_url":"https://api.github.com/repos/quantumlib/OpenFermion/issues{/number}","pulls_url":"https://api.github.com/repos/quantumlib/OpenFermion/pulls{/number}","milestones_url":"https://api.github.com/repos/quantumlib/OpenFermion/milestones{/number}","notifications_url":"https://api.github.com/repos/quantumlib/OpenFermion/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/quantumlib/OpenFermion/labels{/name}","releases_url":"https://api.github.com/repos/quantumlib/OpenFermion/releases{/id}","deployments_url":"https://api.github.com/repos/quantumlib/OpenFermion/deployments","created_at":"2017-09-21T22:10:28Z","updated_at":"2018-06-27T06:30:57Z","pushed_at":"2018-06-28T22:07:45Z","git_url":"git://github.com/quantumlib/OpenFermion.git","ssh_url":"git@github.com:quantumlib/OpenFermion.git","clone_url":"https://github.com/quantumlib/OpenFermion.git","svn_url":"https://github.com/quantumlib/OpenFermion","homepage":"","size":3516,"stargazers_count":505,"watchers_count":505,"language":"Python","has_issues":true,"has_projects":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":128,"mirror_url":null,"archived":false,"open_issues_count":22,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0","node_id":"MDc6TGljZW5zZTI="},"forks":128,"open_issues":22,"watchers":505,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/quantumlib/OpenFermion/pulls/378"},"html":{"href":"https://github.com/quantumlib/OpenFermion/pull/378"},"issue":{"href":"https://api.github.com/repos/quantumlib/OpenFermion/issues/378"},"comments":{"href":"https://api.github.com/repos/quantumlib/OpenFermion/issues/378/comments"},"review_comments":{"href":"https://api.github.com/repos/quantumlib/OpenFermion/pulls/378/comments"},"review_comment":{"href":"https://api.github.com/repos/quantumlib/OpenFermion/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/quantumlib/OpenFermion/pulls/378/commits"},"statuses":{"href":"https://api.github.com/repos/quantumlib/OpenFermion/statuses/57c4a5ba8201fe4b2480541dc9a819cf674dba22"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"jarrodmcc"}}