From 2b08f3f3000f70f9d02ea6fc13ddc28fec4b7b72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20P=2E=20Moutinho?= <56390829+jpmoutinho@users.noreply.github.com> Date: Thu, 18 Jul 2024 15:52:19 +0200 Subject: [PATCH] toggle warnings --- qadence/backends/pyqtorch/convert_ops.py | 7 ++++++- qadence/blocks/matrix.py | 18 +++++++++++++----- 2 files changed, 19 insertions(+), 6 deletions(-) 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)