Skip to content

Commit

Permalink
Merge pull request #183 from qiboteam/grbs
Browse files Browse the repository at this point in the history
Add `gates.GeneralizedRBS` gate
  • Loading branch information
scarrazza authored Aug 14, 2024
2 parents eb74454 + 0f92865 commit 0d9bbd2
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/qibojit/backends/cpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,14 +152,21 @@ 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": # pragma: no cover
# 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)
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)
Expand Down

0 comments on commit 0d9bbd2

Please sign in to comment.