def get_merged(self, other): """ Return self merged with another gate. Default implementation handles rotation gate of the same type, where angles are simply added. Args: other: Rotation gate of same type. Raises: NotMergeable: For non-rotation gates or rotation gates of different type. Returns: New object representing the merged gates. """ if isinstance(other, self.__class__): return self.__class__((self.angle + other.angle) / cmath.pi) raise NotMergeable("Can't merge different types of rotation gates.")
def get_merged(self, other): if not isinstance(other, ScaleGate): raise NotMergeable() return ScaleGate(self.factor * other.factor, self.inverse_factor * other.inverse_factor)
def get_merged(self, other): if (not isinstance(other, ModularBimultiplicationGate) or other.modulus != self.modulus): raise NotMergeable() return ModularBimultiplicationGate(self.factor * other.factor, self.modulus)
def get_merged(self, other): raise NotMergeable()
def get_merged(self, other): if not isinstance(other, RotateBitsGate): raise NotMergeable() return RotateBitsGate(self.amount + other.amount)
def get_merged(self, other): if not isinstance(other, ScaledAdditionGate): raise NotMergeable() return ScaledAdditionGate(self.factor * other.factor)
def get_merged(self, other): if not isinstance(other, OffsetGate): raise NotMergeable() return OffsetGate(self.offset + other.offset)