diff --git a/qadence/backends/pyqtorch/convert_ops.py b/qadence/backends/pyqtorch/convert_ops.py index e1fa40229..11c672914 100644 --- a/qadence/backends/pyqtorch/convert_ops.py +++ b/qadence/backends/pyqtorch/convert_ops.py @@ -201,7 +201,12 @@ def __init__( elif isinstance(block.generator, Tensor): m = block.generator.to(dtype=cdouble) hmat = block_to_tensor( - MatrixBlock(m, qubit_support=block.qubit_support), + MatrixBlock( + m, + qubit_support=block.qubit_support, + check_unitary=False, + check_hermitian=True, + ), qubit_support=self.qubit_support, use_full_support=False, ) diff --git a/qadence/blocks/matrix.py b/qadence/blocks/matrix.py index d8b91684a..e66a2650a 100644 --- a/qadence/blocks/matrix.py +++ b/qadence/blocks/matrix.py @@ -60,7 +60,13 @@ class MatrixBlock(PrimitiveBlock): name = "MatrixBlock" matrix: torch.Tensor - def __init__(self, matrix: torch.Tensor | np.ndarray, qubit_support: tuple[int, ...]) -> None: + def __init__( + self, + matrix: torch.Tensor | np.ndarray, + qubit_support: tuple[int, ...], + check_unitary: bool = True, + check_hermitian: bool = False, + ) -> None: if isinstance(matrix, np.ndarray): matrix = torch.tensor(matrix) if matrix.ndim == 3 and matrix.size(0) == 1: @@ -69,10 +75,12 @@ def __init__(self, matrix: torch.Tensor | np.ndarray, qubit_support: tuple[int, raise TypeError("Please provide a 2D matrix.") if not self.is_square(matrix): raise TypeError("Please provide a square matrix.") - if not self.is_hermitian(matrix): - logger.warning("Provided matrix is not hermitian.") - if not self.is_unitary(matrix): - logger.warning("Provided matrix is not unitary.") + if check_unitary: + if not self.is_hermitian(matrix): + logger.warning("Provided matrix is not hermitian.") + if check_hermitian: + if not self.is_unitary(matrix): + logger.warning("Provided matrix is not unitary.") self.matrix = matrix.clone() super().__init__(qubit_support)