Skip to content

Commit

Permalink
Merge pull request #1191 from qiboteam/siswap
Browse files Browse the repository at this point in the history
Add `SiSWAPDG` gate
  • Loading branch information
renatomello authored Feb 6, 2024
2 parents 330f1bb + 9c197dd commit 176d75c
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 1 deletion.
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
35 changes: 34 additions & 1 deletion src/qibo/gates/gates.py
Original file line number Diff line number Diff line change
Expand Up @@ -1508,7 +1508,7 @@ def qasm_label(self):


class SiSWAP(Gate):
"""The :math:`\\sqrt{\\text{iSWAP}}}` gate.
"""The :math:`\\sqrt{\\text{iSWAP}}` gate.
Corresponds to the following unitary matrix
Expand All @@ -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:`\\left(\\sqrt{\\text{iSWAP}}\\right)^{\\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 176d75c

Please sign in to comment.