From 8e719a395d5ad48ea2b4df99a697f68e047680e9 Mon Sep 17 00:00:00 2001 From: Renato Mello Date: Mon, 5 Feb 2024 12:30:54 +0400 Subject: [PATCH 1/2] add `SiSWAPDG` gate --- src/qibo/backends/__init__.py | 1 + src/qibo/backends/npmatrices.py | 12 ++++++++++++ src/qibo/gates/gates.py | 33 +++++++++++++++++++++++++++++++++ tests/test_gates_gates.py | 2 ++ 4 files changed, 48 insertions(+) diff --git a/src/qibo/backends/__init__.py b/src/qibo/backends/__init__.py index 09e1fe1a54..9c99947881 100644 --- a/src/qibo/backends/__init__.py +++ b/src/qibo/backends/__init__.py @@ -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 diff --git a/src/qibo/backends/npmatrices.py b/src/qibo/backends/npmatrices.py index 364845c514..ee65e90275 100644 --- a/src/qibo/backends/npmatrices.py +++ b/src/qibo/backends/npmatrices.py @@ -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( diff --git a/src/qibo/gates/gates.py b/src/qibo/gates/gates.py index aa0e0d5ede..128518a89e 100644 --- a/src/qibo/gates/gates.py +++ b/src/qibo/gates/gates.py @@ -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. diff --git a/tests/test_gates_gates.py b/tests/test_gates_gates.py index e014031eac..caabc73e57 100644 --- a/tests/test_gates_gates.py +++ b/tests/test_gates_gates.py @@ -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)), ] From 9c197dd130f958c8079b1ca63ce81f81c197afe0 Mon Sep 17 00:00:00 2001 From: Renato Mello Date: Tue, 6 Feb 2024 17:59:44 +0400 Subject: [PATCH 2/2] fic docstring --- src/qibo/gates/gates.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/qibo/gates/gates.py b/src/qibo/gates/gates.py index 128518a89e..c0879b10d2 100644 --- a/src/qibo/gates/gates.py +++ b/src/qibo/gates/gates.py @@ -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 @@ -1538,7 +1538,7 @@ def _dagger(self) -> "Gate": class SiSWAPDG(Gate): - """The :math:`\\sqrt{\\text{iSWAP}}}^{\\dagger}` gate. + """The :math:`\\left(\\sqrt{\\text{iSWAP}}\\right)^{\\dagger}` gate. Corresponds to the following unitary matrix