Skip to content

Commit

Permalink
parallel->serial
Browse files Browse the repository at this point in the history
  • Loading branch information
gandalfr-KY committed May 20, 2024
1 parent f9c9176 commit f1d4efb
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions scaluq/util/utility.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,26 +48,24 @@ inline std::optional<ComplexMatrix> get_pauli_matrix(PauliOperator pauli) {
[&](UINT i, UINT& f_mask, UINT& p_mask, UINT& rot90_cnt) {
UINT pauli_id = pauli_id_list[i];
if (pauli_id == 1) {
f_mask ^= 1ULL << i;
f_mask += 1ULL << i;
} else if (pauli_id == 2) {
f_mask ^= 1ULL << i;
p_mask ^= 1ULL << i;
f_mask += 1ULL << i;
p_mask += 1ULL << i;
rot90_cnt++;
} else if (pauli_id == 3) {
p_mask ^= 1ULL << i;
p_mask += 1ULL << i;
}
},
flip_mask,
phase_mask,
rot90_count);
std::vector<StdComplex> rot = {1, -1.i, -1, 1.i};
UINT matrix_dim = 1ULL << pauli_id_list.size();
Kokkos::parallel_for(Kokkos::RangePolicy<Kokkos::DefaultHostExecutionSpace>(0, matrix_dim),
[&](const UINT index) {
const StdComplex sign =
1. - 2. * (Kokkos::popcount(index & phase_mask) % 2);
mat(index, index ^ flip_mask) = rot[rot90_count % 4] * sign;
});
for (UINT index = 0; index < matrix_dim; index++) {
const StdComplex sign = 1. - 2. * (Kokkos::popcount(index & phase_mask) % 2);
mat(index, index ^ flip_mask) = rot[rot90_count % 4] * sign;
}
return mat;
}

Expand Down

0 comments on commit f1d4efb

Please sign in to comment.