Skip to content

Commit

Permalink
Add pauli_rep properties for common static gates PennyLaneAI#6243
Browse files Browse the repository at this point in the history
  • Loading branch information
Lasse Dierich committed Nov 5, 2024
1 parent c06375c commit 12f7343
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions pennylane/ops/qubit/non_parametric_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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).
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 12f7343

Please sign in to comment.