The Quantum Exact Simulation Toolkit v4.0.0
Loading...
Searching...
No Matches

Testing utilities which compare scalars produced by the QuEST API to those produced by other test utilities, and Quregs modified by the API to qvector qmatrix references. More...

Functions

bool doMatricesAgree (qmatrix a, qmatrix b)
 
bool doScalarsAgree (qcomp a, qcomp b)
 
qreal getTestAbsoluteEpsilon ()
 
qreal getTestRelativeEpsilon ()
 
void REQUIRE_AGREE (CompMatr matrix, qmatrix reference)
 
void REQUIRE_AGREE (CompMatr1 matrix, qmatrix reference)
 
void REQUIRE_AGREE (CompMatr2 matrix, qmatrix reference)
 
void REQUIRE_AGREE (DiagMatr matrix, qmatrix reference)
 
void REQUIRE_AGREE (DiagMatr1 matrix, qmatrix reference)
 
void REQUIRE_AGREE (DiagMatr2 matrix, qmatrix reference)
 
void REQUIRE_AGREE (qcomp scalar, qcomp reference)
 
void REQUIRE_AGREE (qmatrix matrix, qmatrix reference)
 
void REQUIRE_AGREE (qreal scalar, qreal reference)
 
void REQUIRE_AGREE (Qureg qureg, qmatrix reference)
 
void REQUIRE_AGREE (Qureg qureg, Qureg other)
 
void REQUIRE_AGREE (Qureg qureg, qvector reference)
 
void REQUIRE_AGREE (SuperOp matrix, qmatrix reference)
 
void REQUIRE_AGREE (vector< qcomp > list, vector< qcomp > reference)
 
void REQUIRE_AGREE (vector< qreal > list, vector< qreal > reference)
 

Detailed Description

Testing utilities which compare scalars produced by the QuEST API to those produced by other test utilities, and Quregs modified by the API to qvector qmatrix references.

Function Documentation

◆ doMatricesAgree()

bool doMatricesAgree ( qmatrix a,
qmatrix b )

Definition at line 81 of file compare.cpp.

81 {
82 DEMAND( a.size() == b.size() );
83
84 // assumed square and equal-size
85 size_t dim = a.size();
86
87 for (size_t i=0; i<dim; i++)
88 for (size_t j=0; j<dim; j++)
89 if (!doScalarsAgree(a[i][j], b[i][j]))
90 return false;
91
92 return true;
93}

◆ doScalarsAgree()

bool doScalarsAgree ( qcomp a,
qcomp b )

Definition at line 71 of file compare.cpp.

71 {
72
73 // permit absolute OR relative agreement
74
75 if (getAbsDif(a, b) <= ABSOLUTE_EPSILON)
76 return true;
77
78 return (getRelDif(a, b) <= RELATIVE_EPSILON);
79}

◆ getTestAbsoluteEpsilon()

qreal getTestAbsoluteEpsilon ( )

Definition at line 48 of file compare.cpp.

48 {
49
50 return ABSOLUTE_EPSILON;
51}

◆ getTestRelativeEpsilon()

qreal getTestRelativeEpsilon ( )

Definition at line 53 of file compare.cpp.

53 {
54
55 return RELATIVE_EPSILON;
56}

◆ REQUIRE_AGREE() [1/15]

void REQUIRE_AGREE ( CompMatr matrix,
qmatrix reference )

Definition at line 256 of file compare.cpp.

256{ REQUIRE_AGREE( getMatrix(matrix), reference ); }

◆ REQUIRE_AGREE() [2/15]

void REQUIRE_AGREE ( CompMatr1 matrix,
qmatrix reference )

Definition at line 254 of file compare.cpp.

254{ REQUIRE_AGREE( getMatrix(matrix), reference ); }

◆ REQUIRE_AGREE() [3/15]

void REQUIRE_AGREE ( CompMatr2 matrix,
qmatrix reference )

Definition at line 255 of file compare.cpp.

255{ REQUIRE_AGREE( getMatrix(matrix), reference ); }

◆ REQUIRE_AGREE() [4/15]

void REQUIRE_AGREE ( DiagMatr matrix,
qmatrix reference )

Definition at line 259 of file compare.cpp.

259{ REQUIRE_AGREE( getMatrix(matrix), reference ); }

◆ REQUIRE_AGREE() [5/15]

void REQUIRE_AGREE ( DiagMatr1 matrix,
qmatrix reference )

Definition at line 257 of file compare.cpp.

257{ REQUIRE_AGREE( getMatrix(matrix), reference ); }

◆ REQUIRE_AGREE() [6/15]

void REQUIRE_AGREE ( DiagMatr2 matrix,
qmatrix reference )

