The Quantum Exact Simulation Toolkit v4.0.0
Loading...
Searching...
No Matches
matrices.cpp
1/** @file
2 * Unit tests of the matrices module.
3 *
4 * @author Tyson Jones
5 *
6 * @defgroup unitmatr Matrices
7 * @ingroup unittests
8 */
9
10#include "quest/include/quest.h"
11
12#include <catch2/catch_test_macros.hpp>
13#include <catch2/matchers/catch_matchers_string.hpp>
14#include <catch2/generators/catch_generators_range.hpp>
15
16#include "tests/utils/qvector.hpp"
17#include "tests/utils/qmatrix.hpp"
18#include "tests/utils/cache.hpp"
19#include "tests/utils/compare.hpp"
20#include "tests/utils/convert.hpp"
21#include "tests/utils/evolve.hpp"
22#include "tests/utils/linalg.hpp"
23#include "tests/utils/lists.hpp"
24#include "tests/utils/macros.hpp"
25#include "tests/utils/random.hpp"
26
27#include <cstdlib>
28#include <algorithm>
29
30using Catch::Matchers::ContainsSubstring;
31
32
33
34/*
35 * UTILITIES
36 */
37
38#define TEST_CATEGORY \
39 LABEL_UNIT_TAG "[matrices]"
40
41
42
43/**
44 * TESTS
45 *
46 * @ingroup unitmatr
47 * @{
48 */
49
50
51TEST_CASE( "getCompMatr1", TEST_CATEGORY ) {
52
53 SECTION( LABEL_CORRECTNESS ) {
54
55 constexpr int dim = 2;
56 qmatrix ref = getRandomMatrix(dim);
57
58 SECTION( LABEL_C_INTERFACE ) {
59
60 // 2D compile-time array
61 qcomp arr[dim][dim] = {{ref[0][0], ref[0][1]}, {ref[1][0], ref[1][1]}};
62 REQUIRE_AGREE( getCompMatr1(arr), ref );
63
64 // nested pointers
65 qcomp** ptrs = (qcomp**) malloc(dim * sizeof *ptrs);
66 for (int i=0; i<dim; i++) {
67 ptrs[i] = (qcomp*) malloc(dim * sizeof **ptrs);
68 for (int j=0; j<dim; j++)
69 ptrs[i][j] = ref[i][j];
70 }
71 REQUIRE_AGREE( getCompMatr1(ptrs), ref );
72
73 // array of pointers
74 qcomp* ptrArr[dim];
75 for (int i=0; i<dim; i++)
76 ptrArr[i] = ptrs[i];
77 REQUIRE_AGREE( getCompMatr1(ptrArr), ref );
78
79 // cleanup
80 for (int i=0; i<dim; i++)
81 free(ptrs[i]);
82 free(ptrs);
83 }
84
85 SECTION( LABEL_CPP_INTERFACE ) {
86
87 // nested vectors
88 REQUIRE_AGREE( getCompMatr1(ref), ref );
89
90 // inline vectors
91 REQUIRE_AGREE( getCompMatr1({{ref[0][0],ref[0][1]},{ref[1][0],ref[1][1]}}), ref );
92 }
93 }
94
95 SECTION( LABEL_VALIDATION ) {
96
97 SECTION( "null pointer" ) {
98
99 qcomp** ptr = nullptr;
100 REQUIRE_THROWS_WITH( getCompMatr1(ptr), ContainsSubstring("was a null pointer") );
101
102 qcomp* arr[1] = {nullptr};
103 REQUIRE_THROWS_WITH( getCompMatr1(arr), ContainsSubstring("contained a null pointer") );
104 }
105
106 SECTION( "invalid dimensions" ) {
107
108 // detectable only by the C++ interface
109
110 REQUIRE_THROWS_WITH( getCompMatr1({{0,0}}), ContainsSubstring("Incompatible number of rows") );
111 REQUIRE_THROWS_WITH( getCompMatr1({{0,0},{0,0},{0,0}}), ContainsSubstring("Incompatible number of rows") );
112
113 REQUIRE_THROWS_WITH( getCompMatr1({{0,0},{0}}), ContainsSubstring("incompatible number of elements") );
114 REQUIRE_THROWS_WITH( getCompMatr1({{0,0},{0,0,0}}), ContainsSubstring("incompatible number of elements") );
115 }
116 }
117}
118
119
120TEST_CASE( "getCompMatr2", TEST_CATEGORY ) {
121
122 SECTION( LABEL_CORRECTNESS ) {
123
124 constexpr int dim = 4;
125 qmatrix ref = getRandomMatrix(dim);
126
127 SECTION( LABEL_C_INTERFACE ) {
128
129 // 2D compile-time array
130 qcomp arr[dim][dim];
131 for (int i=0; i<dim; i++)
132 for (int j=0; j<dim; j++)
133 arr[i][j] = ref[i][j];
134 REQUIRE_AGREE( getCompMatr2(arr), ref );
135
136 // nested pointers
137 qcomp** ptrs = (qcomp**) malloc(dim * sizeof *ptrs);
138 for (int i=0; i<dim; i++) {
139 ptrs[i] = (qcomp*) malloc(dim * sizeof **ptrs);
140 for (int j=0; j<dim; j++)
141 ptrs[i][j] = ref[i][j];
142 }
143 REQUIRE_AGREE( getCompMatr2(ptrs), ref );
144
145 // array of pointers
146 qcomp* ptrArr[dim];
147 for (int i=0; i<dim; i++)
148 ptrArr[i] = ptrs[i];
149 REQUIRE_AGREE( getCompMatr2(ptrArr), ref );
150
151 // cleanup
152 for (int i=0; i<dim; i++)
153 free(ptrs[i]);
154 free(ptrs);
155 }
156
157 SECTION( LABEL_CPP_INTERFACE ) {
158
159 // nested vectors
160 REQUIRE_AGREE( getCompMatr2(ref), ref );
161
162 // inline vectors
163 REQUIRE_AGREE(
165 {ref[0][0],ref[0][1],ref[0][2],ref[0][3]},
166 {ref[1][0],ref[1][1],ref[1][2],ref[1][3]},
167 {ref[2][0],ref[2][1],ref[2][2],ref[2][3]},
168 {ref[3][0],ref[3][1],ref[3][2],ref[3][3]}
169 }),
170 ref
171 );
172 }
173 }
174
175 SECTION( LABEL_VALIDATION ) {
176
177 SECTION( "null pointer" ) {
178
179 qcomp** ptr = nullptr;
180 REQUIRE_THROWS_WITH( getCompMatr2(ptr), ContainsSubstring("was a null pointer") );
181
182 qcomp* arr[1] = {nullptr};
183 REQUIRE_THROWS_WITH( getCompMatr2(arr), ContainsSubstring("contained a null pointer") );
184 }
185
186 SECTION( "invalid dimensions" ) {
187
188 // detectable only by the C++ interface
189
190 qmatrix bad1 = {{0,0,0,0}};
191 qmatrix bad2 = {{0,0,0,0},{0,0,0,0},{0,0,0,0}};
192
193 REQUIRE_THROWS_WITH( getCompMatr2(bad1), ContainsSubstring("Incompatible number of rows") );
194 REQUIRE_THROWS_WITH( getCompMatr2(bad2), ContainsSubstring("Incompatible number of rows") );
195
196 REQUIRE_THROWS_WITH( getCompMatr2({{0,0,0,0},{0},{0},{0}}), ContainsSubstring("incompatible number of elements") );
197 REQUIRE_THROWS_WITH( getCompMatr2({{0,0,0,0,0},{0},{0},{0}}), ContainsSubstring("incompatible number of elements") );
198 }
199 }
200}
201
202
203TEST_CASE( "getDiagMatr1", TEST_CATEGORY ) {
204
205 SECTION( LABEL_CORRECTNESS ) {
206
207 constexpr int dim = 2;
208 qmatrix ref = getRandomDiagonalMatrix(dim);
209
210 SECTION( LABEL_C_INTERFACE ) {
211
212 // compile-time array
213 qcomp arr[dim] = {ref[0][0], ref[1][1] };
214 REQUIRE_AGREE( getDiagMatr1(arr), ref );
215
216 // pointer
217 qvector diags = getDiagonals(ref);
218 REQUIRE_AGREE( getDiagMatr1(diags.data()), ref );
219 }
220
221 SECTION( LABEL_CPP_INTERFACE ) {
222
223 // inline vectors
224 REQUIRE_AGREE( getDiagMatr1({ref[0][0],ref[1][1]}), ref );
225 }
226 }
227
228 SECTION( LABEL_VALIDATION ) {
229
230 SECTION( "null pointer" ) {
231
232 qcomp* ptr = nullptr;
233 REQUIRE_THROWS_WITH( getDiagMatr1(ptr), ContainsSubstring("was a null pointer") );
234 }
235
236 SECTION( "invalid dimensions" ) {
237
238 // detectable only by the C++ interface
239 qvector bad1 = {0};
240 qvector bad2 = {0,0,0};
241
242 REQUIRE_THROWS_WITH( getDiagMatr1(bad1), ContainsSubstring("Incompatible number of elements") );
243 REQUIRE_THROWS_WITH( getDiagMatr1(bad2), ContainsSubstring("Incompatible number of elements") );
244 }
245 }
246}
247
248
249TEST_CASE( "getDiagMatr2", TEST_CATEGORY ) {
250
251 SECTION( LABEL_CORRECTNESS ) {
252
253 constexpr int dim = 4;
254 qmatrix ref = getRandomDiagonalMatrix(dim);
255
256 SECTION( LABEL_C_INTERFACE ) {
257
258 // compile-time array
259 qcomp arr[dim] = {ref[0][0], ref[1][1], ref[2][2], ref[3][3] };
260 REQUIRE_AGREE( getDiagMatr2(arr), ref );
261
262 // pointer
263 qvector diags = getDiagonals(ref);
264 REQUIRE_AGREE( getDiagMatr2(diags.data()), ref );
265 }
266
267 SECTION( LABEL_CPP_INTERFACE ) {
268
269 // inline vectors
270 REQUIRE_AGREE( getDiagMatr2({ref[0][0], ref[1][1], ref[2][2], ref[3][3] }), ref );
271 }
272 }
273
274 SECTION( LABEL_VALIDATION ) {
275
276 SECTION( "null pointer" ) {
277
278 qcomp* ptr = nullptr;
279 REQUIRE_THROWS_WITH( getDiagMatr2(ptr), ContainsSubstring("was a null pointer") );
280 }
281
282 SECTION( "invalid dimensions" ) {
283
284 // detectable only by the C++ interface
285 qvector bad1 = {0,0,0};
286 qvector bad2 = {0,0,0,0,0};
287
288 REQUIRE_THROWS_WITH( getDiagMatr2(bad1), ContainsSubstring("Incompatible number of elements") );
289 REQUIRE_THROWS_WITH( getDiagMatr2(bad2), ContainsSubstring("Incompatible number of elements") );
290 }
291 }
292}
293
294
295TEST_CASE( "getInlineCompMatr1", TEST_CATEGORY ) {
296
297 SECTION( LABEL_CORRECTNESS ) {
298
299 qmatrix ref = {{1,2},{3_i,4_i}};
300
301 REQUIRE_AGREE( getInlineCompMatr1({{1,2},{3_i,4_i}}), ref );
302 }
303
304 SECTION( LABEL_VALIDATION ) {
305
306 SECTION( "invalid dimensions" ) {
307
308 // detectable only by the C++ interface
309
310 REQUIRE_THROWS_WITH( getInlineCompMatr1({{0,0}}), ContainsSubstring("Incompatible number of rows") );
311 REQUIRE_THROWS_WITH( getInlineCompMatr1({{0,0},{0,0},{0,0}}), ContainsSubstring("Incompatible number of rows") );
312
313 REQUIRE_THROWS_WITH( getInlineCompMatr1({{0,0},{0}}), ContainsSubstring("incompatible number of elements") );
314 REQUIRE_THROWS_WITH( getInlineCompMatr1({{0,0},{0,0,0}}), ContainsSubstring("incompatible number of elements") );
315 }
316 }
317}
318
319
320TEST_CASE( "getInlineCompMatr2", TEST_CATEGORY ) {
321
322 SECTION( LABEL_CORRECTNESS ) {
323
324 qmatrix ref = {
325 {1,2,3,4},
326 {5_i,6_i,7_i,8_i},
327 {-1,-2,-3,-4},
328 {-1_i,-2_i,-3_i,-4_i}};
329
330 REQUIRE_AGREE(
332 {1,2,3,4},
333 {5_i,6_i,7_i,8_i},
334 {-1,-2,-3,-4},
335 {-1_i,-2_i,-3_i,-4_i}
336 }), ref );
337 }
338
339 SECTION( LABEL_VALIDATION ) {
340
341 SECTION( "invalid dimensions" ) {
342
343 // detectable only by the C++ interface
344
345 REQUIRE_THROWS_WITH( getInlineCompMatr2({{0,0,0,0}}), ContainsSubstring("Incompatible number of rows") );
346 REQUIRE_THROWS_WITH( getInlineCompMatr2({{0,0,0,0},{0,0,0,0},{0,0,0,0}}), ContainsSubstring("Incompatible number of rows") );
347
348 REQUIRE_THROWS_WITH( getInlineCompMatr2({{0,0,0,0},{0},{0},{0}}), ContainsSubstring("incompatible number of elements") );
349 REQUIRE_THROWS_WITH( getInlineCompMatr2({{0,0,0,0,0},{0},{0},{0}}), ContainsSubstring("incompatible number of elements") );
350 }
351 }
352}
353
354
355TEST_CASE( "getInlineDiagMatr1", TEST_CATEGORY ) {
356
357 SECTION( LABEL_CORRECTNESS ) {
358
359 qmatrix ref = getDiagonalMatrix({1,2_i});
360
361 REQUIRE_AGREE( getInlineDiagMatr1({1,2_i}), ref );
362 }
363
364 SECTION( LABEL_VALIDATION ) {
365
366 SECTION( "invalid dimensions" ) {
367
368 REQUIRE_THROWS_WITH( getInlineDiagMatr1({0,0,0}), ContainsSubstring("Incompatible number of elements") );
369 }
370 }
371}
372
373
374TEST_CASE( "getInlineDiagMatr2", TEST_CATEGORY ) {
375
376 SECTION( LABEL_CORRECTNESS ) {
377
378 qmatrix ref = getDiagonalMatrix({1,2_i,-3,-4_i});
379
380 REQUIRE_AGREE( getInlineDiagMatr2({1,2_i,-3,-4_i}), ref );
381 }
382
383 SECTION( LABEL_VALIDATION ) {
384
385 SECTION( "invalid dimensions" ) {
386
387 REQUIRE_THROWS_WITH( getInlineDiagMatr2({0,0,0}), ContainsSubstring("Incompatible number of elements") );
388 REQUIRE_THROWS_WITH( getInlineDiagMatr2({0,0,0,0,0}), ContainsSubstring("Incompatible number of elements") );
389 }
390 }
391}
392
393
394TEST_CASE( "createCompMatr", TEST_CATEGORY ) {
395
396 SECTION( LABEL_CORRECTNESS ) {
397
398 // inessential to link to cached Qureg sizes, but
399 // provides a nice ballpark
400 int maxNumQubits = getNumCachedQubits();
401 int numQubits = GENERATE_COPY( range(1, maxNumQubits+1) );
402 CAPTURE( numQubits );
403
404 CompMatr matr = createCompMatr(numQubits);
405 qmatrix blank = getZeroMatrix(getPow2(numQubits));
406
407 // default elements
408 REQUIRE_AGREE( matr, blank );
409
410 // fields
411 REQUIRE( matr.numQubits == numQubits );
412 REQUIRE( matr.numRows == getPow2(numQubits) );
413
414 // default properties
415 REQUIRE( *(matr.isApproxUnitary) == -1 ); // unknown
416 REQUIRE( *(matr.isApproxHermitian) == -1 ); // unknown
417 REQUIRE( *(matr.wasGpuSynced) == 0 ); // false
418
419 // pointers
420 REQUIRE( matr.cpuElems != nullptr );
421 REQUIRE( matr.cpuElemsFlat != nullptr );
422
423 if (getQuESTEnv().isGpuAccelerated)
424 REQUIRE( matr.gpuElemsFlat != nullptr );
425 else
426 REQUIRE( matr.gpuElemsFlat == nullptr );
427
428 destroyCompMatr(matr);
429 }
430
431 SECTION( LABEL_VALIDATION ) {
432
433 SECTION( "env not initialised" ) {
434
435 // impossible to test
436 SUCCEED( );
437 }
438
439 SECTION( "too few qubits" ) {
440
441 int numQubits = GENERATE( -1, 0 );
442
443 REQUIRE_THROWS_WITH( createCompMatr(numQubits), ContainsSubstring("must target one or more qubits") );
444 }
445
446 SECTION( "too many qubits" ) {
447
448 // overflows qindex in all precisions
449 REQUIRE_THROWS_WITH( createCompMatr(50), ContainsSubstring("maximum which can be addressed by the qindex type") );
450
451 // overflows size_t in single precision (and ergo also in double and quad)
452 REQUIRE_THROWS_WITH( createCompMatr(31), ContainsSubstring("necessary memory would overflow size_t") );
453
454 // no overflows, but definitely exceeds local RAM and fails to allocate; frightens address sanitizer!
455 // note the specific error message depends on the what backend the auto-deployer tried to use (e.g.
456 // GPU-accel or distributed) and whether memory-probers realised there was insufficient memory in
457 // advance or whether it proceeded to malloc() which subsequently failed
458 #ifndef SANITIZER_IS_ACTIVE
459 REQUIRE_THROWS_WITH( createCompMatr(25), ContainsSubstring("failed") || ContainsSubstring("insufficient available memory") || ContainsSubstring("available GPU memory") );
460 #endif
461 }
462 }
463}
464
465
466TEST_CASE( "createDiagMatr", TEST_CATEGORY ) {
467
468 SECTION( LABEL_CORRECTNESS ) {
469
470 // inessential to link to cached Qureg sizes, but
471 // provides a nice ballpark
472 int maxNumQubits = getNumCachedQubits();
473 int numQubits = GENERATE_COPY( range(1, maxNumQubits+1) );
474 CAPTURE( numQubits );
475
476 DiagMatr matr = createDiagMatr(numQubits);
477 qmatrix blank = getZeroMatrix(getPow2(numQubits));
478
479 // default elements
480 REQUIRE_AGREE( matr, blank );
481
482 // fields
483 REQUIRE( matr.numQubits == numQubits );
484 REQUIRE( matr.numElems == getPow2(numQubits) );
485
486 // default properties
487 REQUIRE( *(matr.isApproxUnitary) == -1 ); // unknown
488 REQUIRE( *(matr.isApproxHermitian) == -1 ); // unknown
489 REQUIRE( *(matr.isApproxNonZero) == -1 ); // unknown
490 REQUIRE( *(matr.isStrictlyNonNegative) == -1 ); // unknown
491 REQUIRE( *(matr.wasGpuSynced) == 0 ); // false
492
493 // pointers
494 REQUIRE( matr.cpuElems != nullptr );
495
496 if (getQuESTEnv().isGpuAccelerated)
497 REQUIRE( matr.gpuElems != nullptr );
498 else
499 REQUIRE( matr.gpuElems == nullptr );
500
501 destroyDiagMatr(matr);
502 }
503
504 SECTION( LABEL_VALIDATION ) {
505
506 SECTION( "env not initialised" ) {
507
508 // impossible to test
509 SUCCEED( );
510 }
511
512 SECTION( "too few qubits" ) {
513
514 int numQubits = GENERATE( -1, 0 );
515
516 REQUIRE_THROWS_WITH( createDiagMatr(numQubits), ContainsSubstring("must target one or more qubits") );
517 }
518
519 SECTION( "too many qubits" ) {
520
521 // overflows qindex in all precisions
522 REQUIRE_THROWS_WITH( createDiagMatr(100), ContainsSubstring("maximum which can be addressed by the qindex type") );
523
524 // overflows size_t in single precision (and ergo also in double and quad)
525 REQUIRE_THROWS_WITH( createDiagMatr(62), ContainsSubstring("necessary memory would overflow size_t") );
526
527 // no overflows, but definitely exceeds local RAM and fails to allocate; frightens address sanitizer!
528 // note the specific error message depends on the what backend the auto-deployer tried to use (e.g.
529 // GPU-accel or distributed) and whether memory-probers realised there was insufficient memory in
530 // advance or whether it proceeded to malloc() which subsequently failed
531 #ifndef SANITIZER_IS_ACTIVE
532 REQUIRE_THROWS_WITH( createDiagMatr(50), ContainsSubstring("failed") || ContainsSubstring("insufficient available memory") || ContainsSubstring("available GPU memory") );
533 #endif
534 }
535 }
536}
537
538
539TEST_CASE( "createFullStateDiagMatr", TEST_CATEGORY ) {
540
541 SECTION( LABEL_CORRECTNESS ) {
542
543 int numQubits = GENERATE_COPY( range(1, 20) );
544 CAPTURE( numQubits );
545
546 // uses auto deployment
548
549 // check state is blank
550 bool isBlank = true;
551 for (qindex i=0; i<matr.numElemsPerNode && isBlank; i++)
552 isBlank = (matr.cpuElems[i] == qcomp(0,0));
553 REQUIRE( isBlank );
554
555 // dimensions
556 REQUIRE( matr.numQubits == numQubits );
557 REQUIRE( matr.numElems == getPow2(numQubits) );
558 REQUIRE( matr.numElemsPerNode == matr.numElems / (matr.isDistributed? getQuESTEnv().numNodes : 1) );
559
560 // default properties
561 REQUIRE( *(matr.isApproxUnitary) == -1 ); // unknown
562 REQUIRE( *(matr.isApproxHermitian) == -1 ); // unknown
563 REQUIRE( *(matr.isApproxNonZero) == -1 ); // unknown
564 REQUIRE( *(matr.isStrictlyNonNegative) == -1 ); // unknown
565 REQUIRE( *(matr.wasGpuSynced) == 0 ); // false
566
567 // pointers
568 REQUIRE( matr.cpuElems != nullptr );
569
570 int gpu = matr.isGpuAccelerated;
571 if (gpu) REQUIRE( matr.gpuElems != nullptr );
572 else REQUIRE( matr.gpuElems == nullptr );
573
575 }
576
577 SECTION( LABEL_VALIDATION ) {
578
579 SECTION( "env not initialised" ) {
580
581 // impossible to test
582 SUCCEED( );
583 }
584
585 SECTION( "too few qubits" ) {
586
587 int numQubits = GENERATE( -1, 0 );
588
589 REQUIRE_THROWS_WITH( createFullStateDiagMatr(numQubits), ContainsSubstring("must target one or more qubits") );
590 }
591
592 SECTION( "too many qubits" ) {
593
594 // overflows qindex in all precisions
595 REQUIRE_THROWS_WITH( createFullStateDiagMatr(100), ContainsSubstring("maximum which can be addressed by the qindex type") );
596
597 // overflows size_t in single precision (and ergo also in double and quad)
598 REQUIRE_THROWS_WITH( createFullStateDiagMatr(62), ContainsSubstring("memory would overflow size_t") );
599
600 // no overflows, but definitely exceeds local RAM and fails to allocate; frightens address sanitizer!
601 // note the specific error message depends on the what backend the auto-deployer tried to use (e.g.
602 // GPU-accel or distributed) and whether memory-probers realised there was insufficient memory in
603 // advance or whether it proceeded to malloc() which subsequently failed
604 #ifndef SANITIZER_IS_ACTIVE
605 REQUIRE_THROWS_WITH( createFullStateDiagMatr(50), ContainsSubstring("failed") || ContainsSubstring("insufficient available memory") || ContainsSubstring("available GPU memory") );
606 #endif
607 }
608
609 // this function chooses automatic deployment,
610 // so we cannot force illegal distribution
611 }
612}
613
614
615TEST_CASE( "createCustomFullStateDiagMatr", TEST_CATEGORY ) {
616
617 SECTION( LABEL_CORRECTNESS ) {
618
619 for (auto [label, mpi, gpu, omp] : getSupportedDeployments()) {
620
621 DYNAMIC_SECTION( label ) {
622
623 int minNumQubits = std::max({1, getLog2(getQuESTEnv().numNodes)});
624 int maxNumQubits = std::min({20, minNumQubits + 1});
625 int numQubits = GENERATE_COPY( range(minNumQubits, maxNumQubits+1) );
626 CAPTURE( numQubits );
627
628 FullStateDiagMatr matr = createCustomFullStateDiagMatr(numQubits, mpi, gpu, omp);
629
630 // check state is blank
631 bool isBlank = true;
632 for (qindex i=0; i<matr.numElemsPerNode && isBlank; i++)
633 isBlank = (matr.cpuElems[i] == qcomp(0,0));
634 REQUIRE( isBlank );
635
636 // dimensions
637 REQUIRE( matr.numQubits == numQubits );
638 REQUIRE( matr.numElems == getPow2(numQubits) );
639 REQUIRE( matr.numElemsPerNode == matr.numElems / (mpi? getQuESTEnv().numNodes : 1) );
640
641 // accelerations
642 REQUIRE( matr.isDistributed == (int) (mpi && getQuESTEnv().numNodes > 1) );
643 REQUIRE( matr.isGpuAccelerated == (int) gpu );
644 REQUIRE( matr.isMultithreaded == (int) omp );
645
646 // default properties
647 REQUIRE( *(matr.isApproxUnitary) == -1 ); // unknown
648 REQUIRE( *(matr.isApproxHermitian) == -1 ); // unknown
649 REQUIRE( *(matr.isApproxNonZero) == -1 ); // unknown
650 REQUIRE( *(matr.isStrictlyNonNegative) == -1 ); // unknown
651 REQUIRE( *(matr.wasGpuSynced) == 0 ); // false
652
653 // pointers
654 REQUIRE( matr.cpuElems != nullptr );
655
656 if (gpu) REQUIRE( matr.gpuElems != nullptr );
657 else REQUIRE( matr.gpuElems == nullptr );
658
660 }
661 }
662
663 }
664
665 SECTION( LABEL_VALIDATION ) {
666
667 SECTION( "env not initialised" ) {
668
669 // impossible to test
670 SUCCEED( );
671 }
672
673 SECTION( "too few qubits" ) {
674
675 int numQubits = GENERATE( -1, 0 );
676
677 for (auto [label, mpi, gpu, omp] : getSupportedDeployments())
678 REQUIRE_THROWS_WITH( createCustomFullStateDiagMatr(numQubits, mpi,gpu,omp), ContainsSubstring("must target one or more qubits") );
679
680 if (getQuESTEnv().numNodes > 2) { // 1 node => min=1
681 int minNumQubits = getLog2(getQuESTEnv().numNodes);
682 REQUIRE_THROWS_WITH( createCustomFullStateDiagMatr(minNumQubits-1, 1,0,0), ContainsSubstring("node would contain fewer than one element") );
683 }
684 }
685
686 SECTION( "too many qubits" ) {
687
688 for (auto [label, mpi, gpu, omp] : getSupportedDeployments()) {
689
690 // overflows qindex in all precisions
691 REQUIRE_THROWS_WITH( createCustomFullStateDiagMatr(100, mpi,gpu,omp), ContainsSubstring("maximum which can be addressed by the qindex type") );
692
693 // overflows size_t in single precision (and ergo also in double and quad)
694 REQUIRE_THROWS_WITH( createCustomFullStateDiagMatr(62, mpi,gpu,omp), ContainsSubstring("memory would overflow size_t") );
695
696 // no overflows, but definitely exceeds local RAM and fails to allocate; frightens address sanitizer!
697 // note the specific error message depends on the what backend the auto-deployer tried to use (e.g.
698 // GPU-accel or distributed) and whether memory-probers realised there was insufficient memory in
699 // advance or whether it proceeded to malloc() which subsequently failed
700 #ifndef SANITIZER_IS_ACTIVE
701 REQUIRE_THROWS_WITH( createCustomFullStateDiagMatr(50, mpi,gpu,omp), ContainsSubstring("failed") || ContainsSubstring("insufficient available memory") || ContainsSubstring("available GPU memory") );
702 #endif
703 }
704 }
705
706 SECTION( "unsupported deployments" ) {
707
708 if (!getQuESTEnv().isDistributed)
709 REQUIRE_THROWS_WITH( createCustomFullStateDiagMatr(1, 1,0,0), ContainsSubstring("non-distributed QuEST environment") );
710
711 if (!getQuESTEnv().isGpuAccelerated)
712 REQUIRE_THROWS_WITH( createCustomFullStateDiagMatr(1, 0,1,0), ContainsSubstring("non-GPU-accelerated QuEST environment") );
713
714 if (!getQuESTEnv().isMultithreaded)
715 REQUIRE_THROWS_WITH( createCustomFullStateDiagMatr(1, 0,0,1), ContainsSubstring("non-multithreaded QuEST environment") );
716 }
717 }
718}
719
720
721TEST_CASE( "destroyCompMatr", TEST_CATEGORY ) {
722
723 SECTION( LABEL_CORRECTNESS ) {
724
726 REQUIRE_NOTHROW( destroyCompMatr(m) );
727 }
728
729 SECTION( LABEL_VALIDATION ) {
730
731 // sanitizer messes with default initialisation
732 #ifndef SANITIZER_IS_ACTIVE
733 SECTION( "not created" ) {
734
735 CompMatr m;
736 REQUIRE_THROWS_WITH( destroyCompMatr(m), ContainsSubstring("Invalid CompMatr") && ContainsSubstring("not created") );
737 }
738 #endif
739 }
740}
741
742
743TEST_CASE( "destroyDiagMatr", TEST_CATEGORY ) {
744
745 SECTION( LABEL_CORRECTNESS ) {
746
748 REQUIRE_NOTHROW( destroyDiagMatr(m) );
749 }
750
751 SECTION( LABEL_VALIDATION ) {
752
753 // sanitizer messes with default initialisation
754 #ifndef SANITIZER_IS_ACTIVE
755 SECTION( "not created" ) {
756
757 DiagMatr m;
758 REQUIRE_THROWS_WITH( destroyDiagMatr(m), ContainsSubstring("Invalid DiagMatr") && ContainsSubstring("not created") );
759 }
760 #endif
761 }
762}
763
764
765TEST_CASE( "destroyFullStateDiagMatr", TEST_CATEGORY ) {
766
767 SECTION( LABEL_CORRECTNESS ) {
768
770 REQUIRE_NOTHROW( destroyFullStateDiagMatr(m) );
771 }
772
773 SECTION( LABEL_VALIDATION ) {
774
775 // sanitizer messes with default initialisation
776 #ifndef SANITIZER_IS_ACTIVE
777 SECTION( "not created" ) {
778
780 REQUIRE_THROWS_WITH( destroyFullStateDiagMatr(m), ContainsSubstring("Invalid FullStateDiagMatr") );
781 }
782 #endif
783 }
784}
785
786
787TEST_CASE( "syncCompMatr", TEST_CATEGORY ) {
788
789 SECTION( LABEL_CORRECTNESS ) {
790
791 CompMatr matr = createCompMatr(5);
792
793 REQUIRE( *(matr.wasGpuSynced) == 0 );
794
795 SECTION( "overwrites GPU elements" ) {
796
797 // to test that the GPU memory was actually overwritten,
798 // we would need a custom accessor of GPU memory, requiring
799 // the tests are CUDA-compiled - no thank you mam! It is
800 // certain this function works from the other GPU tests.
801
802 SUCCEED( );
803 }
804
805 SECTION( "sets was-synced flag" ) {
806
807 *(matr.wasGpuSynced) = 0;
808
809 syncCompMatr(matr);
810 REQUIRE( *(matr.wasGpuSynced) == 1 );
811 }
812
813 SECTION( "clears numerical flags" ) {
814
815 *(matr).isApproxHermitian = 1;
816 *(matr).isApproxUnitary = 0;
817
818 syncCompMatr(matr);
819 REQUIRE( *(matr.isApproxHermitian) == -1 );
820 REQUIRE( *(matr.isApproxUnitary) == -1 );
821 }
822
823 destroyCompMatr(matr);
824 }
825
826 SECTION( LABEL_VALIDATION ) {
827
828 // sanitizer messes with default initialisation
829 #ifndef SANITIZER_IS_ACTIVE
830 SECTION( "not created" ) {
831
832 CompMatr m;
833 REQUIRE_THROWS_WITH( syncCompMatr(m), ContainsSubstring("Invalid CompMatr") && ContainsSubstring("not created") );
834 }
835 #endif
836 }
837}
838
839
840TEST_CASE( "syncDiagMatr", TEST_CATEGORY ) {
841
842 SECTION( LABEL_CORRECTNESS ) {
843
844 DiagMatr matr = createDiagMatr(5);
845 REQUIRE( *(matr.wasGpuSynced) == 0 );
846
847 SECTION( "overwrites GPU elements" ) {
848
849 // to test that the GPU memory was actually overwritten,
850 // we would need a custom accessor of GPU memory, requiring
851 // the tests are CUDA-compiled - no thank you mam! It is
852 // certain this function works from the other GPU tests.
853
854 SUCCEED( );
855 }
856
857 SECTION( "sets was-synced flag" ) {
858
859 *(matr.wasGpuSynced) = 0;
860
861 syncDiagMatr(matr);
862 REQUIRE( *(matr.wasGpuSynced) == 1 );
863 }
864
865 SECTION( "clears numerical flags" ) {
866
867 *(matr).isApproxHermitian = 1;
868 *(matr).isApproxUnitary = 0;
869 *(matr).isApproxNonZero = 1;
870 *(matr).isStrictlyNonNegative = 0;
871
872 syncDiagMatr(matr);
873 REQUIRE( *(matr.isApproxHermitian) == -1 );
874 REQUIRE( *(matr.isApproxUnitary) == -1 );
875 REQUIRE( *(matr.isApproxNonZero) == -1 );
876 REQUIRE( *(matr.isStrictlyNonNegative) == -1 );
877 }
878
879 destroyDiagMatr(matr);
880 }
881
882 SECTION( LABEL_VALIDATION ) {
883
884 // sanitizer messes with default initialisation
885 #ifndef SANITIZER_IS_ACTIVE
886 SECTION( "not created" ) {
887
888 DiagMatr m;
889 REQUIRE_THROWS_WITH( syncDiagMatr(m), ContainsSubstring("Invalid DiagMatr") && ContainsSubstring("not created") );
890 }
891 #endif
892 }
893}
894
895
896TEST_CASE( "syncFullStateDiagMatr", TEST_CATEGORY ) {
897
898 SECTION( LABEL_CORRECTNESS ) {
899
900 for (auto& [label, matrix]: getCachedFullStateDiagMatrs()) {
901
902 DYNAMIC_SECTION( label ) {
903
904 *(matrix.wasGpuSynced) = 0;
905 *(matrix).isApproxHermitian = 1;
906 *(matrix).isApproxUnitary = 0;
907 *(matrix).isApproxNonZero = 1;
908 *(matrix).isStrictlyNonNegative = 0;
909
910 syncFullStateDiagMatr(matrix);
911 REQUIRE( *(matrix.wasGpuSynced) == 1 );
912
913 REQUIRE( *(matrix.isApproxHermitian) == -1 );
914 REQUIRE( *(matrix.isApproxUnitary) == -1 );
915 REQUIRE( *(matrix.isApproxNonZero) == -1 );
916 REQUIRE( *(matrix.isStrictlyNonNegative) == -1 );
917
918 // to test that the GPU memory was actually overwritten,
919 // we would need a custom accessor of GPU memory, requiring
920 // the tests are CUDA-compiled - no thank you mam! It is
921 // certain this function works from the other GPU tests.
922 }
923 }
924 }
925
926 SECTION( LABEL_VALIDATION ) {
927
928 // sanitizer messes with default initialisation
929 #ifndef SANITIZER_IS_ACTIVE
930 SECTION( "not created" ) {
931
933 REQUIRE_THROWS_WITH( syncFullStateDiagMatr(m), ContainsSubstring("Invalid FullStateDiagMatr") );
934 }
935 #endif
936 }
937}
938
939
940TEST_CASE( "setCompMatr", TEST_CATEGORY ) {
941
942 SECTION( LABEL_CORRECTNESS ) {
943
944 int numQubits = GENERATE( range(1,6) );
945 CAPTURE( numQubits );
946
947 CompMatr matr = createCompMatr(numQubits);
948 REQUIRE( *(matr.wasGpuSynced) == 0 );
949
950 int dim = getPow2(numQubits);
951 qmatrix ref = getRandomMatrix(dim);
952
953 SECTION( LABEL_C_INTERFACE ) {
954
955 // nested pointers
956 qcomp** ptrs = (qcomp**) malloc(dim * sizeof *ptrs);
957 for (int i=0; i<dim; i++) {
958 ptrs[i] = (qcomp*) malloc(dim * sizeof **ptrs);
959 for (int j=0; j<dim; j++)
960 ptrs[i][j] = ref[i][j];
961 }
962 setCompMatr(matr, ptrs);
963 REQUIRE_AGREE( matr, ref );
964 REQUIRE( *(matr.wasGpuSynced) == 1 );
965
966 // cannot test 2D VLAs in this C++ file
967
968 // cleanup
969 for (int i=0; i<dim; i++)
970 free(ptrs[i]);
971 free(ptrs);
972 }
973
974 SECTION( LABEL_CPP_INTERFACE ) {
975
976 // nested vectors
977 setCompMatr( matr, getZeroMatrix(dim) ); // clear
978 setCompMatr( matr, ref );
979 REQUIRE_AGREE( matr, ref );
980 REQUIRE( *(matr.wasGpuSynced) == 1 );
981 }
982
983 destroyCompMatr(matr);
984 }
985
986 SECTION( LABEL_VALIDATION ) {
987
988 CompMatr matr = createCompMatr(1);
989
990 /// @todo fails in MSVC for unknown reason
991 #ifndef _MSC_VER
992 // sanitizer messes with default initialisation
993 #ifndef SANITIZER_IS_ACTIVE
994 SECTION( "not created" ) {
995
996 CompMatr bad;
997 qcomp** dummy;
998 REQUIRE_THROWS_WITH( setCompMatr(bad, dummy), ContainsSubstring("Invalid CompMatr") && ContainsSubstring("not created") );
999 }
1000 #endif
1001 #endif
1002
1003 SECTION( "null pointer" ) {
1004
1005 qcomp** ptr = nullptr;
1006 REQUIRE_THROWS_WITH( setCompMatr(matr, ptr), ContainsSubstring("was a null pointer") );
1007
1008 qcomp* arr[1] = {nullptr};
1009 REQUIRE_THROWS_WITH( setCompMatr(matr, arr), ContainsSubstring("contained a null pointer") );
1010 }
1011
1012 SECTION( "invalid dimensions" ) {
1013
1014 // detectable only by the C++ interface
1015
1016 REQUIRE_NOTHROW( setCompMatr(matr, {{1,2},{3,4}}) );
1017
1018 REQUIRE_THROWS_WITH( setCompMatr(matr,{{1,2}}), ContainsSubstring("Incompatible number of rows") );
1019 REQUIRE_THROWS_WITH( setCompMatr(matr, {{1,2},{3,4},{5,6}}), ContainsSubstring("Incompatible number of rows") );
1020
1021 REQUIRE_THROWS_WITH( setCompMatr(matr, {{0,0},{0}}), ContainsSubstring("incompatible number of elements") );
1022 REQUIRE_THROWS_WITH( setCompMatr(matr, {{0,0},{0,0,0}}), ContainsSubstring("incompatible number of elements") );
1023 }
1024
1025 destroyCompMatr(matr);
1026 }
1027}
1028
1029
1030TEST_CASE( "setDiagMatr", TEST_CATEGORY ) {
1031
1032 SECTION( LABEL_CORRECTNESS ) {
1033
1034 int numQubits = GENERATE( range(1,6) );
1035 CAPTURE( numQubits );
1036
1037 DiagMatr matr = createDiagMatr(numQubits);
1038 REQUIRE( *(matr.wasGpuSynced) == 0 );
1039
1040 int dim = getPow2(numQubits);
1041 qmatrix ref = getRandomDiagonalMatrix(dim);
1042
1043 SECTION( LABEL_C_INTERFACE ) {
1044
1045 // pointer
1046 qvector diags = getDiagonals(ref);
1047 setDiagMatr(matr, diags.data());
1048 REQUIRE_AGREE( matr, ref );
1049 REQUIRE( *(matr.wasGpuSynced) == 1 );
1050 }
1051
1052 SECTION( LABEL_CPP_INTERFACE ) {
1053
1054 // vector
1055 setDiagMatr(matr, getZeroVector(dim)); // clear
1056 setDiagMatr(matr, getDiagonals(ref));
1057 REQUIRE_AGREE( matr, ref );
1058 REQUIRE( *(matr.wasGpuSynced) == 1 );
1059 }
1060
1061 destroyDiagMatr(matr);
1062 }
1063
1064 SECTION( LABEL_VALIDATION ) {
1065
1066 DiagMatr matr = createDiagMatr(1);
1067
1068 // sanitizer messes with default initialisation
1069 #ifndef SANITIZER_IS_ACTIVE
1070 SECTION( "not created" ) {
1071
1072 DiagMatr bad;
1073 qcomp* dummy;
1074 REQUIRE_THROWS_WITH( setDiagMatr(bad, dummy), ContainsSubstring("Invalid DiagMatr") && ContainsSubstring("not created") );
1075 }
1076 #endif
1077
1078 SECTION( "null pointer" ) {
1079
1080 qcomp* ptr = nullptr;
1081 REQUIRE_THROWS_WITH( setDiagMatr(matr, ptr), ContainsSubstring("was a null pointer") );
1082 }
1083
1084 SECTION( "invalid dimensions" ) {
1085
1086 // detectable only by the C++ interface
1087
1088 REQUIRE_NOTHROW( setDiagMatr(matr, {1,2}) );
1089
1090 REQUIRE_THROWS_WITH( setDiagMatr(matr, {1}), ContainsSubstring("Incompatible number of elements") );
1091 REQUIRE_THROWS_WITH( setDiagMatr(matr, {1,2,3}), ContainsSubstring("Incompatible number of elements") );
1092 }
1093
1094 destroyDiagMatr(matr);
1095 }
1096}
1097
1098
1099TEST_CASE( "setInlineCompMatr", TEST_CATEGORY ) {
1100
1101 SECTION( LABEL_CORRECTNESS ) {
1102
1103 CompMatr matr = createCompMatr(1);
1104 REQUIRE( *(matr.wasGpuSynced) == 0 );
1105
1106 setInlineCompMatr( matr, 1, {{1,2},{3,4}} );
1107 REQUIRE_AGREE( matr, {{1,2},{3,4}} );
1108 REQUIRE( *(matr.wasGpuSynced) == 1 );
1109
1110 destroyCompMatr(matr);
1111 }
1112
1113 SECTION( LABEL_VALIDATION ) {
1114
1115 CompMatr matr = createCompMatr(1);
1116
1117 /// @todo fails in MSVC for unknown reason
1118 #ifndef _MSC_VER
1119 // sanitizer messes with default initialisation
1120 #ifndef SANITIZER_IS_ACTIVE
1121 SECTION( "not created" ) {
1122
1123 CompMatr bad;
1124 REQUIRE_THROWS_WITH( setInlineCompMatr(bad, 1, {{1,2},{3,4}}), ContainsSubstring("Invalid CompMatr") && ContainsSubstring("not created") );
1125 }
1126 #endif
1127 #endif
1128
1129 SECTION( "mismatching dimension" ) {
1130
1131 REQUIRE_THROWS_WITH( setInlineCompMatr(matr, 2, {{1,2},{3,4}}), ContainsSubstring("declared number of qubits") && ContainsSubstring("differs") );
1132 }
1133
1134 SECTION( "invalid dimensions" ) {
1135
1136 // detectable only by the C++ interface
1137
1138 REQUIRE_NOTHROW( setInlineCompMatr(matr, 1, {{1,2},{3,4}}) );
1139
1140 REQUIRE_THROWS_WITH( setInlineCompMatr(matr, 1, {{1,2}}), ContainsSubstring("Incompatible number of rows") );
1141 REQUIRE_THROWS_WITH( setInlineCompMatr(matr, 1, {{1,2},{3,4},{5,6}}), ContainsSubstring("Incompatible number of rows") );
1142
1143 REQUIRE_THROWS_WITH( setInlineCompMatr(matr, 1, {{1},{2}}), ContainsSubstring("One or more rows contained an incompatible number of elements") );
1144 REQUIRE_THROWS_WITH( setInlineCompMatr(matr, 1, {{1,2,3},{4,5,6}}), ContainsSubstring("One or more rows contained an incompatible number of elements") );
1145 }
1146
1147 destroyCompMatr(matr);
1148 }
1149}
1150
1151
1152TEST_CASE( "setInlineDiagMatr", TEST_CATEGORY ) {
1153
1154 SECTION( LABEL_CORRECTNESS ) {
1155
1156 DiagMatr matr = createDiagMatr(1);
1157 REQUIRE( *(matr.wasGpuSynced) == 0 );
1158
1159 setInlineDiagMatr( matr, 1, {1,2_i} );
1160 REQUIRE_AGREE( matr, {{1,0},{0,2_i}} );
1161 REQUIRE( *(matr.wasGpuSynced) == 1 );
1162
1163 destroyDiagMatr(matr);
1164 }
1165
1166 SECTION( LABEL_VALIDATION ) {
1167
1168 DiagMatr matr = createDiagMatr(1);
1169
1170 /// @todo fails in MSVC for unknown reason
1171 #ifndef _MSC_VER
1172 // sanitizer messes with default initialisation
1173 #ifndef SANITIZER_IS_ACTIVE
1174 SECTION( "not created" ) {
1175
1176 DiagMatr bad;
1177 REQUIRE_THROWS_WITH( setInlineDiagMatr(bad, 1, {1,2}), ContainsSubstring("Invalid DiagMatr") && ContainsSubstring("not created") );
1178 }
1179 #endif
1180 #endif
1181
1182 SECTION( "mismatching dimension" ) {
1183
1184 REQUIRE_THROWS_WITH( setInlineDiagMatr(matr, 2, {1,2}), ContainsSubstring("declared number of qubits") && ContainsSubstring("differs") );
1185 }
1186
1187 SECTION( "invalid dimensions" ) {
1188
1189 // detectable only by the C++ interface
1190
1191 REQUIRE_NOTHROW( setInlineDiagMatr(matr, 1, {1,2}) );
1192
1193 REQUIRE_THROWS_WITH( setInlineDiagMatr(matr, 1, {1}), ContainsSubstring("Incompatible number of elements") );
1194 REQUIRE_THROWS_WITH( setInlineDiagMatr(matr, 1, {1,2,3}), ContainsSubstring("Incompatible number of elements") );
1195 }
1196
1197 destroyDiagMatr(matr);
1198 }
1199}
1200
1201
1202TEST_CASE( "createInlineCompMatr", TEST_CATEGORY ) {
1203
1204 SECTION( LABEL_CORRECTNESS ) {
1205
1206 CompMatr matr = createInlineCompMatr(1, {{1,2},{3,4}});
1207
1208 REQUIRE_AGREE( matr, {{1,2},{3,4}} );
1209 REQUIRE( *(matr.wasGpuSynced) == 1 );
1210
1211 destroyCompMatr(matr);
1212 }
1213
1214 SECTION( LABEL_VALIDATION ) {
1215
1216 SECTION( "env not initialised" ) {
1217
1218 // impossible to test
1219 SUCCEED( );
1220 }
1221
1222 SECTION( "too few qubits" ) {
1223
1224 int numQubits = GENERATE( -1, 0 );
1225
1226 REQUIRE_THROWS_WITH( createInlineCompMatr(numQubits, {{1}}), ContainsSubstring("must target one or more qubits") );
1227 }
1228
1229 SECTION( "mismatching dimension" ) {
1230
1231 REQUIRE_THROWS_WITH( createInlineCompMatr(2, {{1,2},{3,4}}), ContainsSubstring("Incompatible number of rows") );
1232 }
1233 }
1234}
1235
1236
1237TEST_CASE( "createInlineDiagMatr", TEST_CATEGORY ) {
1238
1239 SECTION( LABEL_CORRECTNESS ) {
1240
1241 DiagMatr matr = createInlineDiagMatr(1, {1,2_i});
1242
1243 REQUIRE_AGREE( matr, {{1,0},{0,2_i}} );
1244 REQUIRE( *(matr.wasGpuSynced) == 1 );
1245
1246 destroyDiagMatr(matr);
1247 }
1248
1249 SECTION( LABEL_VALIDATION ) {
1250
1251 SECTION( "env not initialised" ) {
1252
1253 // impossible to test
1254 SUCCEED( );
1255 }
1256
1257 SECTION( "too few qubits" ) {
1258
1259 int numQubits = GENERATE( -1, 0 );
1260
1261 REQUIRE_THROWS_WITH( createInlineDiagMatr(numQubits, {1}), ContainsSubstring("must target one or more qubits") );
1262 }
1263
1264 SECTION( "mismatching dimension" ) {
1265
1266 REQUIRE_THROWS_WITH( createInlineDiagMatr(2, {1,2}), ContainsSubstring("Incompatible number of elements") );
1267 }
1268 }
1269}
1270
1271
1272/** @} (end defgroup) */
1273
1274
1275
1276/**
1277 * @todo
1278 * UNTESTED FUNCTIONS
1279 */
1280
1281
1282void setFullStateDiagMatr(FullStateDiagMatr out, qindex startInd, qcomp* in, qindex numElems);
1283void setFullStateDiagMatr(FullStateDiagMatr out, qindex startInd, std::vector<qcomp> in);
1284
1285void setInlineFullStateDiagMatr(FullStateDiagMatr matr, qindex startInd, qindex numElems, std::vector<qcomp> in);
1286
1287
1288void setDiagMatrFromMultiVarFunc(DiagMatr out, qcomp (*func)(qindex*), int* numQubitsPerVar, int numVars, int areSigned);
1289
1290void setDiagMatrFromMultiDimLists(DiagMatr out, void* lists, int* numQubitsPerDim, int numDims);
1291
1292
1294
1296
1297void setFullStateDiagMatrFromMultiVarFunc(FullStateDiagMatr out, qcomp (*func)(qindex*), int* numQubitsPerVar, int numVars, int areSigned);
1298
1299void setFullStateDiagMatrFromMultiDimLists(FullStateDiagMatr out, void* lists, int* numQubitsPerDim, int numDims);
1300
1301
1302void reportCompMatr1(CompMatr1 matrix);
1303void reportCompMatr2(CompMatr2 matrix);
1304void reportCompMatr(CompMatr matrix);
1305void reportDiagMatr1(DiagMatr1 matrix);
1306void reportDiagMatr2(DiagMatr2 matrix);
1307void reportDiagMatr(DiagMatr matrix);
QuESTEnv getQuESTEnv()
FullStateDiagMatr createCustomFullStateDiagMatr(int numQubits, int useDistrib, int useGpuAccel, int useMultithread)
Definition matrices.cpp:322
DiagMatr createInlineDiagMatr(int numQb, std::vector< qcomp > elems)
FullStateDiagMatr createFullStateDiagMatr(int numQubits)
Definition matrices.cpp:327
CompMatr createInlineCompMatr(int numQb, std::vector< std::vector< qcomp > > elems)
CompMatr createCompMatr(int numQubits)
Definition matrices.cpp:211
DiagMatr createDiagMatr(int numQubits)
Definition matrices.cpp:246
FullStateDiagMatr createFullStateDiagMatrFromPauliStrSum(PauliStrSum in)
Definition matrices.cpp:658
void destroyDiagMatr(DiagMatr matrix)
Definition matrices.cpp:403
void destroyFullStateDiagMatr(FullStateDiagMatr matrix)
Definition matrices.cpp:404
void destroyCompMatr(CompMatr matrix)
Definition matrices.cpp:402
static CompMatr2 getCompMatr2(qcomp **in)
Definition matrices.h:327
static CompMatr1 getCompMatr1(qcomp **in)
Definition matrices.h:311
static DiagMatr2 getDiagMatr2(qcomp *in)
Definition matrices.h:359
CompMatr1 getInlineCompMatr1({{ matrix }})
CompMatr2 getInlineCompMatr2({{ matrix }})
DiagMatr2 getInlineDiagMatr2({ list })
static DiagMatr1 getDiagMatr1(qcomp *in)
Definition matrices.h:345
DiagMatr1 getInlineDiagMatr1({ list })
void reportCompMatr2(CompMatr2 matrix)
Definition matrices.cpp:785
void reportDiagMatr1(DiagMatr1 matrix)
Definition matrices.cpp:787
void reportCompMatr(CompMatr matrix)
Definition matrices.cpp:786
void reportDiagMatr2(DiagMatr2 matrix)
Definition matrices.cpp:788
void reportCompMatr1(CompMatr1 matrix)
Definition matrices.cpp:784
void reportDiagMatr(DiagMatr matrix)
Definition matrices.cpp:789
void reportFullStateDiagMatr(FullStateDiagMatr matr)
Definition matrices.cpp:790
void setInlineDiagMatr(DiagMatr matr, int numQb, std::vector< qcomp > in)
void setFullStateDiagMatrFromMultiDimLists(FullStateDiagMatr out, void *lists, int *numQubitsPerDim, int numDims)
Definition matrices.cpp:730
void setDiagMatrFromMultiDimLists(DiagMatr out, void *lists, int *numQubitsPerDim, int numDims)
Definition matrices.cpp:708
void setFullStateDiagMatrFromMultiVarFunc(FullStateDiagMatr out, qcomp(*func)(qindex *), int *numQubitsPerVar, int numVars, int areSigned)
Definition matrices.cpp:694
void setInlineCompMatr(CompMatr matr, int numQb, std::vector< std::vector< qcomp > > in)
void setDiagMatr(DiagMatr out, qcomp *in)
Definition matrices.cpp:435
void setCompMatr(CompMatr matr, qcomp **vals)
Definition matrices.cpp:427
void setFullStateDiagMatr(FullStateDiagMatr out, qindex startInd, qcomp *in, qindex numElems)
Definition matrices.cpp:447
void setDiagMatrFromMultiVarFunc(DiagMatr out, qcomp(*func)(qindex *), int *numQubitsPerVar, int numVars, int areSigned)
Definition matrices.cpp:674
void setFullStateDiagMatrFromPauliStrSum(FullStateDiagMatr out, PauliStrSum in)
Definition matrices.cpp:641
void setInlineFullStateDiagMatr(FullStateDiagMatr matr, qindex startInd, qindex numElems, std::vector< qcomp > in)
void syncFullStateDiagMatr(FullStateDiagMatr matr)
Definition matrices.cpp:379
void syncDiagMatr(DiagMatr matr)
Definition matrices.cpp:378
void syncCompMatr(CompMatr matr)
Definition matrices.cpp:377
qmatrix getZeroMatrix(size_t dim)
Definition qmatrix.cpp:18
TEST_CASE("getCompMatr1", TEST_CATEGORY)
Definition matrices.cpp:51
int * wasGpuSynced
Definition matrices.h:108
int * isApproxNonZero
Definition matrices.h:166
int * isStrictlyNonNegative
Definition matrices.h:167
int * wasGpuSynced
Definition matrices.h:174