Skip to content

Commit

Permalink
Fix for non-commutativity check in spin_op multiplication (#2097)
Browse files Browse the repository at this point in the history
* change phase calculation and adjusted _phase to relect the result of non-commutative multiplications

* modified the non-commutativity check
  • Loading branch information
sacpis authored Aug 19, 2024
1 parent 37474b2 commit 479c223
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions runtime/cudaq/spin/spin_op.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ mult(std::vector<bool> row, std::vector<bool> 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++) {
Expand All @@ -84,13 +85,12 @@ mult(std::vector<bool> row, std::vector<bool> 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])
Expand Down

0 comments on commit 479c223

Please sign in to comment.