Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/simulators/density_matrix/densitymatrix.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -478,8 +478,8 @@ DensityMatrix<data_t>::expval_pauli(const reg_t &qubits,
auto phase = std::complex<data_t>(initial_phase);
QV::add_y_phase(num_y, phase);

const uint_t mask_u = ~MASKS[x_max + 1];
const uint_t mask_l = MASKS[x_max];
uint_t mask_u = ~MASKS[x_max + 1];
uint_t mask_l = MASKS[x_max];
auto lambda = [&](const int_t i, double &val_re, double &val_im) -> void {
Comment on lines -481 to 483
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to see what happens if these three lines look like

  const uint_t mask_u = ~MASKS[x_max + 1];
  const uint_t mask_l = MASKS[x_max];
  auto lambda = [&, mask_u, mask_l](const int_t i, double &val_re, double &val_im) -> void {

i.e., the only change from the original is to add , mask_u, mask_l to the capture so that those are captured by value instead of reference. And likewise for the other places with the proposed change.

(void)val_im; // unused
auto idx_vec = ((i << 1) & mask_u) | (i & mask_l);
Expand Down
8 changes: 4 additions & 4 deletions src/simulators/statevector/qubitvector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2324,8 +2324,8 @@ double QubitVector<data_t>::expval_pauli(const reg_t &qubits,
return std::real(apply_reduction_lambda(std::move(lambda)));
}

const uint_t mask_u = ~MASKS[x_max + 1];
const uint_t mask_l = MASKS[x_max];
uint_t mask_u = ~MASKS[x_max + 1];
uint_t mask_l = MASKS[x_max];
auto lambda = [&](const int_t i, double &val_re, double &val_im) -> void {
(void)val_im; // unused
int_t idxs[2];
Expand Down Expand Up @@ -2415,8 +2415,8 @@ void QubitVector<data_t>::apply_pauli(const reg_t &qubits,
return;
}

const uint_t mask_u = ~MASKS[x_max + 1];
const uint_t mask_l = MASKS[x_max];
uint_t mask_u = ~MASKS[x_max + 1];
uint_t mask_l = MASKS[x_max];
auto lambda = [&](const int_t i) -> void {
int_t idxs[2];
idxs[0] = ((i << 1) & mask_u) | (i & mask_l);
Expand Down
2 changes: 1 addition & 1 deletion src/simulators/statevector/transformer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ void Transformer<Container, data_t>::apply_diagonal_matrix(
return;
}

const size_t N = qubits.size();
size_t N = qubits.size();
auto func = [&](const areg_t<2> &inds,
Comment on lines -243 to 244
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here would be

  const size_t N = qubits.size();
  auto func = [&, N](const areg_t<2> &inds,

const cvector_t<data_t> &_diag) -> void {
for (int_t i = 0; i < 2; ++i) {
Expand Down