MCPcopy Create free account
hub / github.com/QuEST-Kit/QuEST / validate_quregFields

Function validate_quregFields

quest/src/core/validation.cpp:1746–1773  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1744 */
1745
1746void validate_quregFields(Qureg qureg, const char* caller) {
1747
1748 // attempt to detect the Qureg was not initialised with createQureg by the
1749 // struct fields being randomised, and ergo being dimensionally incompatible
1750 bool valid = true;
1751 valid &= (qureg.numQubits > 0);
1752 valid &= (qureg.isDensityMatrix == 0 || qureg.isDensityMatrix == 1);
1753 valid &= (qureg.numAmps == powerOf2(((qureg.isDensityMatrix)? 2:1) * qureg.numQubits));
1754
1755 // we do not bother checking slightly more involved fields like numAmpsPerNode
1756
1757 tokenSubs vars = {
1758 {"${DENS_MATR}", qureg.isDensityMatrix},
1759 {"${NUM_QUBITS}", qureg.numQubits},
1760 {"${NUM_AMPS}", qureg.numAmps}};
1761
1762 assertThat(valid, report::INVALID_QUREG_FIELDS, vars, caller);
1763
1764 // In theory, we could check qureg's malloc'd pointers are not-NULL.
1765 // However, this wouldn't catch when Qureg was un-initialised because most
1766 // compilers will not automatically set struct pointers to NULL (though
1767 // that scenario will likely have been caught by above checks). It also
1768 // will not catch that the Qureg has already been validly created then
1769 // destroyed because the struct pointers will not set to NULL (because
1770 // C passes a struct copy). So NULL checks could only check for the specific
1771 // scenario of the user explicitly overwriting valid pointers with NULL -
1772 // this is not worth catching (the eventual NULL segfault might be better)
1773}
1774
1775void validate_quregIsStateVector(Qureg qureg, const char* caller) {
1776

Callers 15

applyDiagMatrPowerFunction · 0.85
applyFullStateDiagMatrFunction · 0.85
applySFunction · 0.85
applyControlledSFunction · 0.85
applyMultiControlledSFunction · 0.85

Calls 2

powerOf2Function · 0.85
assertThatFunction · 0.85

Tested by

no test coverage detected