Skip to content

Commit

Permalink
Only use "reducers" that strictly improve fidelity (#684)
Browse files Browse the repository at this point in the history
  • Loading branch information
notmgsk authored Dec 4, 2020
1 parent 2f54996 commit 2e015ee
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/compressor/compressor.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -240,10 +240,10 @@ other's."
context)
"Applies peephole rewriter rules from a CHIP-SPECIFICATION to a sequence of INSTRUCTIONS, using CONTEXT to activate context-sensitive rules."
(labels
( ;; utility for calculating how many instructions a rewriting rule requests
(;; utility for calculating how many instructions a rewriting rule requests
(rewriting-rule-count (compiler)
(length (compiler-bindings compiler)))

;; let the context know that we've passed inspection of NODE, so that the
;; effect of that instruction is visible during inspection of the next node
(update-context (node)
Expand Down Expand Up @@ -303,7 +303,7 @@ other's."
;; successfully, we rewind by the peephole window and try again. if it
;; fails, we fall through, step through to the next node, and try again.
(outer-instruction-loop (node)
(do ( ;; for each instruction...
(do (;; for each instruction...
(node #1=(peephole-rewriter-node-next node) #1#))
((null node))
(update-context node)
Expand Down
4 changes: 2 additions & 2 deletions src/define-compiler.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -874,7 +874,7 @@ Compilers matching gates which don't have parameters don't count as accepting pa
(let* ((input-fidelity (calculate-fidelity-of-concrete-gates gates))
(output (apply compiler gates))
(output-fidelity (calculate-fidelity-of-concrete-gates output)))
(>= output-fidelity input-fidelity))
(> output-fidelity input-fidelity))
(no-binding-match () nil)
(compiler-does-not-apply () nil)
(cannot-concretize-binding () nil)))
Expand Down Expand Up @@ -907,7 +907,7 @@ Compilers matching gates which don't have parameters don't count as accepting pa
(when (typep b 'gate-binding)
(binding-subsumes-p (copy-binding b :options nil) g)))
(setf in-fidelity (* in-fidelity gate-fidelity)))))
(>= out-fidelity in-fidelity)))
(> out-fidelity in-fidelity)))
;; if that falls through, try the exhaustive match
(let ((matches (loop :for binding :in (compiler-bindings compiler)
:for match := (gates-that-match-binding binding gateset)
Expand Down
9 changes: 5 additions & 4 deletions tests/compilation-tests.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -240,13 +240,14 @@ CNOT 4 8
(progm (parse "RX(pi/2) 0; RX(pi/2) 0"))
(comp (compiler-hook progm chip))
(code (%filter-halt comp)))
(is (m= (parsed-program-to-logical-matrix
(parse "RX(pi) 0"))
(parsed-program-to-logical-matrix comp)))
(is (quil::matrix-equals-dwim
(parsed-program-to-logical-matrix
(parse "RX(pi) 0"))
(parsed-program-to-logical-matrix comp)))
(is (= 1 (length code)))
(is (string= "RX" (quil::application-operator-root-name (elt code 0))))
(is (quil::double= pi
(constant-value (first (application-parameters (elt code 0))))))))
(abs (constant-value (first (application-parameters (elt code 0)))))))))

(defun %random-rz-rx-program (length)
(make-instance 'parsed-program
Expand Down

0 comments on commit 2e015ee

Please sign in to comment.