Skip to content

Commit

Permalink
Add q.Theta
Browse files Browse the repository at this point in the history
  • Loading branch information
itsubaki committed Sep 9, 2023
1 parent 50dda79 commit 89e7364
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
8 changes: 6 additions & 2 deletions q.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ func Index(qb ...Qubit) []int {
return idx
}

func Theta(k int) float64 {
return gate.Theta(k)
}

// Q is a quantum computation simulator.
type Q struct {
qb *qubit.Qubit
Expand Down Expand Up @@ -343,7 +347,7 @@ func (q *Q) QFT(qb ...Qubit) *Q {

k := 2
for j := i + 1; j < l; j++ {
q.CR(gate.Theta(k), qb[j], qb[i])
q.CR(Theta(k), qb[j], qb[i])
k++
}
}
Expand All @@ -357,7 +361,7 @@ func (q *Q) InverseQFT(qb ...Qubit) *Q {
for i := l - 1; i > -1; i-- {
k := l - i
for j := l - 1; j > i; j-- {
q.CR(-1*gate.Theta(k), qb[j], qb[i])
q.CR(-1*Theta(k), qb[j], qb[i])
k--
}

Expand Down
24 changes: 12 additions & 12 deletions q_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -984,10 +984,10 @@ func Example_qFT() {
q2 := qsim.Zero()

qsim.H(q0)
qsim.CR(gate.Theta(2), q1, q0)
qsim.CR(gate.Theta(3), q2, q0)
qsim.CR(q.Theta(2), q1, q0)
qsim.CR(q.Theta(3), q2, q0)
qsim.H(q1)
qsim.CR(gate.Theta(2), q2, q1)
qsim.CR(q.Theta(2), q2, q1)
qsim.H(q2)
qsim.Swap(q0, q2)

Expand Down Expand Up @@ -1126,14 +1126,14 @@ func Example_shorFactoring51() {
// inverse QFT
qsim.Swap(q0, q1, q2, q3)
qsim.H(q3)
qsim.CR(-1*gate.Theta(2), q3, q2)
qsim.CR(-1*q.Theta(2), q3, q2)
qsim.H(q2)
qsim.CR(-1*gate.Theta(3), q3, q1)
qsim.CR(-1*gate.Theta(2), q2, q1)
qsim.CR(-1*q.Theta(3), q3, q1)
qsim.CR(-1*q.Theta(2), q2, q1)
qsim.H(q1)
qsim.CR(-1*gate.Theta(4), q3, q0)
qsim.CR(-1*gate.Theta(3), q2, q0)
qsim.CR(-1*gate.Theta(2), q1, q0)
qsim.CR(-1*q.Theta(4), q3, q0)
qsim.CR(-1*q.Theta(3), q2, q0)
qsim.CR(-1*q.Theta(2), q1, q0)
qsim.H(q0)

m := qsim.Measure(q0, q1, q2, q3).BinaryString()
Expand Down Expand Up @@ -1186,9 +1186,9 @@ func Example_shorFactoring85() {
// inverse QFT
qsim.Swap(q0, q1, q2, q3)
qsim.H(q3)
qsim.CR(-1*gate.Theta(2), q3, q2).H(q2)
qsim.CR(-1*gate.Theta(3), q3, q1).CR(-1*gate.Theta(2), q2, q1).H(q1)
qsim.CR(-1*gate.Theta(4), q3, q0).CR(-1*gate.Theta(3), q2, q0).CR(-1*gate.Theta(2), q1, q0).H(q0)
qsim.CR(-1*q.Theta(2), q3, q2).H(q2)
qsim.CR(-1*q.Theta(3), q3, q1).CR(-1*q.Theta(2), q2, q1).H(q1)
qsim.CR(-1*q.Theta(4), q3, q0).CR(-1*q.Theta(3), q2, q0).CR(-1*q.Theta(2), q1, q0).H(q0)

m := qsim.Measure(q0, q1, q2, q3).BinaryString()
s, r, d, ok := number.FindOrder(a, N, fmt.Sprintf("0.%s", m))
Expand Down

0 comments on commit 89e7364

Please sign in to comment.