Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SiSWAPDG gate #1191

Merged
merged 4 commits into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading