| 1744 | */ |
| 1745 | |
| 1746 | void 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 | |
| 1775 | void validate_quregIsStateVector(Qureg qureg, const char* caller) { |
| 1776 |
no test coverage detected