Skip to content

Commit 1394ae4

Browse files
Upgrade qsim version.
1 parent 326eb30 commit 1394ae4

File tree

4 files changed

+20
-21
lines changed

4 files changed

+20
-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: 9 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,27 +166,29 @@ 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;
174172
param.collect_kop_stat = false;
175173
param.collect_mea_stat = true;
176174
param.normalize_before_mea_gates = true;
177175

176+
177+
178178
// Track op-wise stats.
179-
std::vector<uint64_t> gathered_samples;
179+
QTSimulator::Stat gathered_samples;
180+
//std::vector<uint64_t> gathered_samples;
180181

181182
for (int j = 0; j < num_samples; j++) {
182183
ss.SetStateZero(sv);
183184

184185
QTSimulator::RunOnce(param, ncircuits[i], rand_source.Rand64(), ss, sim,
185-
scratch, sv, gathered_samples);
186+
sv, gathered_samples);
186187
uint64_t q_ind = 0;
187188
uint64_t mask = 1;
188189
bool val = 0;
189190
while (q_ind < nq) {
190-
val = gathered_samples[0] & mask;
191+
val = gathered_samples.samples[0] & mask;
191192
(*output_tensor)(
192193
i, j, static_cast<ptrdiff_t>(max_num_qubits - q_ind - 1)) = val;
193194
q_ind++;
@@ -247,7 +248,6 @@ class TfqNoisySamplesOp : public tensorflow::OpKernel {
247248
Simulator sim = Simulator(tfq_for);
248249
StateSpace ss = StateSpace(tfq_for);
249250
auto sv = ss.Create(largest_nq);
250-
auto scratch = ss.Create(largest_nq);
251251

252252
int needed_random =
253253
4 * (num_samples * ncircuits.size() + num_threads) / num_threads;
@@ -266,27 +266,26 @@ class TfqNoisySamplesOp : public tensorflow::OpKernel {
266266
if (nq > largest_nq) {
267267
largest_nq = nq;
268268
sv = ss.Create(largest_nq);
269-
scratch = ss.Create(largest_nq);
270269
}
271270
QTSimulator::Parameter param;
272271
param.collect_kop_stat = false;
273272
param.collect_mea_stat = true;
274273
param.normalize_before_mea_gates = true;
275274

276275
// Track op-wise stats.
277-
std::vector<uint64_t> gathered_samples;
276+
QTSimulator::Stat gathered_samples;
278277
int run_samples = 0;
279278

280279
while (1) {
281280
ss.SetStateZero(sv);
282281
QTSimulator::RunOnce(param, ncircuits[i], rand_source.Rand64(), ss,
283-
sim, scratch, sv, gathered_samples);
282+
sim, sv, gathered_samples);
284283

285284
uint64_t q_ind = 0;
286285
uint64_t mask = 1;
287286
bool val = 0;
288287
while (q_ind < nq) {
289-
val = gathered_samples[0] & mask;
288+
val = gathered_samples.samples[0] & mask;
290289
(*output_tensor)(
291290
i, j, static_cast<ptrdiff_t>(max_num_qubits - q_ind - 1)) = val;
292291
q_ind++;

0 commit comments

Comments
 (0)