diff --git a/pennylane/ops/qubit/non_parametric_ops.py b/pennylane/ops/qubit/non_parametric_ops.py index b4e0d8407dc..7d447399f5c 100644 --- a/pennylane/ops/qubit/non_parametric_ops.py +++ b/pennylane/ops/qubit/non_parametric_ops.py @@ -77,6 +77,10 @@ def __repr__(self) -> str: def name(self) -> str: return "Hadamard" + def __init__(self, wires: WiresLike, id: Optional[str] = None): + super().__init__(wires=wires, id=id) + self._pauli_rep = qml.pauli.PauliSentence({qml.pauli.PauliWord({self.wires[0]: 'X'}) : INV_SQRT2, qml.pauli.PauliWord({self.wires[0]: 'Z'}) : INV_SQRT2}) + @staticmethod @lru_cache() def compute_matrix() -> np.ndarray: # pylint: disable=arguments-differ @@ -815,6 +819,10 @@ class S(Operation): batch_size = None + def __init__(self, wires: WiresLike, id: Optional[str] = None): + super().__init__(wires=wires, id=id) + self._pauli_rep = qml.pauli.PauliSentence({qml.pauli.PauliWord({self.wires[0]: 'I'}) : 0.5 + 0.5j, qml.pauli.PauliWord({self.wires[0]: 'Z'}) : 0.5 - 0.5j}) + @staticmethod @lru_cache() def compute_matrix() -> np.ndarray: # pylint: disable=arguments-differ @@ -927,6 +935,10 @@ class T(Operation): batch_size = None + def __init__(self, wires: WiresLike, id: Optional[str] = None): + super().__init__(wires=wires, id=id) + self._pauli_rep = qml.pauli.PauliSentence({qml.pauli.PauliWord({self.wires[0]: 'I'}) : (0.5 + 0.5 * INV_SQRT2 * (1 + 1.j)), qml.pauli.PauliWord({self.wires[0]: 'Z'}) : (0.5 - 0.5 * INV_SQRT2 * (1 + 1.j))}) + @staticmethod @lru_cache() def compute_matrix() -> np.ndarray: # pylint: disable=arguments-differ @@ -1037,6 +1049,10 @@ class SX(Operation): basis = "X" + def __init__(self, wires: WiresLike, id: Optional[str] = None): + super().__init__(wires=wires, id=id) + self._pauli_rep = qml.pauli.PauliSentence({qml.pauli.PauliWord({self.wires[0]: 'I'}) : (0.5 + 0.5j), qml.pauli.PauliWord({self.wires[0]: 'X'}) : (0.5 - 0.5j)}) + @staticmethod @lru_cache() def compute_matrix() -> np.ndarray: # pylint: disable=arguments-differ @@ -1152,6 +1168,13 @@ class SWAP(Operation): batch_size = None + def __init__(self, wires: WiresLike, id: Optional[str] = None): + super().__init__(wires=wires, id=id) + self._pauli_rep = qml.pauli.PauliSentence({ qml.pauli.PauliWord({self.wires[0]: 'I', self.wires[1]: 'I'}) : 0.5, + qml.pauli.PauliWord({self.wires[0]: 'X', self.wires[1]: 'X'}) : 0.5, + qml.pauli.PauliWord({self.wires[0]: 'Y', self.wires[1]: 'Y'}) : 0.5, + qml.pauli.PauliWord({self.wires[0]: 'Z', self.wires[1]: 'Z'}) : 0.5 }) + @staticmethod @lru_cache() def compute_matrix() -> np.ndarray: # pylint: disable=arguments-differ @@ -1243,6 +1266,11 @@ class ECR(Operation): batch_size = None + def __init__(self, wires: WiresLike, id: Optional[str] = None): + super().__init__(wires=wires, id=id) + self._pauli_rep = qml.pauli.PauliSentence({ qml.pauli.PauliWord({self.wires[0]: 'X', self.wires[1]: 'I'}) : INV_SQRT2, + qml.pauli.PauliWord({self.wires[0]: 'Y', self.wires[1]: 'X'}) : - INV_SQRT2 }) + @staticmethod def compute_matrix() -> np.ndarray: # pylint: disable=arguments-differ r"""Representation of the operator as a canonical matrix in the computational basis (static method). @@ -1371,6 +1399,13 @@ class ISWAP(Operation): batch_size = None + def __init__(self, wires: WiresLike, id: Optional[str] = None): + super().__init__(wires=wires, id=id) + self._pauli_rep = qml.pauli.PauliSentence({ qml.pauli.PauliWord({self.wires[0]: 'I', self.wires[1]: 'I'}) : 0.5, + qml.pauli.PauliWord({self.wires[0]: 'X', self.wires[1]: 'X'}) : 0.5j, + qml.pauli.PauliWord({self.wires[0]: 'Y', self.wires[1]: 'Y'}) : 0.5j, + qml.pauli.PauliWord({self.wires[0]: 'Z', self.wires[1]: 'Z'}) : 0.5 }) + @staticmethod @lru_cache() def compute_matrix() -> np.ndarray: # pylint: disable=arguments-differ @@ -1488,6 +1523,13 @@ class SISWAP(Operation): batch_size = None + def __init__(self, wires: WiresLike, id: Optional[str] = None): + super().__init__(wires=wires, id=id) + self._pauli_rep = qml.pauli.PauliSentence({ qml.pauli.PauliWord({self.wires[0]: 'I', self.wires[1]: 'I'}) : 0.5 + 0.5 * INV_SQRT2, + qml.pauli.PauliWord({self.wires[0]: 'X', self.wires[1]: 'X'}) : 0.5j * INV_SQRT2, + qml.pauli.PauliWord({self.wires[0]: 'Y', self.wires[1]: 'Y'}) : 0.5j * INV_SQRT2, + qml.pauli.PauliWord({self.wires[0]: 'Z', self.wires[1]: 'Z'}) : 0.5 - 0.5 * INV_SQRT2 }) + @staticmethod @lru_cache() def compute_matrix() -> np.ndarray: # pylint: disable=arguments-differ