Skip to content

Commit

Permalink
updating notebook to use QVMConnection
Browse files Browse the repository at this point in the history
  • Loading branch information
ampolloreno committed Nov 23, 2017
1 parent e9a3c05 commit ae00290
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 27 deletions.
35 changes: 10 additions & 25 deletions examples/GroversAlgorithm.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,13 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"from pyquil.api import SyncConnection\n",
"from pyquil.api import QVMConnection\n",
"from itertools import product\n",
"from mock import patch, Mock\n",
"from pyquil.job_results import JobResult\n",
"\n",
"from grove.amplification.grover import Grover"
]
Expand All @@ -31,7 +30,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -59,7 +58,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -81,15 +80,12 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"with patch(\"pyquil.api.JobConnection\") as cxn:\n",
" jobresult = Mock(JobResult)\n",
" jobresult.is_done.return_value = True\n",
" jobresult.decode.return_value = [\"\".join([bit for bit in target_bitstring])]\n",
" cxn.run_and_measure.return_value = jobresult"
"with patch(\"pyquil.api.QVMConnection\") as cxn:\n",
" cxn.run_and_measure.return_value = [[int(bit) for bit in target_bitstring]]"
]
},
{
Expand All @@ -102,24 +98,13 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"grover = Grover()\n",
"found_bistring = grover.find_bitstring(cxn, bitstring_map)\n",
"assert found_bistring == target_bitstring, \"Found bitstring is not the expected bitstring\""
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"scrolled": false
},
"outputs": [],
"source": [
"print(grover.grover_circuit)"
"found_bitstring = grover.find_bitstring(cxn, bitstring_map)\n",
"assert \"\".join(found_bitstring) == target_bitstring, \"Found bitstring is not the expected bitstring\""
]
},
{
Expand Down
4 changes: 2 additions & 2 deletions grove/amplification/grover.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ def find_bitstring(self, cxn, bitstring_map):
"""

self._init_attr(bitstring_map)
sampled_bitstring = cxn.run_and_measure(self.grover_circuit, self.qubits)
return ''.join([str(b) for b in sampled_bitstring])
sampled_bitstring = cxn.run_and_measure(self.grover_circuit, self.qubits)[0]
return "".join([str(bit) for bit in sampled_bitstring])

@staticmethod
def oracle_grover(oracle, qubits, num_iter=None):
Expand Down

0 comments on commit ae00290

Please sign in to comment.