Skip to content

Commit

Permalink
modified the non-commutativity check
Browse files Browse the repository at this point in the history
  • Loading branch information
sacpis committed Aug 16, 2024
1 parent 2101147 commit 64426fd
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 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,15 +85,13 @@ mult(std::vector<bool> row, std::vector<bool> other_row,
other_phase++;
}

// Calculate the phase resulting from the non-commutative operations
int sum = 0;
for (std::size_t i = 0; i < numQubits; i++)
if ((row[i] && other_row[i + numQubits]) ||
(row[i + numQubits] && other_row[i]))
for (auto a : tmp2)
if (a)
sum++;

auto _phase = orig_phase + other_phase + 2 * sum;
// Adjust phase based on non-commutative nature of Pauli matrices
// 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])
_phase -= 1;
Expand Down

0 comments on commit 64426fd

Please sign in to comment.