@@ -75,9 +75,9 @@ static void BM_MakeIdent(benchmark::State& state) {
75
75
unsigned short nqubits = state.range (0 );
76
76
auto dd = std::make_unique<dd::Package>();
77
77
auto line = std::array<short , dd::MAXN>{};
78
+ line.fill (-1 );
79
+ line[0 ] = 2 ;
78
80
for (auto _: state) {
79
- line.fill (-1 );
80
- line[0 ] = 2 ;
81
81
benchmark::DoNotOptimize (dd->makeGateDD (dd::Imat, nqubits, line));
82
82
}
83
83
}
@@ -91,9 +91,9 @@ static void BM_MakeSingleQubitGateDD_TargetTop(benchmark::State& state) {
91
91
unsigned short nqubits = state.range (0 );
92
92
auto dd = std::make_unique<dd::Package>();
93
93
auto line = std::array<short , dd::MAXN>{};
94
+ line.fill (-1 );
95
+ line[nqubits - 1 ] = 2 ;
94
96
for (auto _: state) {
95
- line.fill (-1 );
96
- line[nqubits - 1 ] = 2 ;
97
97
benchmark::DoNotOptimize (dd->makeGateDD (dd::Xmat, nqubits, line));
98
98
}
99
99
}
@@ -103,9 +103,9 @@ static void BM_MakeSingleQubitGateDD_TargetMiddle(benchmark::State& state) {
103
103
unsigned short nqubits = state.range (0 );
104
104
auto dd = std::make_unique<dd::Package>();
105
105
auto line = std::array<short , dd::MAXN>{};
106
+ line.fill (-1 );
107
+ line[nqubits / 2 ] = 2 ;
106
108
for (auto _: state) {
107
- line.fill (-1 );
108
- line[nqubits / 2 ] = 2 ;
109
109
benchmark::DoNotOptimize (dd->makeGateDD (dd::Xmat, nqubits, line));
110
110
}
111
111
}
@@ -115,9 +115,9 @@ static void BM_MakeSingleQubitGateDD_TargetBottom(benchmark::State& state) {
115
115
unsigned short nqubits = state.range (0 );
116
116
auto dd = std::make_unique<dd::Package>();
117
117
auto line = std::array<short , dd::MAXN>{};
118
+ line.fill (-1 );
119
+ line[0 ] = 2 ;
118
120
for (auto _: state) {
119
- line.fill (-1 );
120
- line[0 ] = 2 ;
121
121
benchmark::DoNotOptimize (dd->makeGateDD (dd::Xmat, nqubits, line));
122
122
}
123
123
}
@@ -127,10 +127,10 @@ static void BM_MakeControlledQubitGateDD_ControlBottom_TargetTop(benchmark::Stat
127
127
unsigned short nqubits = state.range (0 );
128
128
auto dd = std::make_unique<dd::Package>();
129
129
auto line = std::array<short , dd::MAXN>{};
130
+ line.fill (-1 );
131
+ line[0 ] = 1 ;
132
+ line[nqubits - 1 ] = 2 ;
130
133
for (auto _: state) {
131
- line.fill (-1 );
132
- line[0 ] = 1 ;
133
- line[nqubits - 1 ] = 2 ;
134
134
benchmark::DoNotOptimize (dd->makeGateDD (dd::Xmat, nqubits, line));
135
135
}
136
136
}
@@ -140,10 +140,10 @@ static void BM_MakeControlledQubitGateDD_ControlBottom_TargetMiddle(benchmark::S
140
140
unsigned short nqubits = state.range (0 );
141
141
auto dd = std::make_unique<dd::Package>();
142
142
auto line = std::array<short , dd::MAXN>{};
143
+ line.fill (-1 );
144
+ line[0 ] = 1 ;
145
+ line[nqubits / 2 ] = 2 ;
143
146
for (auto _: state) {
144
- line.fill (-1 );
145
- line[0 ] = 1 ;
146
- line[nqubits / 2 ] = 2 ;
147
147
benchmark::DoNotOptimize (dd->makeGateDD (dd::Xmat, nqubits, line));
148
148
}
149
149
}
@@ -153,10 +153,10 @@ static void BM_MakeControlledQubitGateDD_ControlTop_TargetMiddle(benchmark::Stat
153
153
unsigned short nqubits = state.range (0 );
154
154
auto dd = std::make_unique<dd::Package>();
155
155
auto line = std::array<short , dd::MAXN>{};
156
+ line.fill (-1 );
157
+ line[nqubits - 1 ] = 1 ;
158
+ line[nqubits / 2 ] = 2 ;
156
159
for (auto _: state) {
157
- line.fill (-1 );
158
- line[nqubits - 1 ] = 1 ;
159
- line[nqubits / 2 ] = 2 ;
160
160
benchmark::DoNotOptimize (dd->makeGateDD (dd::Xmat, nqubits, line));
161
161
}
162
162
}
@@ -166,10 +166,10 @@ static void BM_MakeControlledQubitGateDD_ControlTop_TargetBottom(benchmark::Stat
166
166
unsigned short nqubits = state.range (0 );
167
167
auto dd = std::make_unique<dd::Package>();
168
168
auto line = std::array<short , dd::MAXN>{};
169
+ line.fill (-1 );
170
+ line[nqubits - 1 ] = 1 ;
171
+ line[0 ] = 2 ;
169
172
for (auto _: state) {
170
- line.fill (-1 );
171
- line[nqubits - 1 ] = 1 ;
172
- line[0 ] = 2 ;
173
173
benchmark::DoNotOptimize (dd->makeGateDD (dd::Xmat, nqubits, line));
174
174
}
175
175
}
@@ -179,9 +179,9 @@ static void BM_MakeFullControlledToffoliDD_TargetTop(benchmark::State& state) {
179
179
unsigned short nqubits = state.range (0 );
180
180
auto dd = std::make_unique<dd::Package>();
181
181
auto line = std::array<short , dd::MAXN>{};
182
+ line.fill (1 );
183
+ line[nqubits - 1 ] = 2 ;
182
184
for (auto _: state) {
183
- line.fill (1 );
184
- line[nqubits - 1 ] = 2 ;
185
185
benchmark::DoNotOptimize (dd->makeGateDD (dd::Xmat, nqubits, line));
186
186
}
187
187
}
@@ -191,9 +191,9 @@ static void BM_MakeFullControlledToffoliDD_TargetMiddle(benchmark::State& state)
191
191
unsigned short nqubits = state.range (0 );
192
192
auto dd = std::make_unique<dd::Package>();
193
193
auto line = std::array<short , dd::MAXN>{};
194
+ line.fill (1 );
195
+ line[nqubits / 2 ] = 2 ;
194
196
for (auto _: state) {
195
- line.fill (1 );
196
- line[nqubits / 2 ] = 2 ;
197
197
benchmark::DoNotOptimize (dd->makeGateDD (dd::Xmat, nqubits, line));
198
198
}
199
199
}
@@ -203,9 +203,9 @@ static void BM_MakeFullControlledToffoliDD_TargetBottom(benchmark::State& state)
203
203
unsigned short nqubits = state.range (0 );
204
204
auto dd = std::make_unique<dd::Package>();
205
205
auto line = std::array<short , dd::MAXN>{};
206
+ line.fill (1 );
207
+ line[0 ] = 2 ;
206
208
for (auto _: state) {
207
- line.fill (1 );
208
- line[0 ] = 2 ;
209
209
benchmark::DoNotOptimize (dd->makeGateDD (dd::Xmat, nqubits, line));
210
210
}
211
211
}
@@ -238,12 +238,12 @@ static void BM_MxV_X(benchmark::State& state) {
238
238
unsigned short nqubits = state.range (0 );
239
239
auto dd = std::make_unique<dd::Package>();
240
240
auto line = std::array<short , dd::MAXN>{};
241
+ auto zero = dd->makeZeroState (nqubits);
242
+ line.fill (-1 );
243
+ line[0 ] = 2 ;
244
+ auto x = dd->makeGateDD (dd::Xmat, nqubits, line);
241
245
242
246
for (auto _: state) {
243
- auto zero = dd->makeZeroState (nqubits);
244
- line.fill (-1 );
245
- line[0 ] = 2 ;
246
- auto x = dd->makeGateDD (dd::Xmat, nqubits, line);
247
247
auto sim = dd->multiply (x, zero);
248
248
benchmark::DoNotOptimize (sim);
249
249
// clear compute table so the next iteration does not find the result cached
@@ -256,12 +256,12 @@ static void BM_MxV_H(benchmark::State& state) {
256
256
unsigned short nqubits = state.range (0 );
257
257
auto dd = std::make_unique<dd::Package>();
258
258
auto line = std::array<short , dd::MAXN>{};
259
+ auto zero = dd->makeZeroState (nqubits);
260
+ line.fill (-1 );
261
+ line[0 ] = 2 ;
262
+ auto h = dd->makeGateDD (dd::Hmat, nqubits, line);
259
263
260
264
for (auto _: state) {
261
- auto zero = dd->makeZeroState (nqubits);
262
- line.fill (-1 );
263
- line[0 ] = 2 ;
264
- auto h = dd->makeGateDD (dd::Hmat, nqubits, line);
265
265
auto sim = dd->multiply (h, zero);
266
266
benchmark::DoNotOptimize (sim);
267
267
// clear compute table so the next iteration does not find the result cached
@@ -274,12 +274,12 @@ static void BM_MxV_T(benchmark::State& state) {
274
274
unsigned short nqubits = state.range (0 );
275
275
auto dd = std::make_unique<dd::Package>();
276
276
auto line = std::array<short , dd::MAXN>{};
277
+ auto zero = dd->makeZeroState (nqubits);
278
+ line.fill (-1 );
279
+ line[0 ] = 2 ;
280
+ auto t = dd->makeGateDD (dd::Tmat, nqubits, line);
277
281
278
282
for (auto _: state) {
279
- auto zero = dd->makeZeroState (nqubits);
280
- line.fill (-1 );
281
- line[0 ] = 2 ;
282
- auto t = dd->makeGateDD (dd::Tmat, nqubits, line);
283
283
auto sim = dd->multiply (t, zero);
284
284
benchmark::DoNotOptimize (sim);
285
285
// clear compute table so the next iteration does not find the result cached
@@ -294,14 +294,14 @@ static void BM_MxV_CX_ControlTop_TargetBottom(benchmark::State& state) {
294
294
auto line = std::array<short , dd::MAXN>{};
295
295
auto basisStates = std::vector<dd::BasisStates>{nqubits, dd::BasisStates::zero};
296
296
basisStates[nqubits - 1 ] = dd::BasisStates::plus;
297
+ auto plus = dd->makeBasisState (nqubits, basisStates);
298
+ line.fill (-1 );
299
+ line[0 ] = 2 ;
300
+ line[nqubits - 1 ] = 1 ;
301
+ auto cx = dd->makeGateDD (dd::Xmat, nqubits, line);
297
302
298
303
for (auto _: state) {
299
- auto plus = dd->makeBasisState (nqubits, basisStates);
300
- line.fill (-1 );
301
- line[0 ] = 2 ;
302
- line[nqubits - 1 ] = 1 ;
303
- auto cx = dd->makeGateDD (dd::Xmat, nqubits, line);
304
- auto sim = dd->multiply (cx, plus);
304
+ auto sim = dd->multiply (cx, plus);
305
305
benchmark::DoNotOptimize (sim);
306
306
// clear compute table so the next iteration does not find the result cached
307
307
dd->clearComputeTables ();
@@ -315,14 +315,14 @@ static void BM_MxV_CX_ControlBottom_TargetTop(benchmark::State& state) {
315
315
auto line = std::array<short , dd::MAXN>{};
316
316
auto basisStates = std::vector<dd::BasisStates>{nqubits, dd::BasisStates::zero};
317
317
basisStates[0 ] = dd::BasisStates::plus;
318
+ auto plus = dd->makeBasisState (nqubits, basisStates);
319
+ line.fill (-1 );
320
+ line[nqubits - 1 ] = 2 ;
321
+ line[0 ] = 1 ;
322
+ auto cx = dd->makeGateDD (dd::Xmat, nqubits, line);
318
323
319
324
for (auto _: state) {
320
- auto plus = dd->makeBasisState (nqubits, basisStates);
321
- line.fill (-1 );
322
- line[nqubits - 1 ] = 2 ;
323
- line[0 ] = 1 ;
324
- auto cx = dd->makeGateDD (dd::Xmat, nqubits, line);
325
- auto sim = dd->multiply (cx, plus);
325
+ auto sim = dd->multiply (cx, plus);
326
326
benchmark::DoNotOptimize (sim);
327
327
// clear compute table so the next iteration does not find the result cached
328
328
dd->clearComputeTables ();
@@ -335,8 +335,9 @@ static void BM_MxV_HadamardLayer(benchmark::State& state) {
335
335
auto dd = std::make_unique<dd::Package>();
336
336
auto line = std::array<short , dd::MAXN>{};
337
337
338
+ auto zero = dd->makeZeroState (nqubits);
338
339
for (auto _: state) {
339
- auto sv = dd-> makeZeroState (nqubits) ;
340
+ auto sv = zero ;
340
341
line.fill (-1 );
341
342
for (int i = 0 ; i < nqubits; ++i) {
342
343
line[std::max (0 , i - 1 )] = -1 ;
@@ -355,8 +356,9 @@ static void BM_MxV_GHZ(benchmark::State& state) {
355
356
auto dd = std::make_unique<dd::Package>();
356
357
auto line = std::array<short , dd::MAXN>{};
357
358
359
+ auto zero = dd->makeZeroState (nqubits);
358
360
for (auto _: state) {
359
- auto sv = dd-> makeZeroState (nqubits) ;
361
+ auto sv = zero ;
360
362
line.fill (-1 );
361
363
line[nqubits - 1 ] = 2 ;
362
364
auto h = dd->makeGateDD (dd::Hmat, nqubits, line);
@@ -378,15 +380,15 @@ static void BM_MxM_Bell(benchmark::State& state) {
378
380
unsigned short nqubits = state.range (0 );
379
381
auto dd = std::make_unique<dd::Package>();
380
382
auto line = std::array<short , dd::MAXN>{};
383
+ line.fill (-1 );
384
+ line[nqubits - 1 ] = 2 ;
385
+ auto h = dd->makeGateDD (dd::Hmat, nqubits, line);
386
+ line[nqubits - 1 ] = 1 ;
387
+ line[0 ] = 2 ;
388
+ auto cx = dd->makeGateDD (dd::Xmat, nqubits, line);
381
389
382
390
for (auto _: state) {
383
- line.fill (-1 );
384
- line[nqubits - 1 ] = 2 ;
385
- auto h = dd->makeGateDD (dd::Hmat, nqubits, line);
386
- line[nqubits - 1 ] = 1 ;
387
- line[0 ] = 2 ;
388
- auto cx = dd->makeGateDD (dd::Xmat, nqubits, line);
389
- auto bell = dd->multiply (cx, h);
391
+ auto bell = dd->multiply (cx, h);
390
392
benchmark::DoNotOptimize (bell);
391
393
// clear compute table so the next iteration does not find the result cached
392
394
dd->clearComputeTables ();
0 commit comments