Skip to content

Commit f09de73

Browse files
up
1 parent 338d692 commit f09de73

File tree

1 file changed

+47
-1
lines changed

1 file changed

+47
-1
lines changed

README.md

+47-1
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,53 @@ for j in range(len(bin_str)):
522522

523523
Just as we've done earlier, we're flipping the qubits, applying the controlled Z-Gate, and finally unflipping to restore the circuit.
524524

525-
Note, while it may be trivial to choose a random answer from the array of strings upon which we obviously know the index, encoding the index as qubits and then asking Grover's algorithm to find that index again for us, this example demonstrates how to use a controlled Z-Gate for this purpose.
525+
### Output
526+
527+
The magic eight ball example results in the following output.
528+
529+
```text
530+
Please ask me a yes/no question and I will predict your future [PRESS ANY KEY] ...
531+
532+
Selected random index 5
533+
Encoding 00101
534+
535+
q_0: ──────■──────
536+
┌───┐ │ ┌───┐
537+
q_1: ┤ X ├─■─┤ X ├
538+
└───┘ │ └───┘
539+
q_2: ──────■──────
540+
┌───┐ │ ┌───┐
541+
q_3: ┤ X ├─■─┤ X ├
542+
├───┤ │ ├───┤
543+
q_4: ┤ X ├─■─┤ X ├
544+
└───┘ │ └───┘
545+
q_5: ──────■──────
546+
547+
┌───┐ ░ ┌─────────┐ ░ ┌───────────┐ ░ ┌─┐
548+
var_0: ┤ H ├──────░─┤0 ├─░─┤0 ├─░──────┤M├─────────────────
549+
├───┤ ░ │ │ ░ │ │ ░ └╥┘┌─┐
550+
var_1: ┤ H ├──────░─┤1 ├─░─┤1 ├─░───────╫─┤M├──────────────
551+
├───┤ ░ │ │ ░ │ │ ░ ║ └╥┘┌─┐
552+
var_2: ┤ H ├──────░─┤2 ├─░─┤2 diffuser ├─░───────╫──╫─┤M├───────────
553+
├───┤ ░ │ oracle │ ░ │ │ ░ ║ ║ └╥┘┌─┐
554+
var_3: ┤ H ├──────░─┤3 ├─░─┤3 ├─░───────╫──╫──╫─┤M├────────
555+
├───┤ ░ │ │ ░ │ │ ░ ║ ║ ║ └╥┘┌─┐
556+
var_4: ┤ H ├──────░─┤4 ├─░─┤4 ├─░───────╫──╫──╫──╫─┤M├─────
557+
├───┤┌───┐ ░ │ │ ░ └───────────┘ ░ ┌───┐ ║ ║ ║ ║ └╥┘┌───┐
558+
out_0: ┤ X ├┤ H ├─░─┤5 ├─░───────────────░─┤ H ├─╫──╫──╫──╫──╫─┤ X ├
559+
└───┘└───┘ ░ └─────────┘ ░ ░ └───┘ ║ ║ ║ ║ ║ └───┘
560+
c: 5/═════════════════════════════════════════════════╩══╩══╩══╩══╩══════
561+
0 1 2 3 4
562+
{'01110': 26, '11010': 29, '11001': 26, '01111': 27, '00000': 34, '01011': 27, '00010': 25, '10011': 27, '10001': 25, '01010': 34, '00111': 31, '01100': 31, '00101': 165, '01001': 19, '10000': 27, '10101': 32, '11100': 32, '11110': 25, '00011': 16, '00100': 31, '00110': 36, '11011': 34, '01000': 28, '10100': 32, '11101': 29, '10110': 25, '10010': 29, '11111': 28, '11000': 24, '10111': 24, '01101': 25, '00001': 21}
563+
564+
Result: 5 (00101)
565+
566+
As I see it, yes.
567+
```
568+
569+
### Notes on Included Oracles
570+
571+
This repository contains very simple oracles for Grover's algorithm, some of which already know the target value and encode it within the oracle circuit. While it may be trivial to choose a random answer from the array of strings upon which we obviously know the index, encoding the index as qubits, and then asking Grover's algorithm to find that index again for us, this example demonstrates how to use a controlled Z-Gate for this purpose.
526572

527573
Future applications should take this idea further to craft more unique and robust oracles for Grover's algorithm where the answer is not immediately known, but is rather determined through a set of clauses.
528574

0 commit comments

Comments
 (0)