From 479c2239d83b334f224e8b2611ddf884c41e0811 Mon Sep 17 00:00:00 2001 From: Sachin Pisal Date: Mon, 19 Aug 2024 16:41:20 -0700 Subject: [PATCH] Fix for non-commutativity check in spin_op multiplication (#2097) * change phase calculation and adjusted _phase to relect the result of non-commutative multiplications * modified the non-commutativity check --- runtime/cudaq/spin/spin_op.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/runtime/cudaq/spin/spin_op.cpp b/runtime/cudaq/spin/spin_op.cpp index e73ae70796..f1acaf1d70 100644 --- a/runtime/cudaq/spin/spin_op.cpp +++ b/runtime/cudaq/spin/spin_op.cpp @@ -73,7 +73,8 @@ mult(std::vector row, std::vector other_row, tmp[i] = row[i] ^ other_row[i]; for (std::size_t i = 0; i < numQubits; i++) - tmp2[i] = row[i] && other_row[numQubits + i]; + tmp2[i] = (row[i] && other_row[numQubits + i]) || + (row[i + numQubits] && other_row[i]); int orig_phase = 0, other_phase = 0; for (std::size_t i = 0; i < numQubits; i++) { @@ -84,13 +85,12 @@ mult(std::vector row, std::vector other_row, other_phase++; } - auto _phase = orig_phase + other_phase; int sum = 0; for (auto a : tmp2) if (a) sum++; - _phase += 2 * sum; + auto _phase = orig_phase + other_phase + 2 * sum; // Based on the phase, figure out an extra coeff to apply for (std::size_t i = 0; i < numQubits; i++) if (tmp[i] && tmp[i + numQubits])