Skip to content

Commit ef78979

Browse files
authored
Merge pull request #698 from tensorflow/upgrade_qsim
Upgrade qsim version.
2 parents 326eb30 + 7c8ba99 commit ef78979

File tree

4 files changed

+17
-21
lines changed

4 files changed

+17
-21
lines changed

WORKSPACE

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ cc_library(
2626

2727
http_archive(
2828
name = "qsim",
29-
sha256 = "525250bafd37aab9db525d22e7b12689da617a116fe2cdf3f524ee7ea6a0ef45",
30-
strip_prefix = "qsim-0.11.2-dev-20220104",
31-
urls = ["https://github.com/quantumlib/qsim/archive/refs/tags/v0.11.2-dev+20220104.zip"],
29+
sha256 = "b9c1eba09a885a938b5e73dfc2e02f5231cf3b01d899415caa24769346a731d5",
30+
strip_prefix = "qsim-0.13.3",
31+
urls = ["https://github.com/quantumlib/qsim/archive/refs/tags/v0.13.3.zip"],
3232
)
3333

3434
http_archive(

tensorflow_quantum/core/ops/noise/tfq_noisy_expectation.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ class TfqNoisyExpectationOp : public tensorflow::OpKernel {
208208
param.collect_kop_stat = false;
209209
param.collect_mea_stat = false;
210210
param.normalize_before_mea_gates = true;
211-
std::vector<uint64_t> unused_stats;
211+
QTSimulator::Stat unused_stats;
212212
// Track op-wise stats.
213213
std::vector<int> run_samples(num_samples[i].size(), 0);
214214
std::vector<double> rolling_sums(num_samples[i].size(), 0.0);
@@ -217,7 +217,7 @@ class TfqNoisyExpectationOp : public tensorflow::OpKernel {
217217
ss.SetStateZero(sv);
218218

219219
QTSimulator::RunOnce(param, ncircuits[i], rand_source.Rand64(), ss, sim,
220-
scratch, sv, unused_stats);
220+
sv, unused_stats);
221221

222222
// Use this trajectory as a source for all expectation calculations.
223223
for (int j = 0; j < pauli_sums[i].size(); j++) {
@@ -325,7 +325,7 @@ class TfqNoisyExpectationOp : public tensorflow::OpKernel {
325325
param.collect_kop_stat = false;
326326
param.collect_mea_stat = false;
327327
param.normalize_before_mea_gates = true;
328-
std::vector<uint64_t> unused_stats;
328+
QTSimulator::Stat unused_stats;
329329
// Track op-wise stats.
330330
std::vector<int> run_samples(num_samples[i].size(), 0);
331331
std::vector<double> rolling_sums(num_samples[i].size(), 0.0);
@@ -334,7 +334,7 @@ class TfqNoisyExpectationOp : public tensorflow::OpKernel {
334334
ss.SetStateZero(sv);
335335

336336
QTSimulator::RunOnce(param, ncircuits[i], rand_source.Rand64(), ss,
337-
sim, scratch, sv, unused_stats);
337+
sim, sv, unused_stats);
338338

339339
// Compute expectations across all ops using this trajectory.
340340
for (int j = 0; j < pauli_sums[i].size(); j++) {

tensorflow_quantum/core/ops/noise/tfq_noisy_sampled_expectation.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ class TfqNoisySampledExpectationOp : public tensorflow::OpKernel {
212212
param.collect_kop_stat = false;
213213
param.collect_mea_stat = false;
214214
param.normalize_before_mea_gates = true;
215-
std::vector<uint64_t> unused_stats;
215+
QTSimulator::Stat unused_stats;
216216
// Track op-wise stats.
217217
std::vector<int> run_samples(num_samples[i].size(), 0);
218218
std::vector<double> rolling_sums(num_samples[i].size(), 0.0);
@@ -221,7 +221,7 @@ class TfqNoisySampledExpectationOp : public tensorflow::OpKernel {
221221
ss.SetStateZero(sv);
222222

223223
QTSimulator::RunOnce(param, ncircuits[i], rand_source.Rand64(), ss, sim,
224-
scratch, sv, unused_stats);
224+
sv, unused_stats);
225225

226226
// Use this trajectory as a source for all expectation calculations.
227227
for (int j = 0; j < pauli_sums[i].size(); j++) {
@@ -331,7 +331,7 @@ class TfqNoisySampledExpectationOp : public tensorflow::OpKernel {
331331
param.collect_kop_stat = false;
332332
param.collect_mea_stat = false;
333333
param.normalize_before_mea_gates = true;
334-
std::vector<uint64_t> unused_stats;
334+
QTSimulator::Stat unused_stats;
335335
// Track op-wise stats.
336336
std::vector<int> run_samples(num_samples[i].size(), 0);
337337
std::vector<double> rolling_sums(num_samples[i].size(), 0.0);
@@ -340,7 +340,7 @@ class TfqNoisySampledExpectationOp : public tensorflow::OpKernel {
340340
ss.SetStateZero(sv);
341341

342342
QTSimulator::RunOnce(param, ncircuits[i], rand_source.Rand64(), ss,
343-
sim, scratch, sv, unused_stats);
343+
sim, sv, unused_stats);
344344

345345
// Compute expectations across all ops using this trajectory.
346346
for (int j = 0; j < pauli_sums[i].size(); j++) {

tensorflow_quantum/core/ops/noise/tfq_noisy_samples.cc

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,6 @@ class TfqNoisySamplesOp : public tensorflow::OpKernel {
149149
Simulator sim = Simulator(tfq_for);
150150
StateSpace ss = StateSpace(tfq_for);
151151
auto sv = ss.Create(largest_nq);
152-
auto scratch = ss.Create(largest_nq);
153152

154153
tensorflow::GuardedPhiloxRandom random_gen;
155154
random_gen.Init(tensorflow::random::New64(), tensorflow::random::New64());
@@ -167,7 +166,6 @@ class TfqNoisySamplesOp : public tensorflow::OpKernel {
167166
// need to switch to larger statespace.
168167
largest_nq = nq;
169168
sv = ss.Create(largest_nq);
170-
scratch = ss.Create(largest_nq);
171169
}
172170

173171
QTSimulator::Parameter param;
@@ -176,18 +174,18 @@ class TfqNoisySamplesOp : public tensorflow::OpKernel {
176174
param.normalize_before_mea_gates = true;
177175

178176
// Track op-wise stats.
179-
std::vector<uint64_t> gathered_samples;
177+
QTSimulator::Stat gathered_samples;
180178

181179
for (int j = 0; j < num_samples; j++) {
182180
ss.SetStateZero(sv);
183181

184182
QTSimulator::RunOnce(param, ncircuits[i], rand_source.Rand64(), ss, sim,
185-
scratch, sv, gathered_samples);
183+
sv, gathered_samples);
186184
uint64_t q_ind = 0;
187185
uint64_t mask = 1;
188186
bool val = 0;
189187
while (q_ind < nq) {
190-
val = gathered_samples[0] & mask;
188+
val = gathered_samples.samples[0] & mask;
191189
(*output_tensor)(
192190
i, j, static_cast<ptrdiff_t>(max_num_qubits - q_ind - 1)) = val;
193191
q_ind++;
@@ -247,7 +245,6 @@ class TfqNoisySamplesOp : public tensorflow::OpKernel {
247245
Simulator sim = Simulator(tfq_for);
248246
StateSpace ss = StateSpace(tfq_for);
249247
auto sv = ss.Create(largest_nq);
250-
auto scratch = ss.Create(largest_nq);
251248

252249
int needed_random =
253250
4 * (num_samples * ncircuits.size() + num_threads) / num_threads;
@@ -266,27 +263,26 @@ class TfqNoisySamplesOp : public tensorflow::OpKernel {
266263
if (nq > largest_nq) {
267264
largest_nq = nq;
268265
sv = ss.Create(largest_nq);
269-
scratch = ss.Create(largest_nq);
270266
}
271267
QTSimulator::Parameter param;
272268
param.collect_kop_stat = false;
273269
param.collect_mea_stat = true;
274270
param.normalize_before_mea_gates = true;
275271

276272
// Track op-wise stats.
277-
std::vector<uint64_t> gathered_samples;
273+
QTSimulator::Stat gathered_samples;
278274
int run_samples = 0;
279275

280276
while (1) {
281277
ss.SetStateZero(sv);
282278
QTSimulator::RunOnce(param, ncircuits[i], rand_source.Rand64(), ss,
283-
sim, scratch, sv, gathered_samples);
279+
sim, sv, gathered_samples);
284280

285281
uint64_t q_ind = 0;
286282
uint64_t mask = 1;
287283
bool val = 0;
288284
while (q_ind < nq) {
289-
val = gathered_samples[0] & mask;
285+
val = gathered_samples.samples[0] & mask;
290286
(*output_tensor)(
291287
i, j, static_cast<ptrdiff_t>(max_num_qubits - q_ind - 1)) = val;
292288
q_ind++;

0 commit comments

Comments
 (0)