Skip to content

Commit

Permalink
added a threshold to remove pauli strings with near null coefficients
Browse files Browse the repository at this point in the history
  • Loading branch information
NicoRenaud committed Jun 28, 2024
1 parent 2b8b012 commit a58c041
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion vqls_prototype/matrix_decomposition/matrix_decomposition.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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))
Expand Down

0 comments on commit a58c041

Please sign in to comment.