Skip to content

Commit

Permalink
Update some files
Browse files Browse the repository at this point in the history
  • Loading branch information
itsubaki committed May 24, 2022
1 parent aed1fc0 commit 852a22f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
16 changes: 0 additions & 16 deletions pkg/evaluator/builtin.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,6 @@ func Builtin(g lexer.Token, p []float64) (matrix.Matrix, bool) {
return nil, false
}

func BuiltinApply(qsim *q.Q, g lexer.Token, p []float64, qargs [][]q.Qubit) bool {
switch g {
case lexer.QFT:
qsim.QFT(flatten(qargs)...)
return true
case lexer.IQFT:
qsim.InvQFT(flatten(qargs)...)
return true
case lexer.CMODEXP2:
qsim.CModExp2(int(p[0]), int(p[1]), qargs[0], qargs[1])
return true
}

return false
}

func flatten(qargs [][]q.Qubit) []q.Qubit {
var out []q.Qubit
for _, q := range qargs {
Expand Down
18 changes: 17 additions & 1 deletion pkg/evaluator/evaluator.go
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ func (e *Evaluator) Apply(s *ast.ApplyStmt, env *env.Environ) error {
}

// QFT, IQFT, CMODEXP2
if BuiltinApply(e.Q, s.Kind, params, qargs) {
if e.ApplyBuiltin(s.Kind, params, qargs) {
return nil
}

Expand All @@ -462,6 +462,22 @@ func (e *Evaluator) Apply(s *ast.ApplyStmt, env *env.Environ) error {
return nil
}

func (e *Evaluator) ApplyBuiltin(g lexer.Token, p []float64, qargs [][]q.Qubit) bool {
switch g {
case lexer.QFT:
e.Q.QFT(flatten(qargs)...)
return true
case lexer.IQFT:
e.Q.InvQFT(flatten(qargs)...)
return true
case lexer.CMODEXP2:
e.Q.CModExp2(int(p[0]), int(p[1]), qargs[0], qargs[1])
return true
}

return false
}

func (e *Evaluator) ApplyU(mod []ast.Modifier, u matrix.Matrix, qargs [][]q.Qubit, env *env.Environ) error {
// Modifier
// FIXME: ctrl and pow cannot be specified at the same time.
Expand Down

0 comments on commit 852a22f

Please sign in to comment.