12#include <catch2/catch_test_macros.hpp>
13#include <catch2/matchers/catch_matchers_string.hpp>
14#include <catch2/generators/catch_generators_range.hpp>
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"
30using Catch::Matchers::ContainsSubstring;
38#define TEST_CATEGORY \
39 LABEL_UNIT_TAG "[matrices]"
53 SECTION( LABEL_CORRECTNESS ) {
55 constexpr int dim = 2;
56 qmatrix ref = getRandomMatrix(dim);
58 SECTION( LABEL_C_INTERFACE ) {
61 qcomp arr[dim][dim] = {{ref[0][0], ref[0][1]}, {ref[1][0], ref[1][1]}};
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];
75 for (
int i=0; i<dim; i++)
80 for (
int i=0; i<dim; i++)
85 SECTION( LABEL_CPP_INTERFACE ) {
91 REQUIRE_AGREE(
getCompMatr1({{ref[0][0],ref[0][1]},{ref[1][0],ref[1][1]}}), ref );
95 SECTION( LABEL_VALIDATION ) {
97 SECTION(
"null pointer" ) {
99 qcomp** ptr =
nullptr;
100 REQUIRE_THROWS_WITH(
getCompMatr1(ptr), ContainsSubstring(
"was a null pointer") );
102 qcomp* arr[1] = {
nullptr};
103 REQUIRE_THROWS_WITH(
getCompMatr1(arr), ContainsSubstring(
"contained a null pointer") );
106 SECTION(
"invalid dimensions" ) {
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") );
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") );
120TEST_CASE(
"getCompMatr2", TEST_CATEGORY ) {
122 SECTION( LABEL_CORRECTNESS ) {
124 constexpr int dim = 4;
125 qmatrix ref = getRandomMatrix(dim);
127 SECTION( LABEL_C_INTERFACE ) {
131 for (
int i=0; i<dim; i++)
132 for (
int j=0; j<dim; j++)
133 arr[i][j] = ref[i][j];
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];
147 for (
int i=0; i<dim; i++)
152 for (
int i=0; i<dim; i++)
157 SECTION( LABEL_CPP_INTERFACE ) {
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]}
175 SECTION( LABEL_VALIDATION ) {
177 SECTION(
"null pointer" ) {
179 qcomp** ptr =
nullptr;
180 REQUIRE_THROWS_WITH(
getCompMatr2(ptr), ContainsSubstring(
"was a null pointer") );
182 qcomp* arr[1] = {
nullptr};
183 REQUIRE_THROWS_WITH(
getCompMatr2(arr), ContainsSubstring(
"contained a null pointer") );
186 SECTION(
"invalid dimensions" ) {
190 qmatrix bad1 = {{0,0,0,0}};
191 qmatrix bad2 = {{0,0,0,0},{0,0,0,0},{0,0,0,0}};
193 REQUIRE_THROWS_WITH(
getCompMatr2(bad1), ContainsSubstring(
"Incompatible number of rows") );
194 REQUIRE_THROWS_WITH(
getCompMatr2(bad2), ContainsSubstring(
"Incompatible number of rows") );
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") );
203TEST_CASE(
"getDiagMatr1", TEST_CATEGORY ) {
205 SECTION( LABEL_CORRECTNESS ) {
207 constexpr int dim = 2;
208 qmatrix ref = getRandomDiagonalMatrix(dim);
210 SECTION( LABEL_C_INTERFACE ) {
213 qcomp arr[dim] = {ref[0][0], ref[1][1] };
217 qvector diags = getDiagonals(ref);
221 SECTION( LABEL_CPP_INTERFACE ) {
224 REQUIRE_AGREE(
getDiagMatr1({ref[0][0],ref[1][1]}), ref );
228 SECTION( LABEL_VALIDATION ) {
230 SECTION(
"null pointer" ) {
232 qcomp* ptr =
nullptr;
233 REQUIRE_THROWS_WITH(
getDiagMatr1(ptr), ContainsSubstring(
"was a null pointer") );
236 SECTION(
"invalid dimensions" ) {
240 qvector bad2 = {0,0,0};
242 REQUIRE_THROWS_WITH(
getDiagMatr1(bad1), ContainsSubstring(
"Incompatible number of elements") );
243 REQUIRE_THROWS_WITH(
getDiagMatr1(bad2), ContainsSubstring(
"Incompatible number of elements") );
249TEST_CASE(
"getDiagMatr2", TEST_CATEGORY ) {
251 SECTION( LABEL_CORRECTNESS ) {
253 constexpr int dim = 4;
254 qmatrix ref = getRandomDiagonalMatrix(dim);
256 SECTION( LABEL_C_INTERFACE ) {
259 qcomp arr[dim] = {ref[0][0], ref[1][1], ref[2][2], ref[3][3] };
263 qvector diags = getDiagonals(ref);
267 SECTION( LABEL_CPP_INTERFACE ) {
270 REQUIRE_AGREE(
getDiagMatr2({ref[0][0], ref[1][1], ref[2][2], ref[3][3] }), ref );
274 SECTION( LABEL_VALIDATION ) {
276 SECTION(
"null pointer" ) {
278 qcomp* ptr =
nullptr;
279 REQUIRE_THROWS_WITH(
getDiagMatr2(ptr), ContainsSubstring(
"was a null pointer") );
282 SECTION(
"invalid dimensions" ) {
285 qvector bad1 = {0,0,0};
286 qvector bad2 = {0,0,0,0,0};
288 REQUIRE_THROWS_WITH(
getDiagMatr2(bad1), ContainsSubstring(
"Incompatible number of elements") );
289 REQUIRE_THROWS_WITH(
getDiagMatr2(bad2), ContainsSubstring(
"Incompatible number of elements") );
295TEST_CASE(
"getInlineCompMatr1", TEST_CATEGORY ) {
297 SECTION( LABEL_CORRECTNESS ) {
299 qmatrix ref = {{1,2},{3_i,4_i}};
304 SECTION( LABEL_VALIDATION ) {
306 SECTION(
"invalid dimensions" ) {
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") );
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") );
320TEST_CASE(
"getInlineCompMatr2", TEST_CATEGORY ) {
322 SECTION( LABEL_CORRECTNESS ) {
328 {-1_i,-2_i,-3_i,-4_i}};
335 {-1_i,-2_i,-3_i,-4_i}
339 SECTION( LABEL_VALIDATION ) {
341 SECTION(
"invalid dimensions" ) {
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") );
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") );
355TEST_CASE(
"getInlineDiagMatr1", TEST_CATEGORY ) {
357 SECTION( LABEL_CORRECTNESS ) {
359 qmatrix ref = getDiagonalMatrix({1,2_i});
364 SECTION( LABEL_VALIDATION ) {
366 SECTION(
"invalid dimensions" ) {
368 REQUIRE_THROWS_WITH(
getInlineDiagMatr1({0,0,0}), ContainsSubstring(
"Incompatible number of elements") );
374TEST_CASE(
"getInlineDiagMatr2", TEST_CATEGORY ) {
376 SECTION( LABEL_CORRECTNESS ) {
378 qmatrix ref = getDiagonalMatrix({1,2_i,-3,-4_i});
383 SECTION( LABEL_VALIDATION ) {
385 SECTION(
"invalid dimensions" ) {
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") );
394TEST_CASE(
"createCompMatr", TEST_CATEGORY ) {
396 SECTION( LABEL_CORRECTNESS ) {
400 int maxNumQubits = getNumCachedQubits();
401 int numQubits = GENERATE_COPY( range(1, maxNumQubits+1) );
402 CAPTURE( numQubits );
408 REQUIRE_AGREE( matr, blank );
412 REQUIRE( matr.
numRows == getPow2(numQubits) );
420 REQUIRE( matr.
cpuElems !=
nullptr );
431 SECTION( LABEL_VALIDATION ) {
433 SECTION(
"env not initialised" ) {
439 SECTION(
"too few qubits" ) {
441 int numQubits = GENERATE( -1, 0 );
443 REQUIRE_THROWS_WITH(
createCompMatr(numQubits), ContainsSubstring(
"must target one or more qubits") );
446 SECTION(
"too many qubits" ) {
449 REQUIRE_THROWS_WITH(
createCompMatr(50), ContainsSubstring(
"maximum which can be addressed by the qindex type") );
452 REQUIRE_THROWS_WITH(
createCompMatr(31), ContainsSubstring(
"necessary memory would overflow size_t") );
458 #ifndef SANITIZER_IS_ACTIVE
460 ContainsSubstring(
"failed") ||
461 ContainsSubstring(
"insufficient available memory") ||
462 ContainsSubstring(
"available GPU memory") ||
463 ContainsSubstring(
"exceeds the available RAM") );
470TEST_CASE(
"createDiagMatr", TEST_CATEGORY ) {
472 SECTION( LABEL_CORRECTNESS ) {
476 int maxNumQubits = getNumCachedQubits();
477 int numQubits = GENERATE_COPY( range(1, maxNumQubits+1) );
478 CAPTURE( numQubits );
484 REQUIRE_AGREE( matr, blank );
488 REQUIRE( matr.
numElems == getPow2(numQubits) );
498 REQUIRE( matr.
cpuElems !=
nullptr );
501 REQUIRE( matr.
gpuElems !=
nullptr );
503 REQUIRE( matr.
gpuElems ==
nullptr );
508 SECTION( LABEL_VALIDATION ) {
510 SECTION(
"env not initialised" ) {
516 SECTION(
"too few qubits" ) {
518 int numQubits = GENERATE( -1, 0 );
520 REQUIRE_THROWS_WITH(
createDiagMatr(numQubits), ContainsSubstring(
"must target one or more qubits") );
523 SECTION(
"too many qubits" ) {
526 REQUIRE_THROWS_WITH(
createDiagMatr(100), ContainsSubstring(
"maximum which can be addressed by the qindex type") );
529 REQUIRE_THROWS_WITH(
createDiagMatr(62), ContainsSubstring(
"necessary memory would overflow size_t") );
535 #ifndef SANITIZER_IS_ACTIVE
537 ContainsSubstring(
"failed") ||
538 ContainsSubstring(
"insufficient available memory") ||
539 ContainsSubstring(
"available GPU memory") ||
540 ContainsSubstring(
"exceeds the available RAM") );
547TEST_CASE(
"createFullStateDiagMatr", TEST_CATEGORY ) {
549 SECTION( LABEL_CORRECTNESS ) {
551 int numQubits = GENERATE_COPY( range(1, 20) );
552 CAPTURE( numQubits );
560 isBlank = (matr.
cpuElems[i] == qcomp(0,0));
565 REQUIRE( matr.
numElems == getPow2(numQubits) );
576 REQUIRE( matr.
cpuElems !=
nullptr );
579 if (gpu) REQUIRE( matr.
gpuElems !=
nullptr );
580 else REQUIRE( matr.
gpuElems ==
nullptr );
585 SECTION( LABEL_VALIDATION ) {
587 SECTION(
"env not initialised" ) {
593 SECTION(
"too few qubits" ) {
595 int numQubits = GENERATE( -1, 0 );
597 REQUIRE_THROWS_WITH(
createFullStateDiagMatr(numQubits), ContainsSubstring(
"must target one or more qubits") );
600 SECTION(
"too many qubits" ) {
603 REQUIRE_THROWS_WITH(
createFullStateDiagMatr(100), ContainsSubstring(
"maximum which can be addressed by the qindex type") );
612 #ifndef SANITIZER_IS_ACTIVE
614 ContainsSubstring(
"failed") ||
615 ContainsSubstring(
"insufficient available memory") ||
616 ContainsSubstring(
"available GPU memory") ||
617 ContainsSubstring(
"exceeds the available RAM") ||
618 ContainsSubstring(
"exceeds the local available RAM") );
628TEST_CASE(
"createCustomFullStateDiagMatr", TEST_CATEGORY ) {
630 SECTION( LABEL_CORRECTNESS ) {
632 for (
auto [label, mpi, gpu, omp] : getSupportedDeployments()) {
634 DYNAMIC_SECTION( label ) {
636 int minNumQubits = std::max({1, getLog2(
getQuESTEnv().numNodes)});
637 int maxNumQubits = std::min({20, minNumQubits + 1});
638 int numQubits = GENERATE_COPY( range(minNumQubits, maxNumQubits+1) );
639 CAPTURE( numQubits );
646 isBlank = (matr.
cpuElems[i] == qcomp(0,0));
651 REQUIRE( matr.
numElems == getPow2(numQubits) );
667 REQUIRE( matr.
cpuElems !=
nullptr );
669 if (gpu) REQUIRE( matr.
gpuElems !=
nullptr );
670 else REQUIRE( matr.
gpuElems ==
nullptr );
678 SECTION( LABEL_VALIDATION ) {
680 SECTION(
"env not initialised" ) {
686 SECTION(
"too few qubits" ) {
688 int numQubits = GENERATE( -1, 0 );
690 for (
auto [label, mpi, gpu, omp] : getSupportedDeployments())
694 int minNumQubits = getLog2(
getQuESTEnv().numNodes);
699 SECTION(
"too many qubits" ) {
701 for (
auto [label, mpi, gpu, omp] : getSupportedDeployments()) {
704 REQUIRE_THROWS_WITH(
createCustomFullStateDiagMatr(100, mpi,gpu,omp), ContainsSubstring(
"maximum which can be addressed by the qindex type") );
713 #ifndef SANITIZER_IS_ACTIVE
715 ContainsSubstring(
"failed") ||
716 ContainsSubstring(
"insufficient available memory") ||
717 ContainsSubstring(
"available GPU memory") ||
718 ContainsSubstring(
"exceeds the available RAM") ||
719 ContainsSubstring(
"exceeds the local available RAM") );
724 SECTION(
"unsupported deployments" ) {
739TEST_CASE(
"destroyCompMatr", TEST_CATEGORY ) {
741 SECTION( LABEL_CORRECTNESS ) {
747 SECTION( LABEL_VALIDATION ) {
750 #ifndef SANITIZER_IS_ACTIVE
751 SECTION(
"not created" ) {
754 REQUIRE_THROWS_WITH(
destroyCompMatr(m), ContainsSubstring(
"Invalid CompMatr") && ContainsSubstring(
"not created") );
761TEST_CASE(
"destroyDiagMatr", TEST_CATEGORY ) {
763 SECTION( LABEL_CORRECTNESS ) {
769 SECTION( LABEL_VALIDATION ) {
772 #ifndef SANITIZER_IS_ACTIVE
773 SECTION(
"not created" ) {
776 REQUIRE_THROWS_WITH(
destroyDiagMatr(m), ContainsSubstring(
"Invalid DiagMatr") && ContainsSubstring(
"not created") );
783TEST_CASE(
"destroyFullStateDiagMatr", TEST_CATEGORY ) {
785 SECTION( LABEL_CORRECTNESS ) {
791 SECTION( LABEL_VALIDATION ) {
794 #ifndef SANITIZER_IS_ACTIVE
795 SECTION(
"not created" ) {
805TEST_CASE(
"syncCompMatr", TEST_CATEGORY ) {
807 SECTION( LABEL_CORRECTNESS ) {
813 SECTION(
"overwrites GPU elements" ) {
823 SECTION(
"sets was-synced flag" ) {
831 SECTION(
"clears numerical flags" ) {
833 *(matr).isApproxHermitian = 1;
834 *(matr).isApproxUnitary = 0;
844 SECTION( LABEL_VALIDATION ) {
847 #ifndef SANITIZER_IS_ACTIVE
848 SECTION(
"not created" ) {
851 REQUIRE_THROWS_WITH(
syncCompMatr(m), ContainsSubstring(
"Invalid CompMatr") && ContainsSubstring(
"not created") );
858TEST_CASE(
"syncDiagMatr", TEST_CATEGORY ) {
860 SECTION( LABEL_CORRECTNESS ) {
865 SECTION(
"overwrites GPU elements" ) {
875 SECTION(
"sets was-synced flag" ) {
883 SECTION(
"clears numerical flags" ) {
885 *(matr).isApproxHermitian = 1;
886 *(matr).isApproxUnitary = 0;
887 *(matr).isApproxNonZero = 1;
888 *(matr).isStrictlyNonNegative = 0;
900 SECTION( LABEL_VALIDATION ) {
903 #ifndef SANITIZER_IS_ACTIVE
904 SECTION(
"not created" ) {
907 REQUIRE_THROWS_WITH(
syncDiagMatr(m), ContainsSubstring(
"Invalid DiagMatr") && ContainsSubstring(
"not created") );
914TEST_CASE(
"syncFullStateDiagMatr", TEST_CATEGORY ) {
916 SECTION( LABEL_CORRECTNESS ) {
918 for (
auto& [label, matrix]: getCachedFullStateDiagMatrs()) {
920 DYNAMIC_SECTION( label ) {
922 *(matrix.wasGpuSynced) = 0;
923 *(matrix).isApproxHermitian = 1;
924 *(matrix).isApproxUnitary = 0;
925 *(matrix).isApproxNonZero = 1;
926 *(matrix).isStrictlyNonNegative = 0;
929 REQUIRE( *(matrix.wasGpuSynced) == 1 );
931 REQUIRE( *(matrix.isApproxHermitian) == -1 );
932 REQUIRE( *(matrix.isApproxUnitary) == -1 );
933 REQUIRE( *(matrix.isApproxNonZero) == -1 );
934 REQUIRE( *(matrix.isStrictlyNonNegative) == -1 );
944 SECTION( LABEL_VALIDATION ) {
947 #ifndef SANITIZER_IS_ACTIVE
948 SECTION(
"not created" ) {
960 SECTION( LABEL_CORRECTNESS ) {
962 int numQubits = GENERATE( range(1,6) );
963 CAPTURE( numQubits );
968 int dim = getPow2(numQubits);
969 qmatrix ref = getRandomMatrix(dim);
971 SECTION( LABEL_C_INTERFACE ) {
974 qcomp** ptrs = (qcomp**) malloc(dim *
sizeof *ptrs);
975 for (
int i=0; i<dim; i++) {
976 ptrs[i] = (qcomp*) malloc(dim *
sizeof **ptrs);
977 for (
int j=0; j<dim; j++)
978 ptrs[i][j] = ref[i][j];
981 REQUIRE_AGREE( matr, ref );
987 for (
int i=0; i<dim; i++)
992 SECTION( LABEL_CPP_INTERFACE ) {
997 REQUIRE_AGREE( matr, ref );
1004 SECTION( LABEL_VALIDATION ) {
1011 #ifndef SANITIZER_IS_ACTIVE
1012 SECTION(
"not created" ) {
1016 REQUIRE_THROWS_WITH(
setCompMatr(bad, dummy), ContainsSubstring(
"Invalid CompMatr") && ContainsSubstring(
"not created") );
1021 SECTION(
"null pointer" ) {
1023 qcomp** ptr =
nullptr;
1024 REQUIRE_THROWS_WITH(
setCompMatr(matr, ptr), ContainsSubstring(
"was a null pointer") );
1026 qcomp* arr[1] = {
nullptr};
1027 REQUIRE_THROWS_WITH(
setCompMatr(matr, arr), ContainsSubstring(
"contained a null pointer") );
1030 SECTION(
"invalid dimensions" ) {
1034 REQUIRE_NOTHROW(
setCompMatr(matr, {{1,2},{3,4}}) );
1036 REQUIRE_THROWS_WITH(
setCompMatr(matr,{{1,2}}), ContainsSubstring(
"Incompatible number of rows") );
1037 REQUIRE_THROWS_WITH(
setCompMatr(matr, {{1,2},{3,4},{5,6}}), ContainsSubstring(
"Incompatible number of rows") );
1039 REQUIRE_THROWS_WITH(
setCompMatr(matr, {{0,0},{0}}), ContainsSubstring(
"incompatible number of elements") );
1040 REQUIRE_THROWS_WITH(
setCompMatr(matr, {{0,0},{0,0,0}}), ContainsSubstring(
"incompatible number of elements") );
1048TEST_CASE(
"setDiagMatr", TEST_CATEGORY ) {
1050 SECTION( LABEL_CORRECTNESS ) {
1052 int numQubits = GENERATE( range(1,6) );
1053 CAPTURE( numQubits );
1058 int dim = getPow2(numQubits);
1059 qmatrix ref = getRandomDiagonalMatrix(dim);
1061 SECTION( LABEL_C_INTERFACE ) {
1064 qvector diags = getDiagonals(ref);
1066 REQUIRE_AGREE( matr, ref );
1070 SECTION( LABEL_CPP_INTERFACE ) {
1075 REQUIRE_AGREE( matr, ref );
1082 SECTION( LABEL_VALIDATION ) {
1087 #ifndef SANITIZER_IS_ACTIVE
1088 SECTION(
"not created" ) {
1092 REQUIRE_THROWS_WITH(
setDiagMatr(bad, dummy), ContainsSubstring(
"Invalid DiagMatr") && ContainsSubstring(
"not created") );
1096 SECTION(
"null pointer" ) {
1098 qcomp* ptr =
nullptr;
1099 REQUIRE_THROWS_WITH(
setDiagMatr(matr, ptr), ContainsSubstring(
"was a null pointer") );
1102 SECTION(
"invalid dimensions" ) {
1108 REQUIRE_THROWS_WITH(
setDiagMatr(matr, {1}), ContainsSubstring(
"Incompatible number of elements") );
1109 REQUIRE_THROWS_WITH(
setDiagMatr(matr, {1,2,3}), ContainsSubstring(
"Incompatible number of elements") );
1119 SECTION( LABEL_CORRECTNESS ) {
1124 setInlineCompMatr( matr, 1, {{1,2},{3,4}} );
1125 REQUIRE_AGREE( matr, {{1,2},{3,4}} );
1131 SECTION( LABEL_VALIDATION ) {
1138 #ifndef SANITIZER_IS_ACTIVE
1139 SECTION(
"not created" ) {
1142 REQUIRE_THROWS_WITH( setInlineCompMatr(bad, 1, {{1,2},{3,4}}), ContainsSubstring(
"Invalid CompMatr") && ContainsSubstring(
"not created") );
1147 SECTION(
"mismatching dimension" ) {
1149 REQUIRE_THROWS_WITH( setInlineCompMatr(matr, 2, {{1,2},{3,4}}), ContainsSubstring(
"declared number of qubits") && ContainsSubstring(
"differs") );
1152 SECTION(
"invalid dimensions" ) {
1156 REQUIRE_NOTHROW( setInlineCompMatr(matr, 1, {{1,2},{3,4}}) );
1158 REQUIRE_THROWS_WITH( setInlineCompMatr(matr, 1, {{1,2}}), ContainsSubstring(
"Incompatible number of rows") );
1159 REQUIRE_THROWS_WITH( setInlineCompMatr(matr, 1, {{1,2},{3,4},{5,6}}), ContainsSubstring(
"Incompatible number of rows") );
1161 REQUIRE_THROWS_WITH( setInlineCompMatr(matr, 1, {{1},{2}}), ContainsSubstring(
"One or more rows contained an incompatible number of elements") );
1162 REQUIRE_THROWS_WITH( setInlineCompMatr(matr, 1, {{1,2,3},{4,5,6}}), ContainsSubstring(
"One or more rows contained an incompatible number of elements") );
1172 SECTION( LABEL_CORRECTNESS ) {
1177 setInlineDiagMatr( matr, 1, {1,2_i} );
1178 REQUIRE_AGREE( matr, {{1,0},{0,2_i}} );
1184 SECTION( LABEL_VALIDATION ) {
1191 #ifndef SANITIZER_IS_ACTIVE
1192 SECTION(
"not created" ) {
1195 REQUIRE_THROWS_WITH( setInlineDiagMatr(bad, 1, {1,2}), ContainsSubstring(
"Invalid DiagMatr") && ContainsSubstring(
"not created") );
1200 SECTION(
"mismatching dimension" ) {
1202 REQUIRE_THROWS_WITH( setInlineDiagMatr(matr, 2, {1,2}), ContainsSubstring(
"declared number of qubits") && ContainsSubstring(
"differs") );
1205 SECTION(
"invalid dimensions" ) {
1209 REQUIRE_NOTHROW( setInlineDiagMatr(matr, 1, {1,2}) );
1211 REQUIRE_THROWS_WITH( setInlineDiagMatr(matr, 1, {1}), ContainsSubstring(
"Incompatible number of elements") );
1212 REQUIRE_THROWS_WITH( setInlineDiagMatr(matr, 1, {1,2,3}), ContainsSubstring(
"Incompatible number of elements") );
1220TEST_CASE(
"createInlineCompMatr", TEST_CATEGORY ) {
1222 SECTION( LABEL_CORRECTNESS ) {
1224 CompMatr matr = createInlineCompMatr(1, {{1,2},{3,4}});
1226 REQUIRE_AGREE( matr, {{1,2},{3,4}} );
1232 SECTION( LABEL_VALIDATION ) {
1234 SECTION(
"env not initialised" ) {
1240 SECTION(
"too few qubits" ) {
1242 int numQubits = GENERATE( -1, 0 );
1244 REQUIRE_THROWS_WITH( createInlineCompMatr(numQubits, {{1}}), ContainsSubstring(
"must target one or more qubits") );
1247 SECTION(
"mismatching dimension" ) {
1249 REQUIRE_THROWS_WITH( createInlineCompMatr(2, {{1,2},{3,4}}), ContainsSubstring(
"Incompatible number of rows") );
1255TEST_CASE(
"createInlineDiagMatr", TEST_CATEGORY ) {
1257 SECTION( LABEL_CORRECTNESS ) {
1259 DiagMatr matr = createInlineDiagMatr(1, {1,2_i});
1261 REQUIRE_AGREE( matr, {{1,0},{0,2_i}} );
1267 SECTION( LABEL_VALIDATION ) {
1269 SECTION(
"env not initialised" ) {
1275 SECTION(
"too few qubits" ) {
1277 int numQubits = GENERATE( -1, 0 );
1279 REQUIRE_THROWS_WITH( createInlineDiagMatr(numQubits, {1}), ContainsSubstring(
"must target one or more qubits") );
1282 SECTION(
"mismatching dimension" ) {
1284 REQUIRE_THROWS_WITH( createInlineDiagMatr(2, {1,2}), ContainsSubstring(
"Incompatible number of elements") );
1303void setInlineFullStateDiagMatr(
FullStateDiagMatr matr, qindex startInd, qindex numElems, std::vector<qcomp> in);
FullStateDiagMatr createCustomFullStateDiagMatr(int numQubits, int useDistrib, int useGpuAccel, int useMultithread)
FullStateDiagMatr createFullStateDiagMatr(int numQubits)
CompMatr createCompMatr(int numQubits)
DiagMatr createDiagMatr(int numQubits)
FullStateDiagMatr createFullStateDiagMatrFromPauliStrSum(PauliStrSum in)
void destroyDiagMatr(DiagMatr matrix)
void destroyFullStateDiagMatr(FullStateDiagMatr matrix)
void destroyCompMatr(CompMatr matrix)
static CompMatr2 getCompMatr2(qcomp **in)
static CompMatr1 getCompMatr1(qcomp **in)
static DiagMatr2 getDiagMatr2(qcomp *in)
CompMatr1 getInlineCompMatr1({{ matrix }})
CompMatr2 getInlineCompMatr2({{ matrix }})
DiagMatr2 getInlineDiagMatr2({ list })
static DiagMatr1 getDiagMatr1(qcomp *in)
DiagMatr1 getInlineDiagMatr1({ list })
void reportCompMatr2(CompMatr2 matrix)
void reportDiagMatr1(DiagMatr1 matrix)
void reportCompMatr(CompMatr matrix)
void reportDiagMatr2(DiagMatr2 matrix)
void reportCompMatr1(CompMatr1 matrix)
void reportDiagMatr(DiagMatr matrix)
void reportFullStateDiagMatr(FullStateDiagMatr matr)
void setFullStateDiagMatrFromMultiDimLists(FullStateDiagMatr out, void *lists, int *numQubitsPerDim, int numDims)
void setDiagMatrFromMultiDimLists(DiagMatr out, void *lists, int *numQubitsPerDim, int numDims)
void setFullStateDiagMatrFromMultiVarFunc(FullStateDiagMatr out, qcomp(*func)(qindex *), int *numQubitsPerVar, int numVars, int areSigned)
void setDiagMatr(DiagMatr out, qcomp *in)
void setCompMatr(CompMatr matr, qcomp **vals)
void setFullStateDiagMatr(FullStateDiagMatr out, qindex startInd, qcomp *in, qindex numElems)
void setDiagMatrFromMultiVarFunc(DiagMatr out, qcomp(*func)(qindex *), int *numQubitsPerVar, int numVars, int areSigned)
void setFullStateDiagMatrFromPauliStrSum(FullStateDiagMatr out, PauliStrSum in)
void syncFullStateDiagMatr(FullStateDiagMatr matr)
void syncDiagMatr(DiagMatr matr)
void syncCompMatr(CompMatr matr)
qmatrix getZeroMatrix(size_t dim)
TEST_CASE("getCompMatr1", TEST_CATEGORY)
int * isStrictlyNonNegative
int * isStrictlyNonNegative