From 532d5735fb19905d5e38b1d7f302d76049096eab Mon Sep 17 00:00:00 2001 From: Marco Lazzarin <48728634+mlazzarin@users.noreply.github.com> Date: Sat, 6 Nov 2021 12:17:17 +0400 Subject: [PATCH 1/2] Fix dtype of CZ matrix --- src/qibo/backends/matrices.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qibo/backends/matrices.py b/src/qibo/backends/matrices.py index a21b7beeca..4e973c4b91 100644 --- a/src/qibo/backends/matrices.py +++ b/src/qibo/backends/matrices.py @@ -92,7 +92,7 @@ def _setCNOT(self): self._CNOT = self.backend.cast(m) def _setCZ(self): - m = np.diag([1, 1, 1, -1]) + m = np.diag([1, 1, 1, -1], dtype=self.dtype) self._CZ = self.backend.cast(m) def _setSWAP(self): From 4bb223742ddcabcd2ddb603f21dae8af7f23c99d Mon Sep 17 00:00:00 2001 From: Marco Lazzarin <48728634+mlazzarin@users.noreply.github.com> Date: Sat, 6 Nov 2021 12:22:48 +0400 Subject: [PATCH 2/2] Fix previous commit --- src/qibo/backends/matrices.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/qibo/backends/matrices.py b/src/qibo/backends/matrices.py index 4e973c4b91..52e6b13638 100644 --- a/src/qibo/backends/matrices.py +++ b/src/qibo/backends/matrices.py @@ -92,7 +92,8 @@ def _setCNOT(self): self._CNOT = self.backend.cast(m) def _setCZ(self): - m = np.diag([1, 1, 1, -1], dtype=self.dtype) + m = np.eye(4, dtype=self.dtype) + m[3, 3] = -1 self._CZ = self.backend.cast(m) def _setSWAP(self):