Skip to content

Commit

Permalink
change phase calculation and adjusted _phase to relect the result of …
Browse files Browse the repository at this point in the history
…non-commutative multiplications
  • Loading branch information
sacpis committed Aug 16, 2024
1 parent 78f0715 commit 2101147
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions runtime/cudaq/spin/spin_op.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,15 @@ mult(std::vector<bool> row, std::vector<bool> other_row,
other_phase++;
}

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

_phase += 2 * sum;
// Based on the phase, figure out an extra coeff to apply
auto _phase = orig_phase + other_phase + 2 * sum;
// Adjust phase based on non-commutative nature of Pauli matrices
for (std::size_t i = 0; i < numQubits; i++)
if (tmp[i] && tmp[i + numQubits])
_phase -= 1;
Expand Down

0 comments on commit 2101147

Please sign in to comment.