{"action":"created","comment":{"url":"https://api.github.com/repos/rigetticomputing/grove/pulls/comments/148183485","pull_request_review_id":73385242,"id":148183485,"diff_hunk":"@@ -0,0 +1,142 @@\n+\n+\"\"\"\n+Finding the minimum energy for an Ising problem by QAOA.\n+\"\"\"\n+import pyquil.api as api\n+from grove.pyqaoa.qaoa import QAOA\n+from pyquil.paulis import PauliSum, PauliTerm\n+from scipy.optimize import minimize\n+import numpy as np\n+\n+CXN = api.SyncConnection()\n+\n+\n+def energy_value(h, J, sol):\n+    \"\"\"\n+    Obtain energy of an Ising solution for a given Ising problem (h,J).\n+\n+    :param h: External magnectic term of the Ising problem. List.\n+    :param J: Interaction term of the Ising problem. Dictionary.\n+    :param sol: Ising solution. List.\n+\n+    \"\"\"\n+    ener_ising = 0\n+    for elm in J.keys():\n+        if elm[0] == elm[1]:\n+            ener_ising += J[elm] * int(sol[elm[0]])\n+        else:\n+            ener_ising += J[elm] * int(sol[elm[0]]) * int(sol[elm[1]])\n+    for i in range(len(h)):\n+        ener_ising += h[i] * int(sol[i])\n+    return ener_ising\n+\n+\n+def print_fun(x):\n+    print(x)\n+\n+\n+def ising_trans(x):\n+    # Transformation to Ising notation\n+    if x == 1:\n+        return -1\n+    else:\n+        return 1\n+\n+\n+def ising_qaoa(h, J, steps=1, rand_seed=None, connection=None, samples=None,\n+               initial_beta=None, initial_gamma=None, minimizer_kwargs=None,\n+               vqe_option=None):\n+    \"\"\"\n+    Ising set up method\n+\n+    :param h: External magnectic term of the Ising problem. List.\n+    :param J: Interaction term of the Ising problem. Dictionary.\n+    :param steps: (Optional. Default=1) Trotterization order for the\n+                  QAOA algorithm.\n+    :param rand_seed: (Optional. Default=None) random seed when beta and\n+                      gamma angles are not provided.\n+    :param connection: (Optional) connection to the QVM. Default is None.\n+    :param samples: (Optional. Default=None) VQE option. Number of samples\n+                    (circuit preparation and measurement) to use in operator\n+                    averaging.\n+    :param initial_beta: (Optional. Default=None) Initial guess for beta\n+                         parameters.\n+    :param initial_gamma: (Optional. Default=None) Initial guess for gamma\n+                          parameters.\n+    :param minimizer_kwargs: (Optional. Default=None). Minimizer optional\n+                             arguments.  If None set to\n+                             {'method': 'Nelder-Mead',\n+                             'options': {'ftol': 1.0e-2, 'xtol': 1.0e-2,\n+                                        'disp': False}\n+    :param vqe_option: (Optional. Default=None). VQE optional\n+                             arguments.  If None set to\n+                       vqe_option = {'disp': print_fun, 'return_all': True,\n+                       'samples': samples}\n+\n+    \"\"\"\n+\n+    cost_operators = []\n+    driver_operators = []\n+    for i, j in J.keys():\n+        cost_operators.append(PauliSum([PauliTerm(\"Z\", i, J[(i, j)]) * PauliTerm(\"Z\", j)]))\n+\n+    for i in range(len(h)):\n+        cost_operators.append(PauliSum([PauliTerm(\"Z\", i, h[i])]))\n+\n+    n_nodes = sorted([item for sublist in J.keys() for item in sublist], reverse=True)[0]\n+\n+    for i in range(n_nodes + 1):\n+        driver_operators.append(PauliSum([PauliTerm(\"X\", i, -1.0)]))\n+\n+    if connection is None:\n+        connection = CXN\n+\n+    if minimizer_kwargs is None:\n+        minimizer_kwargs = {'method': 'Nelder-Mead',\n+                            'options': {'ftol': 1.0e-2, 'xtol': 1.0e-2,\n+                                        'disp': False}}\n+    if vqe_option is None:\n+        vqe_option = {'disp': print_fun, 'return_all': True,\n+                      'samples': samples}\n+\n+    qaoa_inst = QAOA(connection, n_nodes + 1, steps=steps, cost_ham=cost_operators,\n+                     ref_hamiltonian=driver_operators, store_basis=True,\n+                     rand_seed=rand_seed,\n+                     init_betas=initial_beta,\n+                     init_gammas=initial_gamma,\n+                     minimizer=minimize,\n+                     minimizer_kwargs=minimizer_kwargs,\n+                     vqe_options=vqe_option)\n+\n+    return qaoa_inst\n+\n+\n+def ising(h, J, num_steps=0, verbose=True):\n+    \"\"\"\n+    Ising method initialization\n+\n+    :param h: External magnectic term of the Ising problem. List.\n+    :param J: Interaction term of the Ising problem. Dictionary.\n+    :param num_steps: (Optional.Default=2 * len(h)) Trotterization order for the\n+                  QAOA algorithm.\n+    :param verbose: (Optional.Default=True) Verbosity of the code.","path":"grove/ising/ising_qaoa.py","position":122,"original_position":122,"commit_id":"339e595090715900a621df34b1b44b0d2492898b","original_commit_id":"339e595090715900a621df34b1b44b0d2492898b","user":{"login":"jotterbach","id":5595043,"avatar_url":"https://avatars0.githubusercontent.com/u/5595043?v=4","gravatar_id":"","url":"https://api.github.com/users/jotterbach","html_url":"https://github.com/jotterbach","followers_url":"https://api.github.com/users/jotterbach/followers","following_url":"https://api.github.com/users/jotterbach/following{/other_user}","gists_url":"https://api.github.com/users/jotterbach/gists{/gist_id}","starred_url":"https://api.github.com/users/jotterbach/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jotterbach/subscriptions","organizations_url":"https://api.github.com/users/jotterbach/orgs","repos_url":"https://api.github.com/users/jotterbach/repos","events_url":"https://api.github.com/users/jotterbach/events{/privacy}","received_events_url":"https://api.github.com/users/jotterbach/received_events","type":"User","site_admin":false},"body":"can you add the `:return:` and `:rtype:` annotations here?","created_at":"2017-11-01T05:07:21Z","updated_at":"2017-11-01T05:21:18Z","html_url":"https://github.com/rigetticomputing/grove/pull/90#discussion_r148183485","pull_request_url":"https://api.github.com/repos/rigetticomputing/grove/pulls/90","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/rigetticomputing/grove/pulls/comments/148183485"},"html":{"href":"https://github.com/rigetticomputing/grove/pull/90#discussion_r148183485"},"pull_request":{"href":"https://api.github.com/repos/rigetticomputing/grove/pulls/90"}}},"pull_request":{"url":"https://api.github.com/repos/rigetticomputing/grove/pulls/90","id":146341004,"html_url":"https://github.com/rigetticomputing/grove/pull/90","diff_url":"https://github.com/rigetticomputing/grove/pull/90.diff","patch_url":"https://github.com/rigetticomputing/grove/pull/90.patch","issue_url":"https://api.github.com/repos/rigetticomputing/grove/issues/90","number":90,"state":"open","locked":false,"title":"QAOA for Ising models with external fields","user":{"login":"AsierO","id":12262114,"avatar_url":"https://avatars1.githubusercontent.com/u/12262114?v=4","gravatar_id":"","url":"https://api.github.com/users/AsierO","html_url":"https://github.com/AsierO","followers_url":"https://api.github.com/users/AsierO/followers","following_url":"https://api.github.com/users/AsierO/following{/other_user}","gists_url":"https://api.github.com/users/AsierO/gists{/gist_id}","starred_url":"https://api.github.com/users/AsierO/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AsierO/subscriptions","organizations_url":"https://api.github.com/users/AsierO/orgs","repos_url":"https://api.github.com/users/AsierO/repos","events_url":"https://api.github.com/users/AsierO/events{/privacy}","received_events_url":"https://api.github.com/users/AsierO/received_events","type":"User","site_admin":false},"body":"Code that finds the ground state of an Ising model with external fields using QAOA. It includes a modified version of the class QAOA called QAOA_ising modified for this problem. Tests of the code are not included.","created_at":"2017-10-12T23:45:46Z","updated_at":"2017-11-01T05:21:18Z","closed_at":null,"merged_at":null,"merge_commit_sha":"8c54c28e073185404b72b62c4aab1eba27dbbdd5","assignee":null,"assignees":[],"requested_reviewers":[],"milestone":null,"commits_url":"https://api.github.com/repos/rigetticomputing/grove/pulls/90/commits","review_comments_url":"https://api.github.com/repos/rigetticomputing/grove/pulls/90/comments","review_comment_url":"https://api.github.com/repos/rigetticomputing/grove/pulls/comments{/number}","comments_url":"https://api.github.com/repos/rigetticomputing/grove/issues/90/comments","statuses_url":"https://api.github.com/repos/rigetticomputing/grove/statuses/339e595090715900a621df34b1b44b0d2492898b","head":{"label":"AsierO:master","ref":"master","sha":"339e595090715900a621df34b1b44b0d2492898b","user":{"login":"AsierO","id":12262114,"avatar_url":"https://avatars1.githubusercontent.com/u/12262114?v=4","gravatar_id":"","url":"https://api.github.com/users/AsierO","html_url":"https://github.com/AsierO","followers_url":"https://api.github.com/users/AsierO/followers","following_url":"https://api.github.com/users/AsierO/following{/other_user}","gists_url":"https://api.github.com/users/AsierO/gists{/gist_id}","starred_url":"https://api.github.com/users/AsierO/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AsierO/subscriptions","organizations_url":"https://api.github.com/users/AsierO/orgs","repos_url":"https://api.github.com/users/AsierO/repos","events_url":"https://api.github.com/users/AsierO/events{/privacy}","received_events_url":"https://api.github.com/users/AsierO/received_events","type":"User","site_admin":false},"repo":{"id":106755592,"name":"grove","full_name":"AsierO/grove","owner":{"login":"AsierO","id":12262114,"avatar_url":"https://avatars1.githubusercontent.com/u/12262114?v=4","gravatar_id":"","url":"https://api.github.com/users/AsierO","html_url":"https://github.com/AsierO","followers_url":"https://api.github.com/users/AsierO/followers","following_url":"https://api.github.com/users/AsierO/following{/other_user}","gists_url":"https://api.github.com/users/AsierO/gists{/gist_id}","starred_url":"https://api.github.com/users/AsierO/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AsierO/subscriptions","organizations_url":"https://api.github.com/users/AsierO/orgs","repos_url":"https://api.github.com/users/AsierO/repos","events_url":"https://api.github.com/users/AsierO/events{/privacy}","received_events_url":"https://api.github.com/users/AsierO/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/AsierO/grove","description":"Quantum algorithms built using pyQuil","fork":true,"url":"https://api.github.com/repos/AsierO/grove","forks_url":"https://api.github.com/repos/AsierO/grove/forks","keys_url":"https://api.github.com/repos/AsierO/grove/keys{/key_id}","collaborators_url":"https://api.github.com/repos/AsierO/grove/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/AsierO/grove/teams","hooks_url":"https://api.github.com/repos/AsierO/grove/hooks","issue_events_url":"https://api.github.com/repos/AsierO/grove/issues/events{/number}","events_url":"https://api.github.com/repos/AsierO/grove/events","assignees_url":"https://api.github.com/repos/AsierO/grove/assignees{/user}","branches_url":"https://api.github.com/repos/AsierO/grove/branches{/branch}","tags_url":"https://api.github.com/repos/AsierO/grove/tags","blobs_url":"https://api.github.com/repos/AsierO/grove/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/AsierO/grove/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/AsierO/grove/git/refs{/sha}","trees_url":"https://api.github.com/repos/AsierO/grove/git/trees{/sha}","statuses_url":"https://api.github.com/repos/AsierO/grove/statuses/{sha}","languages_url":"https://api.github.com/repos/AsierO/grove/languages","stargazers_url":"https://api.github.com/repos/AsierO/grove/stargazers","contributors_url":"https://api.github.com/repos/AsierO/grove/contributors","subscribers_url":"https://api.github.com/repos/AsierO/grove/subscribers","subscription_url":"https://api.github.com/repos/AsierO/grove/subscription","commits_url":"https://api.github.com/repos/AsierO/grove/commits{/sha}","git_commits_url":"https://api.github.com/repos/AsierO/grove/git/commits{/sha}","comments_url":"https://api.github.com/repos/AsierO/grove/comments{/number}","issue_comment_url":"https://api.github.com/repos/AsierO/grove/issues/comments{/number}","contents_url":"https://api.github.com/repos/AsierO/grove/contents/{+path}","compare_url":"https://api.github.com/repos/AsierO/grove/compare/{base}...{head}","merges_url":"https://api.github.com/repos/AsierO/grove/merges","archive_url":"https://api.github.com/repos/AsierO/grove/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/AsierO/grove/downloads","issues_url":"https://api.github.com/repos/AsierO/grove/issues{/number}","pulls_url":"https://api.github.com/repos/AsierO/grove/pulls{/number}","milestones_url":"https://api.github.com/repos/AsierO/grove/milestones{/number}","notifications_url":"https://api.github.com/repos/AsierO/grove/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/AsierO/grove/labels{/name}","releases_url":"https://api.github.com/repos/AsierO/grove/releases{/id}","deployments_url":"https://api.github.com/repos/AsierO/grove/deployments","created_at":"2017-10-12T23:30:26Z","updated_at":"2017-10-12T23:30:28Z","pushed_at":"2017-10-31T13:16:56Z","git_url":"git://github.com/AsierO/grove.git","ssh_url":"git@github.com:AsierO/grove.git","clone_url":"https://github.com/AsierO/grove.git","svn_url":"https://github.com/AsierO/grove","homepage":"http://forest.rigetti.com","size":1116,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"rigetticomputing:master","ref":"master","sha":"7cba6261d1dc1ff773cbb15a50b3c471a80a848f","user":{"login":"rigetticomputing","id":16469771,"avatar_url":"https://avatars1.githubusercontent.com/u/16469771?v=4","gravatar_id":"","url":"https://api.github.com/users/rigetticomputing","html_url":"https://github.com/rigetticomputing","followers_url":"https://api.github.com/users/rigetticomputing/followers","following_url":"https://api.github.com/users/rigetticomputing/following{/other_user}","gists_url":"https://api.github.com/users/rigetticomputing/gists{/gist_id}","starred_url":"https://api.github.com/users/rigetticomputing/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rigetticomputing/subscriptions","organizations_url":"https://api.github.com/users/rigetticomputing/orgs","repos_url":"https://api.github.com/users/rigetticomputing/repos","events_url":"https://api.github.com/users/rigetticomputing/events{/privacy}","received_events_url":"https://api.github.com/users/rigetticomputing/received_events","type":"Organization","site_admin":false},"repo":{"id":77098216,"name":"grove","full_name":"rigetticomputing/grove","owner":{"login":"rigetticomputing","id":16469771,"avatar_url":"https://avatars1.githubusercontent.com/u/16469771?v=4","gravatar_id":"","url":"https://api.github.com/users/rigetticomputing","html_url":"https://github.com/rigetticomputing","followers_url":"https://api.github.com/users/rigetticomputing/followers","following_url":"https://api.github.com/users/rigetticomputing/following{/other_user}","gists_url":"https://api.github.com/users/rigetticomputing/gists{/gist_id}","starred_url":"https://api.github.com/users/rigetticomputing/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rigetticomputing/subscriptions","organizations_url":"https://api.github.com/users/rigetticomputing/orgs","repos_url":"https://api.github.com/users/rigetticomputing/repos","events_url":"https://api.github.com/users/rigetticomputing/events{/privacy}","received_events_url":"https://api.github.com/users/rigetticomputing/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/rigetticomputing/grove","description":"Quantum algorithms built using pyQuil","fork":false,"url":"https://api.github.com/repos/rigetticomputing/grove","forks_url":"https://api.github.com/repos/rigetticomputing/grove/forks","keys_url":"https://api.github.com/repos/rigetticomputing/grove/keys{/key_id}","collaborators_url":"https://api.github.com/repos/rigetticomputing/grove/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/rigetticomputing/grove/teams","hooks_url":"https://api.github.com/repos/rigetticomputing/grove/hooks","issue_events_url":"https://api.github.com/repos/rigetticomputing/grove/issues/events{/number}","events_url":"https://api.github.com/repos/rigetticomputing/grove/events","assignees_url":"https://api.github.com/repos/rigetticomputing/grove/assignees{/user}","branches_url":"https://api.github.com/repos/rigetticomputing/grove/branches{/branch}","tags_url":"https://api.github.com/repos/rigetticomputing/grove/tags","blobs_url":"https://api.github.com/repos/rigetticomputing/grove/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/rigetticomputing/grove/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/rigetticomputing/grove/git/refs{/sha}","trees_url":"https://api.github.com/repos/rigetticomputing/grove/git/trees{/sha}","statuses_url":"https://api.github.com/repos/rigetticomputing/grove/statuses/{sha}","languages_url":"https://api.github.com/repos/rigetticomputing/grove/languages","stargazers_url":"https://api.github.com/repos/rigetticomputing/grove/stargazers","contributors_url":"https://api.github.com/repos/rigetticomputing/grove/contributors","subscribers_url":"https://api.github.com/repos/rigetticomputing/grove/subscribers","subscription_url":"https://api.github.com/repos/rigetticomputing/grove/subscription","commits_url":"https://api.github.com/repos/rigetticomputing/grove/commits{/sha}","git_commits_url":"https://api.github.com/repos/rigetticomputing/grove/git/commits{/sha}","comments_url":"https://api.github.com/repos/rigetticomputing/grove/comments{/number}","issue_comment_url":"https://api.github.com/repos/rigetticomputing/grove/issues/comments{/number}","contents_url":"https://api.github.com/repos/rigetticomputing/grove/contents/{+path}","compare_url":"https://api.github.com/repos/rigetticomputing/grove/compare/{base}...{head}","merges_url":"https://api.github.com/repos/rigetticomputing/grove/merges","archive_url":"https://api.github.com/repos/rigetticomputing/grove/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/rigetticomputing/grove/downloads","issues_url":"https://api.github.com/repos/rigetticomputing/grove/issues{/number}","pulls_url":"https://api.github.com/repos/rigetticomputing/grove/pulls{/number}","milestones_url":"https://api.github.com/repos/rigetticomputing/grove/milestones{/number}","notifications_url":"https://api.github.com/repos/rigetticomputing/grove/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/rigetticomputing/grove/labels{/name}","releases_url":"https://api.github.com/repos/rigetticomputing/grove/releases{/id}","deployments_url":"https://api.github.com/repos/rigetticomputing/grove/deployments","created_at":"2016-12-22T01:08:42Z","updated_at":"2017-10-29T02:28:54Z","pushed_at":"2017-10-31T13:16:57Z","git_url":"git://github.com/rigetticomputing/grove.git","ssh_url":"git@github.com:rigetticomputing/grove.git","clone_url":"https://github.com/rigetticomputing/grove.git","svn_url":"https://github.com/rigetticomputing/grove","homepage":"http://forest.rigetti.com","size":1147,"stargazers_count":100,"watchers_count":100,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":36,"mirror_url":null,"archived":false,"open_issues_count":14,"forks":36,"open_issues":14,"watchers":100,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/rigetticomputing/grove/pulls/90"},"html":{"href":"https://github.com/rigetticomputing/grove/pull/90"},"issue":{"href":"https://api.github.com/repos/rigetticomputing/grove/issues/90"},"comments":{"href":"https://api.github.com/repos/rigetticomputing/grove/issues/90/comments"},"review_comments":{"href":"https://api.github.com/repos/rigetticomputing/grove/pulls/90/comments"},"review_comment":{"href":"https://api.github.com/repos/rigetticomputing/grove/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/rigetticomputing/grove/pulls/90/commits"},"statuses":{"href":"https://api.github.com/repos/rigetticomputing/grove/statuses/339e595090715900a621df34b1b44b0d2492898b"}},"author_association":"NONE"}}
{"actor":{"display_login":"jotterbach"}}