From a8bee81d90a26fbb9dc822ba26e89784cd3a01d2 Mon Sep 17 00:00:00 2001 From: filipw Date: Sat, 30 Nov 2024 12:46:13 +0100 Subject: [PATCH] added Rxx Ryy and Rzz --- src/qasm.rs | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/src/qasm.rs b/src/qasm.rs index 419047f..d17565a 100644 --- a/src/qasm.rs +++ b/src/qasm.rs @@ -136,21 +136,33 @@ impl Backend for Qasm2Backend { } fn rxx(&mut self, theta: f64, q0: usize, q1: usize) { - // todo: check if rxx is supported in qasm 2.0, probably not - self.code - .push(format!("rxx({}) q[{}], q[{}];", theta, q0, q1)); + self.code.push(format!("h q[{}];", q0)); + self.code.push(format!("h q[{}];", q1)); + self.code.push(format!("cx q[{}], q[{}];", q0, q1)); + self.code.push(format!("rz({}) q[{}];", theta, q1)); + self.code.push(format!("cx q[{}], q[{}];", q0, q1)); + self.code.push(format!("h q[{}];", q0)); + self.code.push(format!("h q[{}];", q1)); } fn ryy(&mut self, theta: f64, q0: usize, q1: usize) { - // todo: check if rxx is supported in qasm 2.0, probably not - self.code - .push(format!("ryy({}) q[{}], q[{}];", theta, q0, q1)); + self.code.push(format!("sdg q[{}];", q0)); + self.code.push(format!("sdg q[{}];", q1)); + self.code.push(format!("h q[{}];", q0)); + self.code.push(format!("h q[{}];", q1)); + self.code.push(format!("cx q[{}], q[{}];", q0, q1)); + self.code.push(format!("rz({}) q[{}];", theta, q1)); + self.code.push(format!("cx q[{}], q[{}];", q0, q1)); + self.code.push(format!("h q[{}];", q0)); + self.code.push(format!("h q[{}];", q1)); + self.code.push(format!("s q[{}];", q0)); + self.code.push(format!("s q[{}];", q1)); } fn rzz(&mut self, theta: f64, q0: usize, q1: usize) { - // todo: check if rxx is supported in qasm 2.0, probably not - self.code - .push(format!("rzz({}) q[{}], q[{}];", theta, q0, q1)); + self.code.push(format!("cx q[{}], q[{}];", q0, q1)); + self.code.push(format!("rz({}) q[{}];", theta, q1)); + self.code.push(format!("cx q[{}], q[{}];", q0, q1)); } fn cy(&mut self, ctl: usize, q: usize) {