From ab63efc7ef280c586dbed008c2243ddf31589198 Mon Sep 17 00:00:00 2001 From: Renato Mello Date: Wed, 18 Sep 2024 13:17:22 +0400 Subject: [PATCH] add method --- src/qibojit/backends/gpu.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/qibojit/backends/gpu.py b/src/qibojit/backends/gpu.py index 5ae4ecb..3cd3676 100644 --- a/src/qibojit/backends/gpu.py +++ b/src/qibojit/backends/gpu.py @@ -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 @@ -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 @@ -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