-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrover-sudoku.qs
56 lines (47 loc) · 1.36 KB
/
grover-sudoku.qs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
namespace GroverSudoku {
open Microsoft.Quantum.Intrinsic;
open Microsoft.Quantum.Arithmetic;
open Microsoft.Quantum.Canon;
open Microsoft.Quantum.Arrays;
open Microsoft.Quantum.Measurement;
operation XOR(q1: Qubit, q2: Qubit, output: Qubit): Unit is Adj {
CNOT(q1, output);
CNOT(q2, output);
}
operation SudokuOracle(input: Qubit[], tmp: Qubit[], output: Qubit): Unit {
within {
XOR(input[0], input[1], tmp[0]);
XOR(input[1], input[3], tmp[1]);
XOR(input[0], input[2], tmp[2]);
XOR(input[2], input[3], tmp[3]);
} apply {
Controlled X(tmp, output);
}
}
operation ReflectZero(input: Qubit[]) : Unit {
within {
ApplyToEachA(X, input);
} apply {
Controlled Z(Most(input), Tail(input));
}
}
operation GroverCircuit() : Result[] {
use input = Qubit[4];
use tmp = Qubit[4];
use pkb = Qubit();
ApplyToEach(H, input);
X(pkb);
H(pkb);
for _ in 1..2 {
SudokuOracle(input, tmp, pkb);
within {
ApplyToEachA(H, input);
} apply {
ReflectZero(input);
}
}
let results = MultiM(input);
ResetAll(tmp + [pkb]);
return results;
}
}