You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+24-6Lines changed: 24 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -326,7 +326,7 @@ q_1: ──■─────
326
326
│
327
327
q_2: ──■─────
328
328
│
329
-
q_3: ──■─────
329
+
q_3: ──Z─────
330
330
```
331
331
332
332
Similarly, to find the state `1011`, we can insert X-Gate (not gates) into our circuit. Since `HXH=Z` and `HZH=X`, we can take advantage of the quantum rules to create a multi-controlled phase circuit from a series of X-gates.
@@ -355,7 +355,7 @@ q_2: ┤ X ├─■─┤ X ├
355
355
└───┘ │ └───┘
356
356
q_3: ──────■──────
357
357
│
358
-
q_4: ──────■──────
358
+
q_4: ──────Z──────
359
359
```
360
360
361
361
Notice how we've applied an X-Gate around the Z-Gate control for qubit 2 (*note, we count qubits from right-to-left using Qiskit standard format*).
@@ -387,15 +387,33 @@ The example for [odd numbers](odd.py) demonstrates a simple example of creating
387
387
388
388
We can see that the odd numbers all contain a `1` for the right-most digit (in binary). Therefore, we can create an oracle for Grover's algorithm to find all measurements of qubits that result in a `1` for the right-most digit by simply applying a controlled Z-Gate from the right-most qubit to all other qubits.
389
389
390
-
The oracle to find odd numbers is shown below.
390
+
The oracle to find odd numbers can be created in Qiskit with the following code.
391
391
392
+
```python
393
+
qc = QuantumCircuit(4)
394
+
qc.append(ZGate().control(1), [0,1])
395
+
qc.append(ZGate().control(1), [0,2])
396
+
qc.append(ZGate().control(1), [0,3])
397
+
```
398
+
399
+
Alternatively, we can use the following shortcut syntax.
400
+
401
+
```python
402
+
n =4
403
+
qc.append(ZGate().control(1), [0,range(1,n+1)])
404
+
```
405
+
406
+
This results in the following oracle.
407
+
408
+
```
392
409
q_0: ─■──■──■─
393
410
│ │ │
394
-
q_1: ─■──┼──┼─
411
+
q_1: ─Z──┼──┼─
395
412
│ │
396
-
q_2: ────■──┼─
413
+
q_2: ────Z──┼─
397
414
│
398
-
q_3: ───────■─
415
+
q_3: ───────Z─
416
+
```
399
417
400
418
Notice, we've used a controlled Z-Gate from qubit 0 to each of the other qubits. When qubit 0 has a value of 1, the Z-Gate is applied to each of the other qubits, setting the matching phase for Grover's algorithm.
0 commit comments