Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add gates.GeneralizedRBS gate #183

Merged
merged 4 commits into from
Aug 14, 2024
Merged
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
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