-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathqft_test.go
92 lines (70 loc) · 1.68 KB
/
qft_test.go
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package qrad
import (
"math"
"testing"
)
func TestQFTDraw(t *testing.T) {
c := NewCircuit([]int{0, 1, 0, 1})
ApplyQFT(c, 0, 3)
c2 := NewCircuit([]int{0, 1, 0})
ApplyQFT(c2, 0, 2)
}
func TestInverseQFTDraw(t *testing.T) {
c := NewCircuit([]int{0, 1, 0, 1})
ApplyInverseQFT(c, 0, 3)
c2 := NewCircuit([]int{0, 1, 0})
ApplyInverseQFT(c2, 0, 2)
}
func TestQFTReversable(t *testing.T) {
soln := []int{0, 1, 0, 1}
c := NewCircuit(soln)
ApplyQFT(c, 0, 3)
ApplyInverseQFT(c, 0, 3)
c.Execute()
for i, b := range soln {
if c.MeasureQubit(i) != b {
t.Error("failed to run reversable QFT")
}
}
}
func TestQFTInverse(t *testing.T) {
c := NewCircuit([]int{0, 0, 0})
c.Append(H, []int{0, 1, 2})
c.Append(ROT(7*math.Pi/4, "7PI/4"), []int{0})
c.Append(ROT(7*math.Pi/2, "7PI/2"), []int{1})
c.Append(ROT(7*math.Pi, "7PI"), []int{2})
ApplyInverseQFT(c, 0, 2)
c.Execute()
for i := 0; i < 3; i++ {
if c.MeasureQubit(i) != 1 {
t.Error("failed to inverse QFT")
}
}
}
func TestQFTInverseOffset(t *testing.T) {
c := NewCircuit([]int{0, 0, 0, 0})
c.Append(H, []int{1, 2, 3})
c.Append(ROT(7*math.Pi/4, "7PI/4"), []int{1})
c.Append(ROT(7*math.Pi/2, "7PI/2"), []int{2})
c.Append(ROT(7*math.Pi, "7PI"), []int{3})
ApplyInverseQFT(c, 1, 3)
c.Execute()
for i := 1; i < 4; i++ {
if c.MeasureQubit(i) != 1 {
t.Error("failed to inverse QFT")
}
}
}
// func TestQFTInverse2(t *testing.T) {
// c := NewCircuit([]int{0, 0, 0, 0})
// c.Append(H, []int{2, 3})
// ApplyInverseQFT(c, 0, 3)
// c.Execute()
// c.Draw()
// for i := 0; i < 4; i++ {
// fmt.Println(c.MeasureQubit(i))
// // if c.MeasureQubit(i) != 1 {
// // t.Error("failed to inverse QFT")
// // }
// }
// }