From 6d1fa445f83e535a854660716f972f373c6a41a1 Mon Sep 17 00:00:00 2001 From: David Yonge-Mallo Date: Sat, 21 Oct 2023 10:06:28 +0200 Subject: [PATCH] Make `RZZ` a subclass of `ParityPhase`. --- pyzx/circuit/gates.py | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/pyzx/circuit/gates.py b/pyzx/circuit/gates.py index 0bada393..ed26f84d 100644 --- a/pyzx/circuit/gates.py +++ b/pyzx/circuit/gates.py @@ -725,24 +725,6 @@ def to_graph(self, g, q_mapper, c_mapper): for gate in self.to_basic_gates(): gate.to_graph(g, q_mapper, c_mapper) -class RZZ(Gate): - name = 'RZZ' - qasm_name = 'rzz' - print_phase = True - def __init__(self, control: int, target: int, phase: FractionLike) -> None: - self.target = target - self.control = control - self.phase = phase - - def to_basic_gates(self): - return [CNOT(control=self.control,target=self.target), - ZPhase(self.target,phase=self.phase), - CNOT(control=self.control,target=self.target)] - - def to_graph(self, g, q_mapper, c_mapper): - for gate in self.to_basic_gates(): - gate.to_graph(g, q_mapper, c_mapper) - class CPhase(CRZ): name = 'CPhase' qasm_name = 'cp' @@ -820,6 +802,16 @@ def tcount(self): return 1 if self.phase.denominator > 2 else 0 +class RZZ(ParityPhase): + name = 'RZZ' + qasm_name = 'rzz' + def __init__(self, control: int, target: int, phase: FractionLike) -> None: + self.control = control + self.target = target + self.targets = (control, target) + self.phase = phase + + class FSim(Gate): name = 'FSim' qsim_name = 'fs'