From 779cb7fa0a9029c3e9056ef2642221b061dadfdb Mon Sep 17 00:00:00 2001 From: Robert Smith Date: Mon, 18 Jul 2022 17:06:44 -0700 Subject: [PATCH] compile CONTROLLED R[XYZ] allowing symbolic parameters --- src/compilers/translators.lisp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/compilers/translators.lisp b/src/compilers/translators.lisp index c660e7ed0..8da283c88 100644 --- a/src/compilers/translators.lisp +++ b/src/compilers/translators.lisp @@ -436,3 +436,31 @@ Note that if (= START-NODE TARGET-NODE) then (list START-NODE) is returned." (define-compiler C-SWAP-to-CSWAP ((_ (#.(controlled-operator (named-operator "SWAP")) () p q r))) (inst "CSWAP" () p q r)) + +(define-compiler C-RX-to-CZ-RX + ((_ (#.(controlled-operator (named-operator "RX")) (theta) p q))) + (inst "CZ" () p q) + (inst "RX" (list (param-* -1/2 theta)) q) + (inst "CZ" () p q) + (inst "RX" (list (param-* 1/2 theta)) q)) + +(define-compiler C-RY-to-CZ-RY + ((_ (#.(controlled-operator (named-operator "RY")) (theta) p q))) + (inst "CZ" () p q) + (inst "RY" (list (param-* -1/2 theta)) q) + (inst "CZ" () p q) + (inst "RY" (list (param-* 1/2 theta)) q)) + +(define-compiler C-RY-to-CNOT-RY + ((_ (#.(controlled-operator (named-operator "RY")) (theta) p q))) + (inst "CNOT" () p q) + (inst "RY" (list (param-* -1/2 theta)) q) + (inst "CNOT" () p q) + (inst "RY" (list (param-* 1/2 theta)) q)) + +(define-compiler C-RZ-to-CNOT-RZ + ((_ (#.(controlled-operator (named-operator "RZ")) (theta) p q))) + (inst "CNOT" () p q) + (inst "RZ" (list (param-* -1/2 theta)) q) + (inst "CNOT" () p q) + (inst "RZ" (list (param-* 1/2 theta)) q))