Skip to content

Commit

Permalink
add method
Browse files Browse the repository at this point in the history
  • Loading branch information
renatomello committed Sep 18, 2024
1 parent 0d9bbd2 commit ab63efc
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/qibojit/backends/gpu.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
from typing import Union

import numpy as np

from qibo.backends.numpy import NumpyBackend
from qibo.config import log, raise_error

Expand Down Expand Up @@ -503,7 +506,7 @@ def calculate_matrix_exp(self, a, matrix, eigenvectors=None, eigenvalues=None):
if self.is_sparse(matrix):
from scipy.sparse.linalg import expm

return self.cast(expm(-1j * a * matrix.get()))
return self.cast(expm(-1j * a * self.to_numpy(matrix)))
else:
from cupyx.scipy.linalg import expm # pylint: disable=import-error

Expand All @@ -513,6 +516,15 @@ def calculate_matrix_exp(self, a, matrix, eigenvectors=None, eigenvalues=None):
ud = self.cp.transpose(self.cp.conj(eigenvectors))
return self.cp.matmul(eigenvectors, self.cp.matmul(expd, ud))

def calculate_matrix_power(self, matrix, power: Union[float, int]):
if isinstance(power, int):
return self.cp.linalg.matrix_power(matrix, power)

copied = self.to_numpy(matrix)
copied = super().calculate_matrix_power(copied, power)

return self.cast(copied, dtype=copied.dtype)


class CuQuantumBackend(CupyBackend): # pragma: no cover
# CI does not test for GPU
Expand Down

0 comments on commit ab63efc

Please sign in to comment.