The Quantum Exact Simulation Toolkit v4.3.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)
 
void setTestAbsoluteEpsilon (qreal eps)
 
void setTestEpsilon (qreal eps)
 
void setTestRelativeEpsilon (qreal eps)
 

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 95 of file compare.cpp.

95 {
96 DEMAND( a.size() == b.size() );
97
98 // assumed square and equal-size
99 size_t dim = a.size();
100
101 for (size_t i=0; i<dim; i++)
102 for (size_t j=0; j<dim; j++)
103 if (!doScalarsAgree(a[i][j], b[i][j]))
104 return false;
105
106 return true;
107}

◆ doScalarsAgree()

bool doScalarsAgree ( qcomp a,
qcomp b )

Definition at line 85 of file compare.cpp.

85 {
86
87 // permit absolute OR relative agreement
88
89 if (getAbsDif(a, b) <= absoluteEpsilon)
90 return true;
91
92 return (getRelDif(a, b) <= relativeEpsilon);
93}

◆ getTestAbsoluteEpsilon()

qreal getTestAbsoluteEpsilon ( )

Definition at line 48 of file compare.cpp.

48 {
49
50 return absoluteEpsilon;
51}

◆ getTestRelativeEpsilon()

qreal getTestRelativeEpsilon ( )

Definition at line 53 of file compare.cpp.

53 {
54
55 return relativeEpsilon;
56}

◆ REQUIRE_AGREE() [1/15]

void REQUIRE_AGREE ( CompMatr matrix,
qmatrix reference )

Definition at line 270 of file compare.cpp.

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

◆ REQUIRE_AGREE() [2/15]

void REQUIRE_AGREE ( CompMatr1 matrix,
qmatrix reference )

Definition at line 268 of file compare.cpp.

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

◆ REQUIRE_AGREE() [3/15]

void REQUIRE_AGREE ( CompMatr2 matrix,
qmatrix reference )

Definition at line 269 of file compare.cpp.

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

◆ REQUIRE_AGREE() [4/15]

void REQUIRE_AGREE ( DiagMatr matrix,
qmatrix reference )

Definition at line 273 of file compare.cpp.

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

◆ REQUIRE_AGREE() [5/15]

void REQUIRE_AGREE ( DiagMatr1 matrix,
qmatrix reference )

Definition at line 271 of file compare.cpp.

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

◆ REQUIRE_AGREE() [6/15]

void REQUIRE_AGREE ( DiagMatr2 matrix,
qmatrix reference )

Definition at line 272 of file compare.cpp.

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

◆ REQUIRE_AGREE() [7/15]

void REQUIRE_AGREE ( qcomp scalar,
qcomp reference )

Definition at line 191 of file compare.cpp.

191 {
192
193 if (!doScalarsAgree(scalar, reference))
194 REPORT_SCALAR_AND_FAIL(scalar, reference);
195
196 SUCCEED( );
197}

◆ REQUIRE_AGREE() [8/15]

void REQUIRE_AGREE ( qmatrix matrix,
qmatrix reference )

Definition at line 254 of file compare.cpp.

254 {
255 DEMAND( matrix.size() == reference.size() );
256
257 size_t dim = matrix.size();
258
259 for (size_t r=0; r<dim; r++)
260 for (size_t c=0; c<dim; c++)
261 if (!doScalarsAgree(matrix[r][c], reference[r][c]))
262 REPORT_ELEM_AND_FAIL(r, c, matrix[r][c], reference[r][c]);
263
264 SUCCEED( );
265}

◆ REQUIRE_AGREE() [9/15]

void REQUIRE_AGREE ( qreal scalar,
qreal reference )

Definition at line 199 of file compare.cpp.

199 {
200
201 if (!doScalarsAgree(qcomp(scalar,0), qcomp(reference,0)))
202 REPORT_SCALAR_AND_FAIL(scalar, reference);
203
204 SUCCEED( );
205}

◆ REQUIRE_AGREE() [10/15]

void REQUIRE_AGREE ( Qureg qureg,
qmatrix reference )

Definition at line 145 of file compare.cpp.

145 {
146 DEMAND( q.isDensityMatrix );
147 DEMAND( getPow2(q.numQubits) == (qindex) m1.size() );
148
149 qmatrix m2 = getMatrix(q);
150
151 for (size_t i=0; i<m1.size(); i++)
152 for (size_t j=0; j<m1.size(); j++)
153 if (!doScalarsAgree(m1[i][j], m2[i][j]))
154 REPORT_AMP_AND_FAIL(j*m1.size()+i, m2[i][j], m1[i][j]);
155
156 SUCCEED( );
157}

◆ REQUIRE_AGREE() [11/15]

void REQUIRE_AGREE ( Qureg qureg,
Qureg other )

Definition at line 285 of file compare.cpp.

285 {
286 DEMAND( qureg.numQubits == other.numQubits );
287 DEMAND( qureg.isDensityMatrix == other.isDensityMatrix );
288
289 return (qureg.isDensityMatrix)?
290 REQUIRE_AGREE( qureg, getMatrix(other) ):
291 REQUIRE_AGREE( qureg, getVector(other) );
292}

◆ REQUIRE_AGREE() [12/15]

void REQUIRE_AGREE ( Qureg qureg,
qvector reference )

Definition at line 131 of file compare.cpp.

131 {
132 DEMAND( !q.isDensityMatrix );
133 DEMAND( q.numAmps == (qindex) v1.size() );
134
135 qvector v2 = getVector(q);
136
137 for (size_t i=0; i<v1.size(); i++)
138 if (!doScalarsAgree(v1[i], v2[i]))
139 REPORT_AMP_AND_FAIL(i, v2[i], v1[i]);
140
141 SUCCEED( );
142}

◆ REQUIRE_AGREE() [13/15]

void REQUIRE_AGREE ( SuperOp matrix,
qmatrix reference )

Definition at line 274 of file compare.cpp.

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

◆ REQUIRE_AGREE() [14/15]

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

Definition at line 225 of file compare.cpp.

225 {
226 DEMAND( apiList.size() == refList.size() );
227
228 for (size_t i=0; i<apiList.size(); i++)
229 if (!doScalarsAgree(apiList[i], refList[i]))
230 REPORT_SCALAR_AND_FAIL(apiList[i], refList[i]);
231
232 SUCCEED( );
233}

◆ REQUIRE_AGREE() [15/15]

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

Definition at line 214 of file compare.cpp.

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

◆ setTestAbsoluteEpsilon()

void setTestAbsoluteEpsilon ( qreal eps)

Definition at line 59 of file compare.cpp.

59 {
60 absoluteEpsilon = eps;
61}

◆ setTestEpsilon()

void setTestEpsilon ( qreal eps)

Definition at line 67 of file compare.cpp.

67 {
68 setTestAbsoluteEpsilon(eps);
69 setTestRelativeEpsilon(eps);
70}

◆ setTestRelativeEpsilon()

void setTestRelativeEpsilon ( qreal eps)

Definition at line 63 of file compare.cpp.

63 {
64 relativeEpsilon = eps;
65}