Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix warnings and errors for TF/absl/C++ changes #775

Closed
wants to merge 1 commit into from
Closed
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
12 changes: 6 additions & 6 deletions tensorflow_quantum/core/ops/math_ops/tfq_inner_product.cc
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ class TfqInnerProductOp : public tensorflow::OpKernel {
// Simulate programs one by one. Parallelizing over state vectors
// we no longer parallelize over circuits. Each time we encounter a
// a larger circuit we will grow the Statevector as necessary.
for (int i = 0; i < fused_circuits.size(); i++) {
for (size_t i = 0; i < fused_circuits.size(); i++) {
int nq = num_qubits[i];
if (nq > largest_nq) {
// need to switch to larger statespace.
Expand All @@ -186,18 +186,18 @@ class TfqInnerProductOp : public tensorflow::OpKernel {
// the state if there is a possibility that circuit[i] and
// circuit[i + 1] produce the same state.
ss.SetStateZero(sv);
for (int j = 0; j < fused_circuits[i].size(); j++) {
for (size_t j = 0; j < fused_circuits[i].size(); j++) {
qsim::ApplyFusedGate(sim, fused_circuits[i][j], sv);
}
for (int j = 0; j < other_fused_circuits[i].size(); j++) {
for (size_t j = 0; j < other_fused_circuits[i].size(); j++) {
// (#679) Just ignore empty program
if (fused_circuits[i].size() == 0) {
(*output_tensor)(i, j) = std::complex<float>(1, 0);
continue;
}

ss.SetStateZero(scratch);
for (int k = 0; k < other_fused_circuits[i][j].size(); k++) {
for (size_t k = 0; k < other_fused_circuits[i][j].size(); k++) {
qsim::ApplyFusedGate(sim, other_fused_circuits[i][j][k], scratch);
}

Expand Down Expand Up @@ -255,13 +255,13 @@ class TfqInnerProductOp : public tensorflow::OpKernel {
// no need to update scratch_state since ComputeExpectation
// will take care of things for us.
ss.SetStateZero(sv);
for (int j = 0; j < fused_circuits[cur_batch_index].size(); j++) {
for (size_t j = 0; j < fused_circuits[cur_batch_index].size(); j++) {
qsim::ApplyFusedGate(sim, fused_circuits[cur_batch_index][j], sv);
}
}

ss.SetStateZero(scratch);
for (int k = 0;
for (size_t k = 0;
k <
other_fused_circuits[cur_batch_index][cur_internal_index].size();
k++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -398,13 +398,13 @@ class TfqInnerProductGradOp : public tensorflow::OpKernel {
// if applicable compute control qubit mask and control value bits.
uint64_t mask = 0;
uint64_t cbits = 0;
for (int k = 0; k < cur_gate.controlled_by.size(); k++) {
for (size_t k = 0; k < cur_gate.controlled_by.size(); k++) {
uint64_t control_loc = cur_gate.controlled_by[k];
mask |= uint64_t{1} << control_loc;
cbits |= ((cur_gate.cmask >> k) & 1) << control_loc;
}

for (int k = 0;
for (size_t k = 0;
k < gradient_gates[cur_batch_index][l - 1].grad_gates.size();
k++) {
// Copy sv_adj onto scratch2 in anticipation of non-unitary
Expand Down
28 changes: 14 additions & 14 deletions tensorflow_quantum/core/ops/noise/tfq_noisy_expectation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,8 @@ class TfqNoisyExpectationOp : public tensorflow::OpKernel {

tensorflow::GuardedPhiloxRandom random_gen;
int max_n_shots = 1;
for (int i = 0; i < num_samples.size(); i++) {
for (int j = 0; j < num_samples[i].size(); j++) {
for (size_t i = 0; i < num_samples.size(); i++) {
for (size_t j = 0; j < num_samples[i].size(); j++) {
max_n_shots = std::max(max_n_shots, num_samples[i][j]);
}
}
Expand All @@ -188,12 +188,12 @@ class TfqNoisyExpectationOp : public tensorflow::OpKernel {
// Simulate programs one by one. Parallelizing over state vectors
// we no longer parallelize over circuits. Each time we encounter a
// a larger circuit we will grow the Statevector as necessary.
for (int i = 0; i < ncircuits.size(); i++) {
for (size_t i = 0; i < ncircuits.size(); i++) {
int nq = num_qubits[i];

// (#679) Just ignore empty program
if (ncircuits[i].channels.size() == 0) {
for (int j = 0; j < pauli_sums[i].size(); j++) {
for (size_t j = 0; j < pauli_sums[i].size(); j++) {
(*output_tensor)(i, j) = -2.0;
}
continue;
Expand All @@ -220,7 +220,7 @@ class TfqNoisyExpectationOp : public tensorflow::OpKernel {
sv, unused_stats);

// Use this trajectory as a source for all expectation calculations.
for (int j = 0; j < pauli_sums[i].size(); j++) {
for (size_t j = 0; j < pauli_sums[i].size(); j++) {
if (run_samples[j] >= num_samples[i][j]) {
continue;
}
Expand All @@ -232,14 +232,14 @@ class TfqNoisyExpectationOp : public tensorflow::OpKernel {
run_samples[j]++;
}
bool break_loop = true;
for (int j = 0; j < num_samples[i].size(); j++) {
for (size_t j = 0; j < num_samples[i].size(); j++) {
if (run_samples[j] < num_samples[i][j]) {
break_loop = false;
break;
}
}
if (break_loop) {
for (int j = 0; j < num_samples[i].size(); j++) {
for (size_t j = 0; j < num_samples[i].size(); j++) {
rolling_sums[j] /= num_samples[i][j];
(*output_tensor)(i, j) = static_cast<float>(rolling_sums[j]);
}
Expand Down Expand Up @@ -280,8 +280,8 @@ class TfqNoisyExpectationOp : public tensorflow::OpKernel {

tensorflow::GuardedPhiloxRandom random_gen;
int max_n_shots = 1;
for (int i = 0; i < num_samples.size(); i++) {
for (int j = 0; j < num_samples[i].size(); j++) {
for (size_t i = 0; i < num_samples.size(); i++) {
for (size_t j = 0; j < num_samples[i].size(); j++) {
max_n_shots = std::max(max_n_shots, num_samples[i][j]);
}
}
Expand All @@ -304,13 +304,13 @@ class TfqNoisyExpectationOp : public tensorflow::OpKernel {
random_gen.ReserveSamples128(ncircuits.size() * max_n_shots + 1);
tensorflow::random::SimplePhilox rand_source(&local_gen);

for (int i = 0; i < ncircuits.size(); i++) {
for (size_t i = 0; i < ncircuits.size(); i++) {
int nq = num_qubits[i];
int rep_offset = rep_offsets[start][i];

// (#679) Just ignore empty program
if (ncircuits[i].channels.size() == 0) {
for (int j = 0; j < pauli_sums[i].size(); j++) {
for (size_t j = 0; j < pauli_sums[i].size(); j++) {
(*output_tensor)(i, j) = -2.0;
}
continue;
Expand All @@ -337,7 +337,7 @@ class TfqNoisyExpectationOp : public tensorflow::OpKernel {
sim, sv, unused_stats);

// Compute expectations across all ops using this trajectory.
for (int j = 0; j < pauli_sums[i].size(); j++) {
for (size_t j = 0; j < pauli_sums[i].size(); j++) {
int p_reps = (num_samples[i][j] + num_threads - 1) / num_threads;
if (run_samples[j] >= p_reps + rep_offset) {
continue;
Expand All @@ -354,7 +354,7 @@ class TfqNoisyExpectationOp : public tensorflow::OpKernel {

// Check if we have run enough trajectories for all ops.
bool break_loop = true;
for (int j = 0; j < num_samples[i].size(); j++) {
for (size_t j = 0; j < num_samples[i].size(); j++) {
int p_reps = (num_samples[i][j] + num_threads - 1) / num_threads;
if (run_samples[j] < p_reps + rep_offset) {
break_loop = false;
Expand All @@ -364,7 +364,7 @@ class TfqNoisyExpectationOp : public tensorflow::OpKernel {
if (break_loop) {
// Lock writing to this batch index in output_tensor.
batch_locks[i].lock();
for (int j = 0; j < num_samples[i].size(); j++) {
for (size_t j = 0; j < num_samples[i].size(); j++) {
rolling_sums[j] /= num_samples[i][j];
(*output_tensor)(i, j) += static_cast<float>(rolling_sums[j]);
}
Expand Down
28 changes: 14 additions & 14 deletions tensorflow_quantum/core/ops/noise/tfq_noisy_sampled_expectation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,8 @@ class TfqNoisySampledExpectationOp : public tensorflow::OpKernel {
tensorflow::GuardedPhiloxRandom random_gen;
int max_psum_length = 1;
int max_n_shots = 1;
for (int i = 0; i < pauli_sums.size(); i++) {
for (int j = 0; j < pauli_sums[i].size(); j++) {
for (size_t i = 0; i < pauli_sums.size(); i++) {
for (size_t j = 0; j < pauli_sums[i].size(); j++) {
max_psum_length =
std::max(max_psum_length, pauli_sums[i][j].terms().size());
max_n_shots = std::max(max_n_shots, num_samples[i][j]);
Expand All @@ -192,12 +192,12 @@ class TfqNoisySampledExpectationOp : public tensorflow::OpKernel {
// Simulate programs one by one. Parallelizing over state vectors
// we no longer parallelize over circuits. Each time we encounter a
// a larger circuit we will grow the Statevector as necessary.
for (int i = 0; i < ncircuits.size(); i++) {
for (size_t i = 0; i < ncircuits.size(); i++) {
int nq = num_qubits[i];

// (#679) Just ignore empty program
if (ncircuits[i].channels.empty()) {
for (int j = 0; j < pauli_sums[i].size(); j++) {
for (size_t j = 0; j < pauli_sums[i].size(); j++) {
(*output_tensor)(i, j) = -2.0;
}
continue;
Expand All @@ -224,7 +224,7 @@ class TfqNoisySampledExpectationOp : public tensorflow::OpKernel {
sv, unused_stats);

// Use this trajectory as a source for all expectation calculations.
for (int j = 0; j < pauli_sums[i].size(); j++) {
for (size_t j = 0; j < pauli_sums[i].size(); j++) {
if (run_samples[j] >= num_samples[i][j]) {
continue;
}
Expand All @@ -236,14 +236,14 @@ class TfqNoisySampledExpectationOp : public tensorflow::OpKernel {
run_samples[j]++;
}
bool break_loop = true;
for (int j = 0; j < num_samples[i].size(); j++) {
for (size_t j = 0; j < num_samples[i].size(); j++) {
if (run_samples[j] < num_samples[i][j]) {
break_loop = false;
break;
}
}
if (break_loop) {
for (int j = 0; j < num_samples[i].size(); j++) {
for (size_t j = 0; j < num_samples[i].size(); j++) {
rolling_sums[j] /= num_samples[i][j];
(*output_tensor)(i, j) = static_cast<float>(rolling_sums[j]);
}
Expand Down Expand Up @@ -285,8 +285,8 @@ class TfqNoisySampledExpectationOp : public tensorflow::OpKernel {
tensorflow::GuardedPhiloxRandom random_gen;
int max_psum_length = 1;
int max_n_shots = 1;
for (int i = 0; i < pauli_sums.size(); i++) {
for (int j = 0; j < pauli_sums[i].size(); j++) {
for (size_t i = 0; i < pauli_sums.size(); i++) {
for (size_t j = 0; j < pauli_sums[i].size(); j++) {
max_psum_length =
std::max(max_psum_length, pauli_sums[i][j].terms().size());
max_n_shots = std::max(max_n_shots, num_samples[i][j]);
Expand All @@ -310,13 +310,13 @@ class TfqNoisySampledExpectationOp : public tensorflow::OpKernel {
auto local_gen = random_gen.ReserveSamples128(num_rand);
tensorflow::random::SimplePhilox rand_source(&local_gen);

for (int i = 0; i < ncircuits.size(); i++) {
for (size_t i = 0; i < ncircuits.size(); i++) {
int nq = num_qubits[i];
int rep_offset = rep_offsets[start][i];

// (#679) Just ignore empty program
if (ncircuits[i].channels.empty()) {
for (int j = 0; j < pauli_sums[i].size(); j++) {
for (size_t j = 0; j < pauli_sums[i].size(); j++) {
(*output_tensor)(i, j) = -2.0;
}
continue;
Expand All @@ -343,7 +343,7 @@ class TfqNoisySampledExpectationOp : public tensorflow::OpKernel {
sim, sv, unused_stats);

// Compute expectations across all ops using this trajectory.
for (int j = 0; j < pauli_sums[i].size(); j++) {
for (size_t j = 0; j < pauli_sums[i].size(); j++) {
int p_reps = (num_samples[i][j] + num_threads - 1) / num_threads;
if (run_samples[j] >= p_reps + rep_offset) {
continue;
Expand All @@ -360,7 +360,7 @@ class TfqNoisySampledExpectationOp : public tensorflow::OpKernel {

// Check if we have run enough trajectories for all ops.
bool break_loop = true;
for (int j = 0; j < num_samples[i].size(); j++) {
for (size_t j = 0; j < num_samples[i].size(); j++) {
int p_reps = (num_samples[i][j] + num_threads - 1) / num_threads;
if (run_samples[j] < p_reps + rep_offset) {
break_loop = false;
Expand All @@ -370,7 +370,7 @@ class TfqNoisySampledExpectationOp : public tensorflow::OpKernel {
if (break_loop) {
// Lock writing to this batch index in output_tensor.
batch_locks[i].lock();
for (int j = 0; j < num_samples[i].size(); j++) {
for (size_t j = 0; j < num_samples[i].size(); j++) {
rolling_sums[j] /= num_samples[i][j];
(*output_tensor)(i, j) += static_cast<float>(rolling_sums[j]);
}
Expand Down
4 changes: 2 additions & 2 deletions tensorflow_quantum/core/ops/noise/tfq_noisy_samples.cc
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ class TfqNoisySamplesOp : public tensorflow::OpKernel {
// Simulate programs one by one. Parallelizing over state vectors
// we no longer parallelize over circuits. Each time we encounter a
// a larger circuit we will grow the Statevector as nescessary.
for (int i = 0; i < ncircuits.size(); i++) {
for (size_t i = 0; i < ncircuits.size(); i++) {
int nq = num_qubits[i];

if (nq > largest_nq) {
Expand Down Expand Up @@ -252,7 +252,7 @@ class TfqNoisySamplesOp : public tensorflow::OpKernel {
auto local_gen = random_gen.ReserveSamples32(needed_random);
tensorflow::random::SimplePhilox rand_source(&local_gen);

for (int i = 0; i < ncircuits.size(); i++) {
for (size_t i = 0; i < ncircuits.size(); i++) {
int nq = num_qubits[i];
int j = start > 0 ? offset_prefix_sum[start - 1][i] : 0;
int needed_samples = offset_prefix_sum[start][i] - j;
Expand Down
Loading