Definition at line 258 of file compare.cpp.

258{ REQUIRE_AGREE( getMatrix(matrix), reference ); }

◆ REQUIRE_AGREE() [7/15]

void REQUIRE_AGREE ( qcomp scalar,
qcomp reference )

Definition at line 177 of file compare.cpp.

177 {
178
179 if (!doScalarsAgree(scalar, reference))
180 REPORT_SCALAR_AND_FAIL(scalar, reference);
181
182 SUCCEED( );
183}

◆ REQUIRE_AGREE() [8/15]

void REQUIRE_AGREE ( qmatrix matrix,
qmatrix reference )

Definition at line 240 of file compare.cpp.

240 {
241 DEMAND( matrix.size() == reference.size() );
242
243 size_t dim = matrix.size();
244
245 for (size_t r=0; r<dim; r++)
246 for (size_t c=0; c<dim; c++)
247 if (!doScalarsAgree(matrix[r][c], reference[r][c]))
248 REPORT_ELEM_AND_FAIL(r, c, matrix[r][c], reference[r][c]);
249
250 SUCCEED( );
251}

◆ REQUIRE_AGREE() [9/15]

void REQUIRE_AGREE ( qreal scalar,
qreal reference )

Definition at line 185 of file compare.cpp.

185 {
186
187 if (!doScalarsAgree(qcomp(scalar,0), qcomp(reference,0)))
188 REPORT_SCALAR_AND_FAIL(scalar, reference);
189
190 SUCCEED( );
191}

◆ REQUIRE_AGREE() [10/15]

void REQUIRE_AGREE ( Qureg qureg,
qmatrix reference )

Definition at line 131 of file compare.cpp.

131 {
132 DEMAND( q.isDensityMatrix );
133 DEMAND( getPow2(q.numQubits) == (qindex) m1.size() );
134
135 qmatrix m2 = getMatrix(q);
136
137 for (size_t i=0; i<m1.size(); i++)
138 for (size_t j=0; j<m1.size(); j++)
139 if (!doScalarsAgree(m1[i][j], m2[i][j]))
140 REPORT_AMP_AND_FAIL(j*m1.size()+i, m2[i][j], m1[i][j]);
141
142 SUCCEED( );
143}

◆ REQUIRE_AGREE() [11/15]

void REQUIRE_AGREE ( Qureg qureg,
Qureg other )

Definition at line 271 of file compare.cpp.

271 {
272 DEMAND( qureg.numQubits == other.numQubits );
273 DEMAND( qureg.isDensityMatrix == other.isDensityMatrix );
274
275 return (qureg.isDensityMatrix)?
276 REQUIRE_AGREE( qureg, getMatrix(other) ):
277 REQUIRE_AGREE( qureg, getVector(other) );
278}

◆ REQUIRE_AGREE() [12/15]

void REQUIRE_AGREE ( Qureg qureg,
qvector reference )

Definition at line 117 of file compare.cpp.

117 {
118 DEMAND( !q.isDensityMatrix );
119 DEMAND( q.numAmps == (qindex) v1.size() );
120
121 qvector v2 = getVector(q);
122
123 for (size_t i=0; i<v1.size(); i++)
124 if (!doScalarsAgree(v1[i], v2[i]))
125 REPORT_AMP_AND_FAIL(i, v2[i], v1[i]);
126
127 SUCCEED( );
128}

◆ REQUIRE_AGREE() [13/15]

void REQUIRE_AGREE ( SuperOp matrix,
qmatrix reference )

Definition at line 260 of file compare.cpp.

260{ REQUIRE_AGREE( getMatrix(matrix), reference ); }

◆ REQUIRE_AGREE() [14/15]

void REQUIRE_AGREE ( vector< qcomp > list,
vector< qcomp > reference )

Definition at line 211 of file compare.cpp.

211 {
212 DEMAND( apiList.size() == refList.size() );
213
214 for (size_t i=0; i<apiList.size(); i++)
215 if (!doScalarsAgree(apiList[i], refList[i]))
216 REPORT_SCALAR_AND_FAIL(apiList[i], refList[i]);
217
218 SUCCEED( );
219}

◆ REQUIRE_AGREE() [15/15]

void REQUIRE_AGREE ( vector< qreal > list,
vector< qreal > reference )

Definition at line 200 of file compare.cpp.

200 {
201 DEMAND( apiList.size() == refList.size() );
202
203 for (size_t i=0; i<apiList.size(); i++)
204 if (!doScalarsAgree(apiList[i], refList[i]))
205 REPORT_SCALAR_AND_FAIL(apiList[i], refList[i]);
206
207 SUCCEED( );
208}