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 SiSWAP gate #1167

Merged
merged 6 commits into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
7 changes: 7 additions & 0 deletions doc/source/api-reference/qibo.rst
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,13 @@ iSwap (iSWAP)
:members:
:member-order: bysource

Square root of iSwap (SiSWAP)
"""""""""""""""""""""""""""""

.. autoclass:: qibo.gates.SiSWAP
:members:
:member-order: bysource

f-Swap (FSWAP)
""""""""""""""

Expand Down
1 change: 1 addition & 0 deletions src/qibo/backends/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ def create(self, dtype):
self.CSXDG = self.matrices.CSXDG
self.SWAP = self.matrices.SWAP
self.iSWAP = self.matrices.iSWAP
self.SiSWAP = self.matrices.SiSWAP
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 @@ -194,6 +194,18 @@ def iSWAP(self):
[[1, 0, 0, 0], [0, 0, 1j, 0], [0, 1j, 0, 0], [0, 0, 0, 1]], dtype=self.dtype
)

@cached_property
def SiSWAP(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
29 changes: 28 additions & 1 deletion src/qibo/gates/gates.py
Original file line number Diff line number Diff line change
Expand Up @@ -1476,7 +1476,7 @@ def qasm_label(self):


class iSWAP(Gate):
"""The iswap gate.
"""The iSWAP gate.

Corresponds to the following unitary matrix

Expand Down Expand Up @@ -1507,6 +1507,33 @@ def qasm_label(self):
return "iswap"


class SiSWAP(Gate):
"""The :math:`\\sqrt{\\text{iSWAP}}}` 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 = "siswap"
self.draw_label = "si"
self.target_qubits = (q0, q1)
self.init_args = [q0, q1]
self.unitary = True


class FSWAP(Gate):
"""The fermionic swap gate.

Expand Down
11 changes: 11 additions & 0 deletions tests/test_gates_gates.py
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,17 @@ def test_iswap(backend):
assert gates.iSWAP(0, 1).unitary


def test_siswap(backend):
final_state = apply_gates(backend, [gates.X(1), gates.SiSWAP(0, 1)], nqubits=2)
target_state = np.zeros_like(final_state)
target_state[1] = 1.0 / np.sqrt(2)
target_state[2] = 1.0j / np.sqrt(2)
backend.assert_allclose(final_state, target_state)

assert not gates.SiSWAP(0, 1).clifford
assert gates.SiSWAP(0, 1).unitary


def test_fswap(backend):
nqubits = 2
initial_state = random_statevector(2**nqubits, backend=backend)
Expand Down
Loading