Skip to content

Commit 040d3d2

Browse files
authored
Merge pull request #58 from itsubaki/expand-search-space
Add an extra qubit for search space expansion
2 parents 160a755 + 28ef9ce commit 040d3d2

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

cmd/counting/main.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ func oracle(qsim *q.Q, r, s []q.Qubit, c, a q.Qubit) {
2020
xor(r[0], r[2], s[2]) // a != c
2121
xor(r[1], r[3], s[3]) // b != d
2222

23-
// apply X if c and s are all 1
24-
qsim.ControlledX([]q.Qubit{c, s[0], s[1], s[2], s[3]}, []q.Qubit{a})
23+
// apply X if s and c are all 1
24+
// r[4] is an extra qubit for search space expansion
25+
qsim.ControlledX([]q.Qubit{s[0], s[1], s[2], s[3], c, r[4]}, []q.Qubit{a})
2526

2627
// uncompute
2728
xor(r[1], r[3], s[3])
@@ -55,12 +56,18 @@ func main() {
5556

5657
// initialize
5758
c := qsim.Zeros(t) // for phase estimation
58-
r := qsim.Zeros(4) // data qubits for the Grover search space
59+
60+
// data qubits for the Grover search space
61+
// technique for expanding the search space from N to 2N
62+
r := qsim.Zeros(5)
5963
s := qsim.Zeros(4) // ancilla qubits for comparing Sudoku constraints
6064
a := qsim.Zero() // ancilla qubit for oracle
6165

66+
// superposition
6267
qsim.H(c...)
6368
qsim.H(r...)
69+
70+
// prepare ancilla to minus state
6471
qsim.X(a)
6572
qsim.H(a)
6673

@@ -83,6 +90,6 @@ func main() {
8390
theta := 2 * math.Pi * phi // theta = 2*pi*phi
8491
M := N * math.Pow(math.Sin(theta/2), 2) // M = N*(sin(theta/2))**2
8592

86-
fmt.Printf("%v; phi=%.4f, theta=%.4f, M=%.4f, M'=%.4f\n", state, phi, theta, M, N-M)
93+
fmt.Printf("%v; phi=%.4f, theta=%.4f, M=%.4f, eps=%.4f\n", state, phi, theta, min(M, N-M), math.Abs(min(M, N-M)-2))
8794
}
8895
}

0 commit comments

Comments
 (0)