Skip to content

Commit

Permalink
add SiSWAPDG gate
Browse files Browse the repository at this point in the history
  • Loading branch information
renatomello committed Feb 5, 2024
1 parent c113117 commit 8e719a3
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/qibo/backends/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ def create(self, dtype):
self.SWAP = self.matrices.SWAP
self.iSWAP = self.matrices.iSWAP
self.SiSWAP = self.matrices.SiSWAP
self.SiSWAPDG = self.matrices.SiSWAPDG
self.FSWAP = self.matrices.FSWAP
self.ECR = self.matrices.ECR
self.SYC = self.matrices.SYC
Expand Down
12 changes: 12 additions & 0 deletions src/qibo/backends/npmatrices.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,18 @@ def SiSWAP(self):
dtype=self.dtype,
)

@cached_property
def SiSWAPDG(self):
return self.np.array(
[
[1, 0, 0, 0],
[0, 1 / self.np.sqrt(2), -1j / self.np.sqrt(2), 0],
[0, -1j / self.np.sqrt(2), 1 / self.np.sqrt(2), 0],
[0, 0, 0, 1],
],
dtype=self.dtype,
)

@cached_property
def FSWAP(self):
return self.np.array(
Expand Down
33 changes: 33 additions & 0 deletions src/qibo/gates/gates.py
Original file line number Diff line number Diff line change
Expand Up @@ -1533,6 +1533,39 @@ def __init__(self, q0, q1):
self.init_args = [q0, q1]
self.unitary = True

def _dagger(self) -> "Gate":
return SiSWAPDG(*self.qubits)


class SiSWAPDG(Gate):
"""The :math:`\\sqrt{\\text{iSWAP}}}^{\\dagger}` gate.
Corresponds to the following unitary matrix
.. math::
\\begin{pmatrix}
1 & 0 & 0 & 0 \\\\
0 & 1/\\sqrt{2} & -i/\\sqrt{2} & 0 \\\\
0 & -i/\\sqrt{2} & 1/\\sqrt{2} & 0 \\\\
0 & 0 & 0 & 1 \\\\
\\end{pmatrix}
Args:
q0 (int): the first qubit to be swapped id number.
q1 (int): the second qubit to be swapped id number.
"""

def __init__(self, q0, q1):
super().__init__()
self.name = "siswapdg"
self.draw_label = "sidg"
self.target_qubits = (q0, q1)
self.init_args = [q0, q1]
self.unitary = True

def _dagger(self) -> "Gate":
return SiSWAP(*self.qubits)


class FSWAP(Gate):
"""The fermionic swap gate.
Expand Down
2 changes: 2 additions & 0 deletions tests/test_gates_gates.py
Original file line number Diff line number Diff line change
Expand Up @@ -1546,6 +1546,8 @@ def test_controlled_unitary_matrix(backend):
("GIVENS", (0, 1, 0.1)),
("RBS", (0, 1, 0.2)),
("ECR", (0, 1)),
("SiSWAP", (0, 1)),
("SiSWAPDG", (0, 1)),
]


Expand Down

0 comments on commit 8e719a3

Please sign in to comment.