From c20ab81793266f3e4188d21dbb693c793667c1eb Mon Sep 17 00:00:00 2001 From: Sachin Pisal Date: Fri, 8 Nov 2024 11:37:20 -0800 Subject: [PATCH] * Ignore terms with 0 coefficients Signed-off-by: Sachin Pisal --- runtime/cudaq/spin/spin_op.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/runtime/cudaq/spin/spin_op.cpp b/runtime/cudaq/spin/spin_op.cpp index a898efd0f1..2289d4f2be 100644 --- a/runtime/cudaq/spin/spin_op.cpp +++ b/runtime/cudaq/spin/spin_op.cpp @@ -414,9 +414,11 @@ spin_op &spin_op::operator+=(const spin_op &v) noexcept { for (auto [term, coeff] : tmpv.terms) { auto iter = terms.find(term); - if (iter != terms.end()) + if (iter != terms.end()) { iter->second += coeff; - else + if (std::abs(iter->second) < 1e-12) + terms.erase(iter); + } else terms.emplace(term, coeff); }