From dd789306d6db8b2cebf0705fe9386b2e39e5dc76 Mon Sep 17 00:00:00 2001 From: Renato Mello Date: Wed, 26 Jun 2024 15:29:21 +0400 Subject: [PATCH 1/3] add "GeneralizedRBS" gate --- src/qibojit/backends/cpu.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/qibojit/backends/cpu.py b/src/qibojit/backends/cpu.py index 4ae8deaf..c03c9b53 100644 --- a/src/qibojit/backends/cpu.py +++ b/src/qibojit/backends/cpu.py @@ -152,14 +152,20 @@ def _create_qubits_tensor(gate, nqubits): def _as_custom_matrix(self, gate): name = gate.__class__.__name__ + _matrix = getattr(self.custom_matrices, name) + if isinstance(gate, ParametrizedGate): - return getattr(self.custom_matrices, name)(*gate.parameters) - elif isinstance(gate, FusedGate): # pragma: no cover + if name == "GeneralizedRBS": + theta = gate.init_kwargs["theta"] + phi = gate.init_kwargs["phi"] + return _matrix(gate.init_args[0], gate.init_args[1], theta, phi) + return _matrix(*gate.parameters) + + if isinstance(gate, FusedGate): # pragma: no cover # fusion is tested in qibo tests return self.matrix_fused(gate) - else: - matrix = getattr(self.custom_matrices, name) - return matrix(2 ** len(gate.target_qubits)) if callable(matrix) else matrix + + return _matrix(2 ** len(gate.target_qubits)) if callable(_matrix) else _matrix def apply_gate(self, gate, state, nqubits): matrix = self._as_custom_matrix(gate) From db0bf468dbe1e8bf95eda400fe3bf51bfc0bdeb3 Mon Sep 17 00:00:00 2001 From: Renato Mello Date: Wed, 26 Jun 2024 15:34:27 +0400 Subject: [PATCH 2/3] coverage --- src/qibojit/backends/cpu.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/qibojit/backends/cpu.py b/src/qibojit/backends/cpu.py index c03c9b53..ae0fd0d5 100644 --- a/src/qibojit/backends/cpu.py +++ b/src/qibojit/backends/cpu.py @@ -155,7 +155,8 @@ def _as_custom_matrix(self, gate): _matrix = getattr(self.custom_matrices, name) if isinstance(gate, ParametrizedGate): - if name == "GeneralizedRBS": + if name == "GeneralizedRBS": # pragma: no cover + # this is tests in qibo tests theta = gate.init_kwargs["theta"] phi = gate.init_kwargs["phi"] return _matrix(gate.init_args[0], gate.init_args[1], theta, phi) From 0f92865ee884b93b8d0a7e0a56a471d83cce96ba Mon Sep 17 00:00:00 2001 From: Renato Mello Date: Wed, 14 Aug 2024 09:10:14 +0000 Subject: [PATCH 3/3] Update src/qibojit/backends/cpu.py Co-authored-by: Matteo Robbiati <62071516+MatteoRobbiati@users.noreply.github.com> --- src/qibojit/backends/cpu.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qibojit/backends/cpu.py b/src/qibojit/backends/cpu.py index ae0fd0d5..ce823ba3 100644 --- a/src/qibojit/backends/cpu.py +++ b/src/qibojit/backends/cpu.py @@ -156,7 +156,7 @@ def _as_custom_matrix(self, gate): if isinstance(gate, ParametrizedGate): if name == "GeneralizedRBS": # pragma: no cover - # this is tests in qibo tests + # this is tested in qibo tests theta = gate.init_kwargs["theta"] phi = gate.init_kwargs["phi"] return _matrix(gate.init_args[0], gate.init_args[1], theta, phi)