From a58c041d5d8eefc9b40f34d0a598c75adfa1d620 Mon Sep 17 00:00:00 2001 From: Nicolas Renaud Date: Fri, 28 Jun 2024 17:23:28 +0200 Subject: [PATCH] added a threshold to remove pauli strings with near null coefficients --- vqls_prototype/matrix_decomposition/matrix_decomposition.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/vqls_prototype/matrix_decomposition/matrix_decomposition.py b/vqls_prototype/matrix_decomposition/matrix_decomposition.py index b445f9b..c4c6ee7 100644 --- a/vqls_prototype/matrix_decomposition/matrix_decomposition.py +++ b/vqls_prototype/matrix_decomposition/matrix_decomposition.py @@ -376,6 +376,7 @@ def __init__( ] = None, load: Optional[str] = None, sparse: Optional[bool] = False, + threshold: float = 1e-6, ): """Decompose a matrix representing quantum circuits @@ -390,8 +391,10 @@ def __init__( valid only for a circuit with 1 element. Defaults to None. load (Optional[str]): filename to load the decomposition from sparse (optional[bool]): use a sparse decomposition + threshold (optional[float]): elements with coefficients smaller than this value will be ignored """ self.use_sparse = sparse + self.threshold = threshold super().__init__(matrix, circuits, coefficients, load) @staticmethod @@ -464,7 +467,7 @@ def decompose_matrix( coef: complex_array_type = self._get_pauli_coefficient( self.matrix, pauli_string, self.sparse_matrix ) - if coef * np.conj(coef) != 0: + if coef * np.conj(coef) >= self.threshold: self.strings.append(pauli_string) coeffs.append(prefactor * coef) circuits.append(self._create_circuit(pauli_string))