Skip to content

Commit a228041

Browse files
authored
Fix grover_oracle() (#3316)
This PR is just a small change in one of the cells of the [Grover's tutorial notebook](https://learning.quantum.ibm.com/tutorial/grovers-algorithm) to consider the edge case where one of the marked states is all 1s. Before this PR, doing something like this would fail: ```python grover_oracle("111") ``` After this PR, it works as expected and the circuit contains no X gates in that edge case. I have limited the change to that cell in the notebook, and I have not rerun the whole notebook to avoid modifying cells metadata and other irrelevant things. Fixes: #3315
1 parent 6f38e3e commit a228041

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

docs/tutorials/grovers-algorithm.ipynb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,11 @@
9393
" ]\n",
9494
" # Add a multi-controlled Z-gate with pre- and post-applied X-gates (open-controls)\n",
9595
" # where the target bit-string has a '0' entry\n",
96-
" qc.x(zero_inds)\n",
96+
" if zero_inds:\n",
97+
" qc.x(zero_inds)\n",
9798
" qc.compose(MCMTGate(ZGate(), num_qubits - 1, 1), inplace=True)\n",
98-
" qc.x(zero_inds)\n",
99+
" if zero_inds:\n",
100+
" qc.x(zero_inds)\n",
99101
" return qc"
100102
]
101103
},

0 commit comments

Comments
 (0)