Skip to content

Commit 0ef28db

Browse files
up
1 parent c95a394 commit 0ef28db

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

README.md

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ q_1: ──■─────
326326
327327
q_2: ──■─────
328328
329-
q_3: ───────
329+
q_3: ──Z─────
330330
```
331331

332332
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 ├
355355
└───┘ │ └───┘
356356
q_3: ──────■──────
357357
358-
q_4: ────────────
358+
q_4: ──────Z──────
359359
```
360360

361361
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
387387

388388
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.
389389

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.
391391

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+
```
392409
q_0: ─■──■──■─
393410
│ │ │
394-
q_1: ───┼──┼─
411+
q_1: ─Z──┼──┼─
395412
│ │
396-
q_2: ──────┼─
413+
q_2: ────Z──┼─
397414
398-
q_3: ───────■─
415+
q_3: ───────Z─
416+
```
399417

400418
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.
401419

0 commit comments

Comments
 (0)