Skip to content
Draft
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
19 changes: 19 additions & 0 deletions src/qibo/backends/npmatrices.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,25 @@ def SWAP(self):
[[1, 0, 0, 0], [0, 0, 1, 0], [0, 1, 0, 0], [0, 0, 0, 1]], dtype=self.dtype
)

@cached_property
def CSWAP(self):
return self._cast(
[
[1, 0, 0, 0, 0, 0, 0, 0],
[0, 1, 0, 0, 0, 0, 0, 0],
[0, 0, 1, 0, 0, 0, 0, 0],
[0, 0, 0, 1, 0, 0, 0, 0],
[0, 0, 0, 0, 1, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 1, 0],
[0, 0, 0, 0, 0, 1, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 1],
],
dtype=self.dtype,
)
# return self._cast(
# [[1, 0, 0, 0], [0, 0, 1, 0], [0, 1, 0, 0], [0, 0, 0, 1]], dtype=self.dtype
# )

@cached_property
def iSWAP(self):
return self._cast(
Expand Down
45 changes: 45 additions & 0 deletions src/qibo/gates/gates.py
Original file line number Diff line number Diff line change
Expand Up @@ -1686,6 +1686,51 @@ def qasm_label(self) -> str:
return "swap"


class CSWAP(Gate):
"""The controlled-SWAP gate.

Corresponds to the following unitary matrix

.. math::
\\begin{pmatrix}
1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\\\
0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 \\\\
0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 \\\\
0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 \\\\
0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 \\\\
0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 \\\\
0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 \\\\
0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 \\\\
\\end{pmatrix}

Args:
q0 (int): the control qubit id number.
q1 (int): the first target qubit id number.
q2 (int): the second target qubit id number.
"""

def __init__(self, q0: int, q1: int, q2: int):
super().__init__()
self.name = "cswap"
self.draw_label = "x"
self.control_qubits = (q0,)
self.target_qubits = (q1, q2)
self.init_args = [q0, q1, q2]
self.unitary = True

@property
def clifford(self) -> bool:
return False

@property
def hamming_weight(self) -> bool:
return True

@property
def qasm_label(self) -> str:
return "cswap"


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

Expand Down
Loading