diff --git a/docs/tutorial.md b/docs/tutorial.md index b3e99706e..ddd13ac48 100644 --- a/docs/tutorial.md +++ b/docs/tutorial.md @@ -176,24 +176,24 @@ Configuring the environment is ordinarily not necessary, but convenient in certa For example, we may wish our simulations to deterministically obtain the same measurement outcomes and random states as a previous or future run, and ergo choose to [override](https://quest-kit.github.io/QuEST/group__debug__seed.html#ga9e3a6de413901afbf50690573add1587) the default seeds. ```cpp unsigned seeds[] = {123u, 1u << 10}; -setSeeds(seeds, 2); +setQuESTSeeds(seeds, 2); ``` We may wish further to [adjust](https://quest-kit.github.io/QuEST/group__debug__reporting.html) how subsequent functions will display information to the screen ```cpp int maxRows = 8; int maxCols = 4; -setMaxNumReportedItems(maxRows, maxCols); -setMaxNumReportedSigFigs(3); +setQuESTMaxNumReportedItems(maxRows, maxCols); +setQuESTMaxNumReportedSigFigs(3); ``` or [add](https://quest-kit.github.io/QuEST/group__debug__reporting.html#ga29413703d609254244d6b13c663e6e06) extra spacing between QuEST's printed outputs ```cpp -setNumReportedNewlines(3); +setQuESTNumReportedNewlines(3); ``` Perhaps we also wish to relax the [precision](https://quest-kit.github.io/QuEST/group__debug__validation.html#gae395568df6def76045ec1881fcb4e6d1) with which our future inputs will be asserted unitary or Hermitian ```cpp -setValidationEpsilon(0.001); +setQuESTValidationEpsilon(0.001); ``` but when unitarity _is_ violated, or we otherwise pass an invalid input, we wish to execute a [custom function](https://quest-kit.github.io/QuEST/group__debug__validation.html#ga14b6e7ce08465e36750da3acbc41062f) before exiting. ```cpp @@ -205,7 +205,7 @@ void myErrorHandler(const char *func, const char *msg) { exit(1); } -setInputErrorHandler(myErrorHandler); +setQuESTInputErrorHandler(myErrorHandler); ``` > [!TIP] @@ -218,7 +218,7 @@ setInputErrorHandler(myErrorHandler); > std::string msg(errMsg); > throw std::runtime_error(func + ": " + msg); > } -> setInputErrorHandler(myErrorHandler); +> setQuESTInputErrorHandler(myErrorHandler); > ``` @@ -253,7 +253,7 @@ Qureg (10 qubit statevector, 1024 qcomps, 16.1 KiB): 0 |1022⟩ 0 |1023⟩ ``` -> This printed only `8` amplitudes as per our setting of [`setMaxNumReportedItems()`](https://quest-kit.github.io/QuEST/group__debug__reporting.html#ga093c985b1970a0fd8616c01b9825979a) above. +> This printed only `8` amplitudes as per our setting of [`setQuESTMaxNumReportedItems()`](https://quest-kit.github.io/QuEST/group__debug__reporting.html#ga093c985b1970a0fd8616c01b9825979a) above. Behind the scenes, the function `createQureg` did something clever; it consulted the compiled deployments and available hardware to decide whether to distribute `qureg`, or dedicate it persistent GPU memory, and marked whether or not to multithread its subsequent modification. It attempts to choose _optimally_, avoiding gratuitous parallelisation if the overheads outweigh the benefits, or if the hardware devices have insufficient memory. @@ -356,7 +356,7 @@ Qureg: globalTotal.......16 MiB ``` -> The spacing between the outputs of those two consecutive QuEST functions was determined by our earlier call to [`setNumReportedNewlines()`](https://quest-kit.github.io/QuEST/group__debug__reporting.html#ga29413703d609254244d6b13c663e6e06). +> The spacing between the outputs of those two consecutive QuEST functions was determined by our earlier call to [`setQuESTNumReportedNewlines()`](https://quest-kit.github.io/QuEST/group__debug__reporting.html#ga29413703d609254244d6b13c663e6e06). A density matrix `Qureg` can model classical uncertainty as results from [decoherence](https://quest-kit.github.io/QuEST/group__decoherence.html), and proves useful when simulating quantum operations on a noisy quantum computer. @@ -415,7 +415,7 @@ Qureg (5 qubit density matrix, 32x32 qcomps, 16.1 KiB): -0.00597-0.00615i -0.00207-0.00451i … 0.000509-0.00401i 0.0173+(3.12e-19)i ``` -> The number of printed significant figures above results from our earlier calling of [`setMaxNumReportedSigFigs()`](https://quest-kit.github.io/QuEST/group__debug__reporting.html#ga15d46e5d813f70b587762814964e1994). +> The number of printed significant figures above results from our earlier calling of [`setQuESTMaxNumReportedSigFigs()`](https://quest-kit.github.io/QuEST/group__debug__reporting.html#ga15d46e5d813f70b587762814964e1994). @@ -612,7 +612,7 @@ Exiting... If we're satisfied our matrix _is_ sufficiently approximately unitary, we can [adjust](https://quest-kit.github.io/QuEST/group__debug__validation.html#gae395568df6def76045ec1881fcb4e6d1) or [disable](https://quest-kit.github.io/QuEST/group__debug__validation.html#ga5999824df0785ea88fb2d5b5582f2b46) the validation. ```cpp // max(norm(m * dagger(m) - identity)) = 0.9025 -setValidationEpsilon(0.903); +setQuESTValidationEpsilon(0.903); applyCompMatr1(qureg, 0, m); ``` @@ -783,7 +783,7 @@ reportScalar("entanglement", calcPurity(reduced)); ## Report the results -We've seen above that [scalars](https://quest-kit.github.io/QuEST/group__types.html) can be reported, handling the pretty formatting of real and complex numbers, controlled by settings like [`setMaxNumReportedSigFigs()`](https://quest-kit.github.io/QuEST/group__debug__reporting.html#ga15d46e5d813f70b587762814964e1994). But we can also report every data structure in the QuEST API, such as Pauli strings +We've seen above that [scalars](https://quest-kit.github.io/QuEST/group__types.html) can be reported, handling the pretty formatting of real and complex numbers, controlled by settings like [`setQuESTMaxNumReportedSigFigs()`](https://quest-kit.github.io/QuEST/group__debug__reporting.html#ga15d46e5d813f70b587762814964e1994). But we can also report every data structure in the QuEST API, such as Pauli strings ```cpp reportPauliStr( getInlinePauliStr("XXYYZZ", {5,50, 10,60, 30,40}) @@ -805,8 +805,8 @@ PauliStrSum (4 terms, 160 bytes): ``` All outputs are affected by the [reporter settings](https://quest-kit.github.io/QuEST/group__debug__reporting.html). ```cpp -setMaxNumReportedItems(4,4); -setMaxNumReportedSigFigs(1); +setQuESTMaxNumReportedItems(4,4); +setQuESTMaxNumReportedSigFigs(1); reportCompMatr(bigmatrix); ``` ``` diff --git a/examples/extended/dynamics.c b/examples/extended/dynamics.c index 03abcc16c..8c72d71ab 100644 --- a/examples/extended/dynamics.c +++ b/examples/extended/dynamics.c @@ -103,16 +103,16 @@ PauliStrSum createMyObservable(int numQubits) { void reportMyStructs(Qureg qureg, PauliStrSum hamil, PauliStrSum observ) { - setMaxNumReportedSigFigs(6); // sig-figs in scalars - setNumReportedNewlines(2); // spacing between reports - setReportedPauliChars(".XYZ"); // print I as . - setReportedPauliStrStyle(0); // print XYZ (0) or Z3 Y2 X1 (1) - setMaxNumReportedItems(8, 8); // show max 8 qureg amplitudes + setQuESTMaxNumReportedSigFigs(6); // sig-figs in scalars + setQuESTNumReportedNewlines(2); // spacing between reports + setQuESTReportedPauliChars(".XYZ"); // print I as . + setQuESTReportedPauliStrStyle(0); // print XYZ (0) or Z3 Y2 X1 (1) + setQuESTMaxNumReportedItems(8, 8); // show max 8 qureg amplitudes reportStr("[Initial state]"); reportQureg(qureg); - setMaxNumReportedItems(0, 0); // show 0=all Pauli operators + setQuESTMaxNumReportedItems(0, 0); // show 0=all Pauli operators reportStr("[Hamiltonian]"); reportPauliStrSum(hamil); @@ -144,8 +144,8 @@ int main() { reportMyStructs(qureg, hamil, observ); // tidy reporting of below expectation values - setMaxNumReportedSigFigs(3); - setNumReportedNewlines(1); + setQuESTMaxNumReportedSigFigs(3); + setQuESTNumReportedNewlines(1); // evolve by repeatedly (each is a "step") Trotterising // exp(-i dt H) with the specified order and repetitions. @@ -172,8 +172,8 @@ int main() { reportStr(""); // preview the final state... - setNumReportedNewlines(2); - setMaxNumReportedItems(25, 25); + setQuESTNumReportedNewlines(2); + setQuESTMaxNumReportedItems(25, 25); reportStr("[Final state]"); reportQureg(qureg); diff --git a/examples/extended/dynamics.cpp b/examples/extended/dynamics.cpp index 636145387..da4fd9223 100644 --- a/examples/extended/dynamics.cpp +++ b/examples/extended/dynamics.cpp @@ -100,16 +100,16 @@ PauliStrSum createMyObservable(int numQubits) { void reportMyStructs(Qureg qureg, PauliStrSum hamil, PauliStrSum observ) { - setMaxNumReportedSigFigs(6); // sig-figs in scalars - setNumReportedNewlines(2); // spacing between reports - setReportedPauliChars(".XYZ"); // print I as . - setReportedPauliStrStyle(0); // print XYZ (0) or Z3 Y2 X1 (1) - setMaxNumReportedItems(8, 8); // show max 8 qureg amplitudes + setQuESTMaxNumReportedSigFigs(6); // sig-figs in scalars + setQuESTNumReportedNewlines(2); // spacing between reports + setQuESTReportedPauliChars(".XYZ"); // print I as . + setQuESTReportedPauliStrStyle(0); // print XYZ (0) or Z3 Y2 X1 (1) + setQuESTMaxNumReportedItems(8, 8); // show max 8 qureg amplitudes reportStr("[Initial state]"); reportQureg(qureg); - setMaxNumReportedItems(0, 0); // show 0=all Pauli operators + setQuESTMaxNumReportedItems(0, 0); // show 0=all Pauli operators reportStr("[Hamiltonian]"); reportPauliStrSum(hamil); @@ -141,8 +141,8 @@ int main() { reportMyStructs(qureg, hamil, observ); // tidy reporting of below expectation values - setMaxNumReportedSigFigs(3); - setNumReportedNewlines(1); + setQuESTMaxNumReportedSigFigs(3); + setQuESTNumReportedNewlines(1); // evolve by repeatedly (each is a "step") Trotterising // exp(-i dt H) with the specified order and repetitions. @@ -166,8 +166,8 @@ int main() { reportStr(""); // preview the final state... - setNumReportedNewlines(2); - setMaxNumReportedItems(25, 25); + setQuESTNumReportedNewlines(2); + setQuESTMaxNumReportedItems(25, 25); reportStr("[Final state]"); reportQureg(qureg); diff --git a/examples/isolated/reporting_matrices.c b/examples/isolated/reporting_matrices.c index 319c758cb..cb497593e 100644 --- a/examples/isolated/reporting_matrices.c +++ b/examples/isolated/reporting_matrices.c @@ -49,7 +49,7 @@ void demo_CompMatr() { for (int i=0; i [!CAUTION] * > Unlike other functions (including calcExpecFullStateDiagMatr()), this function will _NOT_ * > consult the imaginary components of the elements of @p matrix, since a non-complex exponentiation * > function is used. That is, while validation permits the imaginary components to be small, they * > will be internally treated as precisely zero. This is true even when Hermiticity validation - * > is disabled using setValidationOff(). To consult the imaginary components of @p matrix, use + * > is disabled using setQuESTValidationOff(). To consult the imaginary components of @p matrix, use * > calcExpecNonHermitianFullStateDiagMatrPower(). * * - Hermiticity of @p matrix when raised to @p exponent further requires that, when @p exponent is @@ -298,7 +298,7 @@ qreal calcExpecFullStateDiagMatr(Qureg qureg, FullStateDiagMatr matr); * zero elements which would otherwise create divergences in @f$\hat{D}^x@f$. Validation ergo * checks that when @p exponent is (strictly) negative, @p matrix contains no elements within * distance @f$\valeps@f$ to zero (regardless of the magnitude of @p exponent). Adjust - * @f$\valeps@f$ using setValidationEpsilon(). + * @f$\valeps@f$ using setQuESTValidationEpsilon(). * - The passed @p exponent is always real, but can be relaxed to a general complex scalar via * calcExpecNonHermitianFullStateDiagMatrPower(). * - The returned value is always real, and the imaginary component is neglected even when @@ -890,7 +890,7 @@ qreal calcPurity(Qureg qureg); * - The output of this function is always real, which validation will check after computing the * fidelity as a complex scalar. Specifically, validation will assert that the result has an * absolute imaginary component less than the validation epsilon, which can be adjusted with - * setValidationEpsilon(). + * setQuESTValidationEpsilon(). * * - This function does not yet support both @p qureg and @p other being density matrices, for * which the fidelity calculation is more substantial. @@ -1004,7 +1004,7 @@ qreal calcFidelity(Qureg qureg, Qureg other); \left| \, \im{ \brapsi \dmrho \svpsi } \, \right| \le \valeps, \\ \re{ \brapsi \dmrho \svpsi } \le 1 + \valeps, * @f] - * where @f$\valeps@f$ is the validation epsilon, adjustable via setValidationEpsilon(). + * where @f$\valeps@f$ is the validation epsilon, adjustable via setQuESTValidationEpsilon(). * * - Even when the above postcondition validation is disabled, the Bures and purified distance * calculations will respectively replace @f$\left| \braket{\phi}{\psi} \right|@f$ and diff --git a/quest/include/debug.h b/quest/include/debug.h index 48ef22527..a51236141 100644 --- a/quest/include/debug.h +++ b/quest/include/debug.h @@ -43,19 +43,19 @@ extern "C" { /// @notyetdoced -void setSeeds(unsigned* seeds, int numSeeds); +void setQuESTSeeds(unsigned* seeds, int numSeeds); /// @notyetdoced -void setSeedsToDefault(); +void setQuESTSeedsToDefault(); /// @notyetdoced -void getSeeds(unsigned* seeds); +void getQuESTSeeds(unsigned* seeds); /// @notyetdoced -int getNumSeeds(); +int getQuESTNumSeeds(); /** @} */ @@ -79,27 +79,27 @@ int getNumSeeds(); * - [C](https://github.com/QuEST-Kit/QuEST/blob/devel/examples/isolated/setting_errorhandler.c) and * [C++](https://github.com/QuEST-Kit/QuEST/blob/devel/examples/isolated/setting_errorhandler.cpp) examples */ -void setInputErrorHandler(void (*callback)(const char* func, const char* msg)); +void setQuESTInputErrorHandler(void (*callback)(const char* func, const char* msg)); /// @notyetdoced -void setValidationOn(); +void setQuESTValidationOn(); /// @notyetdoced -void setValidationOff(); +void setQuESTValidationOff(); /// @notyetdoced -void setValidationEpsilonToDefault(); +void setQuESTValidationEpsilonToDefault(); /// @notyetdoced -void setValidationEpsilon(qreal eps); +void setQuESTValidationEpsilon(qreal eps); /// @notyetdoced -qreal getValidationEpsilon(); +qreal getQuESTValidationEpsilon(); /** @} */ @@ -115,7 +115,7 @@ qreal getValidationEpsilon(); /// @notyetdoced /// @notyettested -void setMaxNumReportedItems(qindex numRows, qindex numCols); +void setQuESTMaxNumReportedItems(qindex numRows, qindex numCols); /** @notyetdoced @@ -123,11 +123,11 @@ void setMaxNumReportedItems(qindex numRows, qindex numCols); * > (e.g. `5.32 KiB`) which is always shown with three significant figures * > (or four when in bytes, e.g. `1023 bytes`). */ -void setMaxNumReportedSigFigs(int numSigFigs); +void setQuESTMaxNumReportedSigFigs(int numSigFigs); /// @notyetdoced -void setNumReportedNewlines(int numNewlines); +void setQuESTNumReportedNewlines(int numNewlines); /** @@ -138,11 +138,11 @@ void setNumReportedNewlines(int numNewlines); PauliStr str = getInlinePauliStr("XYZ", {0,10,20}); reportPauliStr(str); - setReportedPauliChars(".xyz"); + setQuESTReportedPauliChars(".xyz"); reportPauliStr(str); * ``` */ -void setReportedPauliChars(const char* paulis); +void setQuESTReportedPauliChars(const char* paulis); /** @@ -152,14 +152,14 @@ void setReportedPauliChars(const char* paulis); * ``` PauliStr str = getInlinePauliStr("XYZ", {0,10,20}); - setReportedPauliStrStyle(0); + setQuESTReportedPauliStrStyle(0); reportPauliStr(str); - setReportedPauliStrStyle(1); + setQuESTReportedPauliStrStyle(1); reportPauliStr(str); * ``` */ -void setReportedPauliStrStyle(int style); +void setQuESTReportedPauliStrStyle(int style); /** @} */ @@ -174,11 +174,11 @@ void setReportedPauliStrStyle(int style); /// @notyetdoced -qindex getGpuCacheSize(); +qindex getQuESTGpuCacheSize(); /// @notyetdoced -void clearGpuCache(); +void clearQuESTGpuCache(); /** @} */ @@ -194,7 +194,7 @@ void clearGpuCache(); /// @notyetdoced /// @notyettested -void getEnvironmentString(char str[200]); +void getQuESTEnvironmentString(char str[200]); /** @} */ @@ -225,16 +225,16 @@ void getEnvironmentString(char str[200]); /// @notyettested /// @notyetdoced /// @cppvectoroverload -/// @see setSeeds() -void setSeeds(std::vector seeds); +/// @see setQuESTSeeds() +void setQuESTSeeds(std::vector seeds); /// @ingroup debug_seed /// @notyettested /// @notyetdoced /// @cpponly -/// @see getSeeds() -std::vector getSeeds(); +/// @see getQuESTSeeds() +std::vector getQuESTSeeds(); #endif // __cplusplus diff --git a/quest/include/deprecated.h b/quest/include/deprecated.h index 1a63b2044..f70b2102c 100644 --- a/quest/include/deprecated.h +++ b/quest/include/deprecated.h @@ -449,13 +449,6 @@ typedef enum pauliOpType _NoWarnPauliOpType; "setDensityQuregAmps(Qureg, qindex startRow, qindex startCol, qcomp** amps, qindex numRows, qindex numCols)") -#define getQuESTSeeds(...) \ - _ERROR_GENERAL_MSG( \ - "The QuEST function 'getQuESTSeeds(QuESTEnv env, unsigned long int* out, int numOut)' has been deprecated. " \ - "Please instead use 'getSeeds(unsigned* out)' which accepts a pointer to pre-allocated memory of length " \ - "equal to that returned by 'getNumSeeds()'. We cannot automatically invoke this replacement routine." ) - - #define applyPhaseFunc(...) \ _ERROR_PHASE_FUNC_REMOVED("applyPhaseFunc") @@ -548,17 +541,44 @@ typedef enum pauliOpType _NoWarnPauliOpType; #define _GET_ENVIRONMENT_STRING_1(str) \ - getEnvironmentString(str) + getQuESTEnvironmentString(str) #define _GET_ENVIRONMENT_STRING_2(str) \ - _WARN_FUNC_NOW_HAS_FEWER_ARGS("getEnvironmentString(QuESTEnv, char[200])", "getEnvironmentString(char[200])") \ + _WARN_FUNC_NOW_HAS_FEWER_ARGS("getQuESTEnvironmentString(QuESTEnv, char[200])", "getQuESTEnvironmentString(char[200])") \ _GET_ENVIRONMENT_STRING_1(str) -#define getEnvironmentString(...) \ +#define getQuESTEnvironmentString(...) \ _CALL_MACRO_WITH_1_OR_2_ARGS(_GET_ENVIRONMENT_STRING, __VA_ARGS__) +/* + * FUNCTIONS WITH THE SAME NAME BUT 1 INSTEAD OF 3 ARGS + * + * which are handled similar to above + */ + + +#define _GET_MACRO_WITH_1_OR_3_ARGS(_1, _2, _3, macroname, ...) macroname + +#define _CALL_MACRO_WITH_1_OR_3_ARGS(prefix, ...) \ + _GET_MACRO_WITH_1_OR_3_ARGS(__VA_ARGS__, prefix##_3, prefix##_2, prefix##_1)(__VA_ARGS__) + + +#define _GET_QUEST_SEEDS_1(out) \ + getQuESTSeeds(out) + +#define _GET_QUEST_SEEDS_3(env, out, numOut) \ + _WARN_FUNC_NOW_HAS_FEWER_ARGS( \ + "getQuESTSeeds(QuESTEnv env, unsigned long int* out, int numOut)", \ + "getQuESTSeeds(unsigned* out)") \ + _GET_QUEST_SEEDS_1(out) + +#define getQuESTSeeds(...) \ + _CALL_MACRO_WITH_1_OR_3_ARGS(_GET_QUEST_SEEDS, __VA_ARGS__) + + + /* * FUNCTIONS WITH THE SAME NAME BUT 0 INSTEAD OF 1 ARGS * @@ -657,10 +677,10 @@ static inline void v3_mixKrausMap(Qureg qureg, int targ, _NoWarnComplexMatrix2 * static inline void _mixNonTPKrausMap(Qureg qureg, int targ, _NoWarnComplexMatrix2 *ops, int numOps) { - qreal eps = getValidationEpsilon(); - setValidationEpsilon(0); + qreal eps = getQuESTValidationEpsilon(); + setQuESTValidationEpsilon(0); _MIX_KRAUS_MAP_INNER(qureg, ops, numOps, &targ, 1); - setValidationEpsilon(eps); + setQuESTValidationEpsilon(eps); } #define mixNonTPKrausMap(...) \ @@ -673,10 +693,10 @@ static inline void _mixNonTPKrausMap(Qureg qureg, int targ, _NoWarnComplexMatrix static inline void _mixTwoQubitKrausMap(Qureg qureg, int targ1, int targ2, _NoWarnComplexMatrix4 *ops, int numOps, int isNonCPTP) { int targs[] = {targ1, targ2}; - qreal eps = getValidationEpsilon(); - if (isNonCPTP) setValidationEpsilon(0); + qreal eps = getQuESTValidationEpsilon(); + if (isNonCPTP) setQuESTValidationEpsilon(0); _MIX_KRAUS_MAP_INNER(qureg, ops, numOps, targs, 2); - setValidationEpsilon(eps); + setQuESTValidationEpsilon(eps); } #define mixTwoQubitKrausMap(...) \ @@ -703,11 +723,11 @@ static inline void _mixMultiQubitKrausMap(Qureg qureg, int* targs, int numTargs, setKrausMap(map, ptrs); free(ptrs); - qreal eps = getValidationEpsilon(); - if (isNonCPTP) setValidationEpsilon(0); + qreal eps = getQuESTValidationEpsilon(); + if (isNonCPTP) setQuESTValidationEpsilon(0); (mixKrausMap)(qureg, targs, numTargs, map); // calls above macro, wrapped to avoid warning */ destroyKrausMap(map); - setValidationEpsilon(eps); + setQuESTValidationEpsilon(eps); } #define mixMultiQubitKrausMap(...) \ @@ -827,16 +847,16 @@ static inline QuESTEnv _createQuESTEnv() { leftapplyDiagMatr(__VA_ARGS__) static inline void _applyGateSubDiagonalOp(Qureg qureg, int* targets, int numTargets, DiagMatr op) { - qreal eps = getValidationEpsilon(); - setValidationEpsilon(0); + qreal eps = getQuESTValidationEpsilon(); + setQuESTValidationEpsilon(0); applyDiagMatr(qureg, targets, numTargets, op); - setValidationEpsilon(eps); + setQuESTValidationEpsilon(eps); } #define applyGateSubDiagonalOp(...) \ _WARN_GENERAL_MSG( \ "The QuEST function 'applyGateSubDiagonalOp()' is deprecated. To achieve the same thing, disable " \ - "numerical validation via 'setValidationEpsilon(0)' before calling 'applyDiagMatr()'. You can " \ - "save the existing epsilon via 'getValidationEpsilon()' to thereafter restore. This procedure " \ + "numerical validation via 'setQuESTValidationEpsilon(0)' before calling 'applyDiagMatr()'. You can " \ + "save the existing epsilon via 'getQuESTValidationEpsilon()' to thereafter restore. This procedure " \ "has been performed here automatically.") \ _applyGateSubDiagonalOp(__VA_ARGS__) @@ -1131,32 +1151,32 @@ static inline void _applyPauliHamil(Qureg inQureg, PauliStrSum hamil, Qureg outQ static inline void _applyGateMatrixN(Qureg qureg, int* targs, int numTargs, CompMatr u) { - qreal eps = getValidationEpsilon(); - setValidationEpsilon(0); + qreal eps = getQuESTValidationEpsilon(); + setQuESTValidationEpsilon(0); applyCompMatr(qureg, targs, numTargs, u); - setValidationEpsilon(eps); + setQuESTValidationEpsilon(eps); } #define applyGateMatrixN(...) \ _WARN_GENERAL_MSG( \ "The QuEST function 'applyGateMatrixN()' is deprecated. To achieve the same thing, disable " \ - "numerical validation via 'setValidationEpsilon(0)' before calling 'applyCompMatr()'. You can " \ - "save the existing epsilon via 'getValidationEpsilon()' to thereafter restore. This procedure " \ + "numerical validation via 'setQuESTValidationEpsilon(0)' before calling 'applyCompMatr()'. You can " \ + "save the existing epsilon via 'getQuESTValidationEpsilon()' to thereafter restore. This procedure " \ "has been performed here automatically.") \ _applyGateMatrixN(__VA_ARGS__) static inline void _applyMultiControlledGateMatrixN(Qureg qureg, int* ctrls, int numCtrls, int* targs, int numTargs, CompMatr u) { - qreal eps = getValidationEpsilon(); - setValidationEpsilon(0); + qreal eps = getQuESTValidationEpsilon(); + setQuESTValidationEpsilon(0); applyMultiControlledCompMatr(qureg, ctrls, numCtrls, targs, numTargs, u); - setValidationEpsilon(eps); + setQuESTValidationEpsilon(eps); } #define applyMultiControlledGateMatrixN(...) \ _WARN_GENERAL_MSG( \ "The QuEST function 'applyMultiControlledGateMatrixN()' is deprecated. To achieve the same thing, disable " \ - "numerical validation via 'setValidationEpsilon(0)' before calling 'applyMultiControlledCompMatr()'. You can " \ - "save the existing epsilon via 'getValidationEpsilon()' to thereafter restore. This procedure has been " \ + "numerical validation via 'setQuESTValidationEpsilon(0)' before calling 'applyMultiControlledCompMatr()'. You can " \ + "save the existing epsilon via 'getQuESTValidationEpsilon()' to thereafter restore. This procedure has been " \ "performed here automatically.") \ _applyMultiControlledGateMatrixN(__VA_ARGS__) @@ -1331,12 +1351,12 @@ static inline void _multiControlledMultiRotatePauli(Qureg qureg, int* ctrls, int #define seedQuESTDefault(...) \ - _WARN_FUNC_RENAMED("seedQuESTDefault(QuESTEnv)", "setSeedsToDefault()") \ - setSeedsToDefault() + _WARN_FUNC_RENAMED("seedQuESTDefault(QuESTEnv)", "setQuESTSeedsToDefault()") \ + setQuESTSeedsToDefault() #define seedQuEST(env, seeds, numSeeds) \ - _WARN_FUNC_RENAMED("seedQuEST(QuESTEnv, unsigned long int*, int)", "setSeeds(unsigned*, int)") \ - setSeeds(seeds, numSeeds) + _WARN_FUNC_RENAMED("seedQuEST(QuESTEnv, unsigned long int*, int)", "setQuESTSeeds(unsigned*, int)") \ + setQuESTSeeds(seeds, numSeeds) diff --git a/quest/include/modes.h b/quest/include/modes.h index f8fc52a1c..30441009d 100644 --- a/quest/include/modes.h +++ b/quest/include/modes.h @@ -55,8 +55,8 @@ * Specifying `DEFAULT_VALIDATION_EPSILON` to a positive, real number overrides the * precision-specific default (`1E-5`, `1E-12`, `1E-13` for single, double and quadruple * precision respectively). The specified epsilon is used by QuEST for numerical validation - * unless overriden at runtime via setValidationEpsilon(), in which case it can be - * restored to that specified by this environment variable using setValidationEpsilonToDefault(). + * unless overriden at runtime via setQuESTValidationEpsilon(), in which case it can be + * restored to that specified by this environment variable using setQuESTValidationEpsilonToDefault(). * * @envvarvalues * - setting @p DEFAULT_VALIDATION_EPSILON=0 disables numerical validation, as if the value diff --git a/quest/include/operations.h b/quest/include/operations.h index ea4a316ae..ff81ad7aa 100644 --- a/quest/include/operations.h +++ b/quest/include/operations.h @@ -95,7 +95,7 @@ digraph { * @f[ \max\limits_{ij} \Big|\left(\hat{U} \hat{U}^\dagger - \id\right)_{ij}\Big|^2 \le \valeps * @f] - * where the validation epsilon @f$ \valeps @f$ can be adjusted with setValidationEpsilon(). + * where the validation epsilon @f$ \valeps @f$ can be adjusted with setQuESTValidationEpsilon(). * * @myexample * ``` @@ -194,7 +194,7 @@ digraph { * @f[ \max\limits_{ij} \Big|\left(\hat{U} \hat{U}^\dagger - \id\right)_{ij}\Big|^2 \le \valeps * @f] - * where the validation epsilon @f$ \valeps @f$ can be adjusted with setValidationEpsilon(). + * where the validation epsilon @f$ \valeps @f$ can be adjusted with setQuESTValidationEpsilon(). * * @equivalences * diff --git a/quest/include/trotterisation.h b/quest/include/trotterisation.h index 6fd493264..59600c9d9 100644 --- a/quest/include/trotterisation.h +++ b/quest/include/trotterisation.h @@ -138,7 +138,7 @@ extern "C" { * @f[ \max\limits_{i} |c_i| \le \valeps * @f] - * where the validation epsilon @f$ \valeps @f$ can be adjusted with setValidationEpsilon(). + * where the validation epsilon @f$ \valeps @f$ can be adjusted with setQuESTValidationEpsilon(). * Otherwise, use applyTrotterizedNonUnitaryPauliStrSumGadget() to permit non-Hermitian @p sum * and ergo effect a non-unitary exponential(s). * @@ -352,7 +352,7 @@ extern "C" { * @f[ \max\limits_{i} |c_i| \le \valeps * @f] - * where the validation epsilon @f$ \valeps @f$ can be adjusted with setValidationEpsilon(). The imaginary components + * where the validation epsilon @f$ \valeps @f$ can be adjusted with setQuESTValidationEpsilon(). The imaginary components * of the Hamiltonian _are_ considered during simulation. * * - The @p time parameter is necessarily real to retain unitarity. It can be substituted for a strictly imaginary @@ -488,7 +488,7 @@ void applyTrotterizedUnitaryTimeEvolution(Qureg qureg, PauliStrSum hamil, qreal * @f[ \max\limits_{i} |c_i| \le \valeps * @f] - * where the validation epsilon @f$ \valeps @f$ can be adjusted with setValidationEpsilon(). Beware however that + * where the validation epsilon @f$ \valeps @f$ can be adjusted with setQuESTValidationEpsilon(). Beware however that * imaginary-time evolution under a non-Hermitian Hamiltonian will _not_ necessarily approach the lowest lying eigenstate * (the eigenvalues may be non-real) so is likely of limited utility. * @@ -604,8 +604,8 @@ void applyTrotterizedImaginaryTimeEvolution(Qureg qureg, PauliStrSum hamil, qrea * @f[ \min\limits_{i} \gamma_i \ge - \valeps * @f] - * where the validation epsilon @f$ \valeps @f$ can be adjusted with setValidationEpsilon(). Non-trace-preserving, - * negative damping rates can be simulated by disabling numerical validation via `setValidationEpsilon(0)`. + * where the validation epsilon @f$ \valeps @f$ can be adjusted with setQuESTValidationEpsilon(). Non-trace-preserving, + * negative damping rates can be simulated by disabling numerical validation via `setQuESTValidationEpsilon(0)`. * * - The @p time parameter is necessarily real, and cannot be generalised to imaginary or complex like in other * functions. Generalisation is trivially numerically possible, but has no established physical meaning and so diff --git a/quest/src/api/debug.cpp b/quest/src/api/debug.cpp index 82146da2a..e6c6b9f2a 100644 --- a/quest/src/api/debug.cpp +++ b/quest/src/api/debug.cpp @@ -34,7 +34,7 @@ extern "C" { */ -void setSeeds(unsigned* seeds, int numSeeds) { +void setQuESTSeeds(unsigned* seeds, int numSeeds) { validate_envIsInit(__func__); validate_randomSeeds(seeds, numSeeds, __func__); @@ -42,20 +42,20 @@ void setSeeds(unsigned* seeds, int numSeeds) { rand_setSeeds(vector(seeds, seeds+numSeeds)); } -void setSeedsToDefault() { +void setQuESTSeedsToDefault() { validate_envIsInit(__func__); rand_setSeedsToDefault(); } -int getNumSeeds() { +int getQuESTNumSeeds() { validate_envIsInit(__func__); return rand_getNumSeeds(); } -void getSeeds(unsigned* seeds) { +void getQuESTSeeds(unsigned* seeds) { validate_envIsInit(__func__); auto vec = rand_getSeeds(); @@ -71,19 +71,19 @@ void getSeeds(unsigned* seeds) { * VALIDATION */ -void setInputErrorHandler(void (*callback)(const char*, const char*)) { +void setQuESTInputErrorHandler(void (*callback)(const char*, const char*)) { validate_envIsInit(__func__); validateconfig_setErrorHandler(callback); } -void setValidationOn() { +void setQuESTValidationOn() { validate_envIsInit(__func__); validateconfig_enable(); } -void setValidationOff() { +void setQuESTValidationOff() { validate_envIsInit(__func__); // disables all validation and computation @@ -97,7 +97,7 @@ void setValidationOff() { } -void setValidationEpsilon(qreal eps) { +void setQuESTValidationEpsilon(qreal eps) { validate_envIsInit(__func__); validate_newEpsilonValue(eps, __func__); @@ -105,14 +105,14 @@ void setValidationEpsilon(qreal eps) { util_setEpsilonSensitiveHeapFlagsToUnknown(); } -void setValidationEpsilonToDefault() { +void setQuESTValidationEpsilonToDefault() { validate_envIsInit(__func__); validateconfig_setEpsilonToDefault(); util_setEpsilonSensitiveHeapFlagsToUnknown(); } -qreal getValidationEpsilon() { +qreal getQuESTValidationEpsilon() { validate_envIsInit(__func__); return validateconfig_getEpsilon(); @@ -125,7 +125,7 @@ qreal getValidationEpsilon() { */ -void setMaxNumReportedItems(qindex numRows, qindex numCols) { +void setQuESTMaxNumReportedItems(qindex numRows, qindex numCols) { validate_envIsInit(__func__); validate_newMaxNumReportedScalars(numRows, numCols, __func__); @@ -139,7 +139,7 @@ void setMaxNumReportedItems(qindex numRows, qindex numCols) { } -void setMaxNumReportedSigFigs(int numSigFigs) { +void setQuESTMaxNumReportedSigFigs(int numSigFigs) { validate_envIsInit(__func__); validate_newMaxNumReportedSigFigs(numSigFigs, __func__); @@ -147,7 +147,7 @@ void setMaxNumReportedSigFigs(int numSigFigs) { } -void setNumReportedNewlines(int numNewlines) { +void setQuESTNumReportedNewlines(int numNewlines) { validate_envIsInit(__func__); validate_newNumReportedNewlines(numNewlines, __func__); @@ -155,7 +155,7 @@ void setNumReportedNewlines(int numNewlines) { } -void setReportedPauliChars(const char* paulis) { +void setQuESTReportedPauliChars(const char* paulis) { validate_envIsInit(__func__); validate_numPauliChars(paulis, __func__); @@ -163,7 +163,7 @@ void setReportedPauliChars(const char* paulis) { } -void setReportedPauliStrStyle(int flag) { +void setQuESTReportedPauliStrStyle(int flag) { validate_envIsInit(__func__); validate_reportedPauliStrStyleFlag(flag, __func__); @@ -177,7 +177,7 @@ void setReportedPauliStrStyle(int flag) { */ -qindex getGpuCacheSize() { +qindex getQuESTGpuCacheSize() { validate_envIsInit(__func__); if (getQuESTEnv().isGpuAccelerated) @@ -188,7 +188,7 @@ qindex getGpuCacheSize() { } -void clearGpuCache() { +void clearQuESTGpuCache() { validate_envIsInit(__func__); // safely do nothing if not GPU accelerated @@ -206,19 +206,19 @@ void clearGpuCache() { */ -void setSeeds(vector seeds) { - setSeeds(seeds.data(), seeds.size()); +void setQuESTSeeds(vector seeds) { + setQuESTSeeds(seeds.data(), seeds.size()); } -vector getSeeds() { +vector getQuESTSeeds() { validate_envIsInit(__func__); // allocate temp vector, and pedantically validate successful vector out; - int numSeeds = getNumSeeds(); + int numSeeds = rand_getNumSeeds(); auto callback = [&]() { validate_tempListAllocSucceeded(false, numSeeds, sizeof(unsigned), __func__); }; util_tryAllocVector(out, numSeeds, callback); - getSeeds(out.data()); + getQuESTSeeds(out.data()); return out; } diff --git a/quest/src/api/environment.cpp b/quest/src/api/environment.cpp index 541491899..6f4a45a32 100644 --- a/quest/src/api/environment.cpp +++ b/quest/src/api/environment.cpp @@ -489,7 +489,7 @@ void reportQuESTEnv() { } -void getEnvironmentString(char str[200]) { +void getQuESTEnvironmentString(char str[200]) { validate_envIsInit(__func__); QuESTEnv env = getQuESTEnv(); diff --git a/quest/src/core/validation.cpp b/quest/src/core/validation.cpp index 3b6fc18a2..2db517548 100644 --- a/quest/src/core/validation.cpp +++ b/quest/src/core/validation.cpp @@ -136,7 +136,7 @@ namespace report { "Invalid number of trailing newlines (${NUM_NEWLINES}). Cannot generally be less than zero, and must not be zero when calling multi-line reporting functions like reportQureg()."; string INSUFFICIENT_NUM_REPORTED_NEWLINES = - "The number of trailing newlines (set by setNumReportedNewlines()) is zero which is not permitted when calling multi-line reporters."; + "The number of trailing newlines (set by setQuESTNumReportedNewlines()) is zero which is not permitted when calling multi-line reporters."; string INVALID_NUM_NEW_PAULI_CHARS = "Given an invalid number of Pauli characters. Must specify precisely four to respectively replace IXYZ."; @@ -1144,7 +1144,7 @@ void default_inputErrorHandler(const char* func, const char* msg) { // safe to call even before MPI has been setup, and ignores user-set trailing newlines. // It begins with \n to interrupt half-printed lines (when trailing newlines are set to - // 0 via setNumReportedNewlines(0)), for visual clarity. Note that user's overriding + // 0 via setQuESTNumReportedNewlines(0)), for visual clarity. Note that user's overriding // functions might not think to print an initial newline but oh well! print(string("\n") + "QuEST encountered a validation error during function " diff --git a/tests/deprecated/test_calculations.cpp b/tests/deprecated/test_calculations.cpp index 0f02a6dea..9ce963fb2 100644 --- a/tests/deprecated/test_calculations.cpp +++ b/tests/deprecated/test_calculations.cpp @@ -386,9 +386,9 @@ TEST_CASE( "calcExpecPauliProd", "[calculations]" ) { // (get real, since we start in a non-Hermitian state, hence diagonal isn't real) // disable validation during call, because result is non-real and will upset post-check - setValidationOff(); + setQuESTValidationOff(); qreal res = calcExpecPauliProd(mat, targs, paulis.data(), numTargs, matWork); - setValidationOn(); + setQuESTValidationOn(); REQUIRE( res == Approx(tr).margin(10*REAL_EPS) ); } diff --git a/tests/deprecated/test_decoherence.cpp b/tests/deprecated/test_decoherence.cpp index edf1d9f61..d4a626d47 100644 --- a/tests/deprecated/test_decoherence.cpp +++ b/tests/deprecated/test_decoherence.cpp @@ -32,7 +32,7 @@ using std::vector; initDebugState(qureg); \ QMatrix ref = toQMatrix(qureg); \ assertQuregAndRefInDebugState(qureg, ref); \ - setValidationEpsilon(REAL_EPS); + setQuESTValidationEpsilon(REAL_EPS); /* allows concise use of ContainsSubstring in catch's REQUIRE_THROWS_WITH */ using Catch::Matchers::ContainsSubstring; diff --git a/tests/deprecated/test_main.cpp b/tests/deprecated/test_main.cpp index 35ba37477..628a9c8d8 100644 --- a/tests/deprecated/test_main.cpp +++ b/tests/deprecated/test_main.cpp @@ -41,7 +41,7 @@ extern "C" void validationErrorHandler(const char* errFunc, const char* errMsg) int main(int argc, char* argv[]) { initQuESTEnv(); - setInputErrorHandler(validationErrorHandler); + setQuESTInputErrorHandler(validationErrorHandler); setRandomTestStateSeeds(); int result = Catch::Session().run( argc, argv ); diff --git a/tests/deprecated/test_unitaries.cpp b/tests/deprecated/test_unitaries.cpp index f0bb2f5aa..6cfd9e803 100644 --- a/tests/deprecated/test_unitaries.cpp +++ b/tests/deprecated/test_unitaries.cpp @@ -31,13 +31,13 @@ QMatrix refMatr = toQMatrix(quregMatr); \ assertQuregAndRefInDebugState(quregVec, refVec); \ assertQuregAndRefInDebugState(quregMatr, refMatr); \ - setValidationEpsilon(REAL_EPS); + setQuESTValidationEpsilon(REAL_EPS); /** Destroys the data structures made by PREPARE_TEST */ #define CLEANUP_TEST(quregVec, quregMatr) \ destroyQureg(quregVec); \ destroyQureg(quregMatr); \ - setValidationEpsilon(REAL_EPS); + setQuESTValidationEpsilon(REAL_EPS); /* allows concise use of ContainsSubstring in catch's REQUIRE_THROWS_WITH */ using Catch::Matchers::ContainsSubstring; diff --git a/tests/main.cpp b/tests/main.cpp index fca57f5ff..dc1032d92 100644 --- a/tests/main.cpp +++ b/tests/main.cpp @@ -125,7 +125,7 @@ int main(int argc, char* argv[]) { // prepare QuEST before anything else, since many // testing utility functions repurpose QuEST ones initQuESTEnv(); - setInputErrorHandler(validationErrorHandler); + setQuESTInputErrorHandler(validationErrorHandler); // ensure RNG consensus among all nodes setRandomTestStateSeeds(); diff --git a/tests/unit/debug.cpp b/tests/unit/debug.cpp index 07a967493..714cffe7b 100644 --- a/tests/unit/debug.cpp +++ b/tests/unit/debug.cpp @@ -46,7 +46,7 @@ using std::vector; */ -TEST_CASE( "setInputErrorHandler", TEST_CATEGORY ) { +TEST_CASE( "setQuESTInputErrorHandler", TEST_CATEGORY ) { /// @todo /// We can test this by saving the current handler, @@ -62,7 +62,7 @@ TEST_CASE( "setInputErrorHandler", TEST_CATEGORY ) { } -TEST_CASE( "setMaxNumReportedSigFigs", TEST_CATEGORY ) { +TEST_CASE( "setQuESTMaxNumReportedSigFigs", TEST_CATEGORY ) { SECTION( LABEL_CORRECTNESS ) { @@ -77,11 +77,11 @@ TEST_CASE( "setMaxNumReportedSigFigs", TEST_CATEGORY ) { }; // disable auto \n after lines - setNumReportedNewlines(0); + setQuESTNumReportedNewlines(0); for (size_t numSigFigs=1; numSigFigs<=refs.size(); numSigFigs++) { - setMaxNumReportedSigFigs(numSigFigs); + setQuESTMaxNumReportedSigFigs(numSigFigs); // redirect stdout to buffer std::stringstream buffer; @@ -103,22 +103,22 @@ TEST_CASE( "setMaxNumReportedSigFigs", TEST_CATEGORY ) { int num = GENERATE( -1, 0 ); - REQUIRE_THROWS_WITH( setMaxNumReportedSigFigs(num), ContainsSubstring("Cannot be less than one") ); + REQUIRE_THROWS_WITH( setQuESTMaxNumReportedSigFigs(num), ContainsSubstring("Cannot be less than one") ); } } // restore to QuEST default for future tests - setMaxNumReportedSigFigs(5); + setQuESTMaxNumReportedSigFigs(5); } -TEST_CASE( "setNumReportedNewlines", TEST_CATEGORY ) { +TEST_CASE( "setQuESTNumReportedNewlines", TEST_CATEGORY ) { SECTION( LABEL_CORRECTNESS ) { for (int numNewlines=0; numNewlines<3; numNewlines++) { - setNumReportedNewlines(numNewlines); + setQuESTNumReportedNewlines(numNewlines); // redirect stdout to buffer std::stringstream buffer; @@ -138,23 +138,23 @@ TEST_CASE( "setNumReportedNewlines", TEST_CATEGORY ) { SECTION( "number" ) { - REQUIRE_THROWS_WITH( setNumReportedNewlines(-1), ContainsSubstring("Cannot generally be less than zero") ); + REQUIRE_THROWS_WITH( setQuESTNumReportedNewlines(-1), ContainsSubstring("Cannot generally be less than zero") ); } SECTION( "multine number" ) { - setNumReportedNewlines(0); + setQuESTNumReportedNewlines(0); REQUIRE_THROWS_WITH( reportQuESTEnv(), ContainsSubstring("zero") && ContainsSubstring("not permitted when calling multi-line") ); } } // restore to QuEST default for future tests - setNumReportedNewlines(2); + setQuESTNumReportedNewlines(2); } -TEST_CASE( "setSeeds", TEST_CATEGORY ) { +TEST_CASE( "setQuESTSeeds", TEST_CATEGORY ) { SECTION( LABEL_CORRECTNESS ) { @@ -173,7 +173,7 @@ TEST_CASE( "setSeeds", TEST_CATEGORY ) { const int numReps = 5; // set an arbitrary fixed seed... - setSeeds(seeds, numSeeds); + setQuESTSeeds(seeds, numSeeds); // generate and remember a random state initRandomMixedState(qureg, numMixedStates); @@ -188,7 +188,7 @@ TEST_CASE( "setSeeds", TEST_CATEGORY ) { for (int r=0; r out(numSeeds); - REQUIRE_NOTHROW( getSeeds(out.data()) ); + REQUIRE_NOTHROW( getQuESTSeeds(out.data()) ); } SECTION( "correct output" ) { @@ -319,11 +319,11 @@ TEST_CASE( "getSeeds", TEST_CATEGORY ) { in[i] = static_cast(getRandomInt(0, 99999)); // pass seeds to QuEST - setSeeds(in.data(), numSeeds); + setQuESTSeeds(in.data(), numSeeds); // check we get them back vector out(numSeeds); - getSeeds(out.data()); + getQuESTSeeds(out.data()); for (int i=0; i(getRandomInt(0, 99999)); // pass seeds to QuEST - setSeeds(in.data(), numSeeds); + setQuESTSeeds(in.data(), numSeeds); // confirm we get out correct number - REQUIRE( getNumSeeds() == numSeeds ); + REQUIRE( getQuESTNumSeeds() == numSeeds ); } } @@ -380,20 +380,20 @@ TEST_CASE( "getNumSeeds", TEST_CATEGORY ) { } // re-randomise seeds for remaining tests - setSeedsToDefault(); + setQuESTSeedsToDefault(); } -TEST_CASE( "setValidationOn", TEST_CATEGORY ) { +TEST_CASE( "setQuESTValidationOn", TEST_CATEGORY ) { SECTION( LABEL_CORRECTNESS ) { // always safe to call for (int i=0; i<3; i++) - REQUIRE_NOTHROW( setValidationOn() ); + REQUIRE_NOTHROW( setQuESTValidationOn() ); // illegal and caught - REQUIRE_THROWS( setSeeds(nullptr, -99) ); + REQUIRE_THROWS( setQuESTSeeds(nullptr, -99) ); } SECTION( LABEL_VALIDATION ) { @@ -404,13 +404,13 @@ TEST_CASE( "setValidationOn", TEST_CATEGORY ) { } -TEST_CASE( "setValidationOff", TEST_CATEGORY ) { +TEST_CASE( "setQuESTValidationOff", TEST_CATEGORY ) { SECTION( LABEL_CORRECTNESS ) { // confirm always safe to call for (int i=0; i<3; i++) - REQUIRE_NOTHROW( setValidationOff() ); + REQUIRE_NOTHROW( setQuESTValidationOff() ); // prepare non-unitary matrix CompMatr1 m = getCompMatr1({{1,2},{3,4}}); @@ -420,7 +420,7 @@ TEST_CASE( "setValidationOff", TEST_CATEGORY ) { REQUIRE_NOTHROW( applyCompMatr1(qureg, 0, m) ); // which otherwise triggers - setValidationOn(); + setQuESTValidationOn(); REQUIRE_THROWS( applyCompMatr1(qureg, 0, m) ); destroyQureg(qureg); @@ -433,11 +433,11 @@ TEST_CASE( "setValidationOff", TEST_CATEGORY ) { } // ensure validation is on for remaining tests - setValidationOn(); + setQuESTValidationOn(); } -TEST_CASE( "setValidationEpsilon", TEST_CATEGORY ) { +TEST_CASE( "setQuESTValidationEpsilon", TEST_CATEGORY ) { SECTION( LABEL_CORRECTNESS ) { @@ -454,14 +454,14 @@ TEST_CASE( "setValidationEpsilon", TEST_CATEGORY ) { REQUIRE_THROWS( applyCompMatr1(qureg, 0, m) ); // confirm setting = 0 disables epsilon errors... - setValidationEpsilon(0); + setQuESTValidationEpsilon(0); REQUIRE_NOTHROW( applyCompMatr1(qureg, 0, m) ); // but does not disable absolute errors REQUIRE_THROWS( applyCompMatr1(qureg, -1, m) ); // confirm non-zero (forgive all) works - setValidationEpsilon(9999); // bigger than dist of m*conj(m) from identity squared + setQuESTValidationEpsilon(9999); // bigger than dist of m*conj(m) from identity squared REQUIRE_NOTHROW( applyCompMatr1(qureg, 0, m) ); } @@ -483,7 +483,7 @@ TEST_CASE( "setValidationEpsilon", TEST_CATEGORY ) { *(m.isApproxUnitary) = 1; *(m.isApproxHermitian) = 1; - setValidationEpsilon(.1); + setQuESTValidationEpsilon(.1); REQUIRE( *(m.isApproxUnitary) == -1 ); REQUIRE( *(m.isApproxHermitian) == -1 ); @@ -497,7 +497,7 @@ TEST_CASE( "setValidationEpsilon", TEST_CATEGORY ) { *(m.isApproxHermitian) = 0; *(m.isApproxNonZero) = 1; - setValidationEpsilon(.1); + setQuESTValidationEpsilon(.1); REQUIRE( *(m.isApproxUnitary) == -1 ); REQUIRE( *(m.isApproxHermitian) == -1 ); REQUIRE( *(m.isApproxNonZero) == -1 ); @@ -512,7 +512,7 @@ TEST_CASE( "setValidationEpsilon", TEST_CATEGORY ) { *(m.isApproxHermitian) = 0; *(m.isApproxNonZero) = 1; - setValidationEpsilon(.1); + setQuESTValidationEpsilon(.1); REQUIRE( *(m.isApproxUnitary) == -1 ); REQUIRE( *(m.isApproxHermitian) == -1 ); REQUIRE( *(m.isApproxNonZero) == -1 ); @@ -525,7 +525,7 @@ TEST_CASE( "setValidationEpsilon", TEST_CATEGORY ) { KrausMap k = createKrausMap(1, 3); *(k.isApproxCPTP) = 1; - setValidationEpsilon(.1); + setQuESTValidationEpsilon(.1); REQUIRE( *(k.isApproxCPTP) == -1 ); destroyKrausMap(k); @@ -539,30 +539,30 @@ TEST_CASE( "setValidationEpsilon", TEST_CATEGORY ) { qreal eps = GENERATE( -0.5, -1, -100 ); - REQUIRE_THROWS_WITH( setValidationEpsilon(eps), ContainsSubstring("positive number") ); + REQUIRE_THROWS_WITH( setQuESTValidationEpsilon(eps), ContainsSubstring("positive number") ); } } // ensure validation epsilon is default for remaining tests - setValidationEpsilonToDefault(); + setQuESTValidationEpsilonToDefault(); } -TEST_CASE( "getValidationEpsilon", TEST_CATEGORY ) { +TEST_CASE( "getQuESTValidationEpsilon", TEST_CATEGORY ) { SECTION( LABEL_CORRECTNESS ) { // confirm always safe to call for (int i=0; i<3; i++) - REQUIRE_NOTHROW( getValidationEpsilon() ); // ignores output + REQUIRE_NOTHROW( getQuESTValidationEpsilon() ); // ignores output GENERATE( range(0,10) ); // confirm set correctly qreal eps = getRandomReal(0, 99999); - setValidationEpsilon(eps); + setQuESTValidationEpsilon(eps); - REQUIRE( getValidationEpsilon() == eps ); + REQUIRE( getQuESTValidationEpsilon() == eps ); } SECTION( LABEL_VALIDATION ) { @@ -572,18 +572,18 @@ TEST_CASE( "getValidationEpsilon", TEST_CATEGORY ) { } // ensure validation epsilon is default for remaining tests - setValidationEpsilonToDefault(); + setQuESTValidationEpsilonToDefault(); } -TEST_CASE( "setValidationEpsilonToDefault", TEST_CATEGORY ) { +TEST_CASE( "setQuESTValidationEpsilonToDefault", TEST_CATEGORY ) { SECTION( LABEL_CORRECTNESS ) { SECTION( "always safe to call" ) { for (int i=0; i<3; i++) - REQUIRE_NOTHROW( setValidationEpsilonToDefault() ); + REQUIRE_NOTHROW( setQuESTValidationEpsilonToDefault() ); } SECTION( "affects validation" ) { @@ -596,11 +596,11 @@ TEST_CASE( "setValidationEpsilonToDefault", TEST_CATEGORY ) { REQUIRE_THROWS( applyCompMatr1(qureg, 0, m) ); // confirm setting = 0 disables epsilon errors... - setValidationEpsilon(0); + setQuESTValidationEpsilon(0); REQUIRE_NOTHROW( applyCompMatr1(qureg, 0, m) ); // which returns when stored to default - setValidationEpsilonToDefault(); + setQuESTValidationEpsilonToDefault(); REQUIRE_THROWS( applyCompMatr1(qureg, 0, m) ); destroyQureg(qureg); @@ -614,7 +614,7 @@ TEST_CASE( "setValidationEpsilonToDefault", TEST_CATEGORY ) { *(m.isApproxUnitary) = 1; *(m.isApproxHermitian) = 1; - setValidationEpsilonToDefault(); + setQuESTValidationEpsilonToDefault(); REQUIRE( *(m.isApproxUnitary) == -1 ); REQUIRE( *(m.isApproxHermitian) == -1 ); @@ -628,7 +628,7 @@ TEST_CASE( "setValidationEpsilonToDefault", TEST_CATEGORY ) { *(m.isApproxHermitian) = 0; *(m.isApproxNonZero) = 1; - setValidationEpsilonToDefault(); + setQuESTValidationEpsilonToDefault(); REQUIRE( *(m.isApproxUnitary) == -1 ); REQUIRE( *(m.isApproxHermitian) == -1 ); REQUIRE( *(m.isApproxNonZero) == -1 ); @@ -643,7 +643,7 @@ TEST_CASE( "setValidationEpsilonToDefault", TEST_CATEGORY ) { *(m.isApproxHermitian) = 0; *(m.isApproxNonZero) = 1; - setValidationEpsilonToDefault(); + setQuESTValidationEpsilonToDefault(); REQUIRE( *(m.isApproxUnitary) == -1 ); REQUIRE( *(m.isApproxHermitian) == -1 ); REQUIRE( *(m.isApproxNonZero) == -1 ); @@ -656,7 +656,7 @@ TEST_CASE( "setValidationEpsilonToDefault", TEST_CATEGORY ) { KrausMap k = createKrausMap(1, 3); *(k.isApproxCPTP) = 1; - setValidationEpsilonToDefault(); + setQuESTValidationEpsilonToDefault(); REQUIRE( *(k.isApproxCPTP) == -1 ); destroyKrausMap(k); @@ -674,21 +674,21 @@ TEST_CASE( "setValidationEpsilonToDefault", TEST_CATEGORY ) { } // ensure validation epsilon is default for remaining tests - setValidationEpsilonToDefault(); + setQuESTValidationEpsilonToDefault(); } -TEST_CASE( "getGpuCacheSize", TEST_CATEGORY ) { +TEST_CASE( "getQuESTGpuCacheSize", TEST_CATEGORY ) { SECTION( LABEL_CORRECTNESS ) { // confirm cache begins empty - clearGpuCache(); - REQUIRE( getGpuCacheSize() == 0 ); + clearQuESTGpuCache(); + REQUIRE( getQuESTGpuCacheSize() == 0 ); // hackily detect cuQuantum char envStr[200]; - getEnvironmentString(envStr); + getQuESTEnvironmentString(envStr); bool usingCuQuantum = std::string(envStr).find("cuQuantum=0") == std::string::npos; // proceed only if we're ever using our own GPU cache @@ -716,7 +716,7 @@ TEST_CASE( "getGpuCacheSize", TEST_CATEGORY ) { // confirm it expanded, OR stayed the same, which happens when // the total number of simultaneous threads needed hits/exceeds // the number available in the hardware - qindex newSize = getGpuCacheSize(); + qindex newSize = getQuESTGpuCacheSize(); CAPTURE( cacheSize, newSize ); REQUIRE( newSize >= cacheSize ); @@ -746,10 +746,10 @@ TEST_CASE( "getGpuCacheSize", TEST_CATEGORY ) { */ -void setMaxNumReportedItems(qindex numRows, qindex numCols); +void setQuESTMaxNumReportedItems(qindex numRows, qindex numCols); -void getEnvironmentString(char str[200]); +void getQuESTEnvironmentString(char str[200]); -void setReportedPauliChars(const char* paulis); +void setQuESTReportedPauliChars(const char* paulis); -void setReportedPauliStrStyle(int style); +void setQuESTReportedPauliStrStyle(int style); diff --git a/tests/unit/operations.cpp b/tests/unit/operations.cpp index 0e33220db..80b75b9c2 100644 --- a/tests/unit/operations.cpp +++ b/tests/unit/operations.cpp @@ -744,8 +744,8 @@ void testOperationCorrectness(auto operation, auto matrixRefGen) { // upon few qubits are single-precision. So we disable completely until // we re-implement 'input validation' checks which force us to fix thresholds (Args == compmatr)? - setValidationEpsilon(0): - setValidationEpsilonToDefault(); + setQuESTValidationEpsilon(0): + setQuESTValidationEpsilonToDefault(); // prepare test function which will receive both statevectors and density matrices auto testFunc = [&](Qureg qureg, auto& stateRef) -> void { @@ -777,7 +777,7 @@ void testOperationCorrectness(auto operation, auto matrixRefGen) { // free any heap-alloated API matrices and restore epsilon freeRemainingArgs(furtherArgs); - setValidationEpsilonToDefault(); + setQuESTValidationEpsilonToDefault(); } @@ -1724,8 +1724,8 @@ TEST_CASE( "applyForcedQubitMeasurement", TEST_CATEGORY_OPS ) { // below validation tests assume qubit 0 can collapse to either outcome // (which does not require normalisation; qureg can be in the debug state) initDebugState(qureg); - REQUIRE( calcProbOfQubitOutcome(qureg, 0, 0) > getValidationEpsilon() ); - REQUIRE( calcProbOfQubitOutcome(qureg, 0, 1) > getValidationEpsilon() ); + REQUIRE( calcProbOfQubitOutcome(qureg, 0, 0) > getQuESTValidationEpsilon() ); + REQUIRE( calcProbOfQubitOutcome(qureg, 0, 1) > getQuESTValidationEpsilon() ); SECTION( "qureg uninitialised" ) { @@ -1778,7 +1778,7 @@ TEST_CASE( "applyForcedQubitMeasurement", TEST_CATEGORY_OPS ) { qreal goodTheta = 0.1; applyRotateX(qureg, 0, goodTheta); REQUIRE( - calcProbOfQubitOutcome(qureg, 0, badOutcome) > getValidationEpsilon() + calcProbOfQubitOutcome(qureg, 0, badOutcome) > getQuESTValidationEpsilon() ); REQUIRE_NOTHROW( applyForcedQubitMeasurement(qureg, 0, badOutcome) @@ -1806,7 +1806,7 @@ TEST_CASE( "applyForcedMultiQubitMeasurement", TEST_CATEGORY_OPS ) { // this test may randomly request a measurement outcome which // is illegally unlikely, triggering validation; we merely // disable such validation and hope divergences don't break the test! - setValidationEpsilon(0); + setQuESTValidationEpsilon(0); auto testFunc = [&](Qureg qureg, auto& ref) { @@ -1830,7 +1830,7 @@ TEST_CASE( "applyForcedMultiQubitMeasurement", TEST_CATEGORY_OPS ) { SECTION( LABEL_STATEVEC ) { TEST_ON_CACHED_QUREGS(statevecQuregs, statevecRef, testFunc); } SECTION( LABEL_DENSMATR ) { TEST_ON_CACHED_QUREGS(densmatrQuregs, densmatrRef, testFunc); } - setValidationEpsilonToDefault(); + setQuESTValidationEpsilonToDefault(); } SECTION( LABEL_VALIDATION ) { @@ -1842,7 +1842,7 @@ TEST_CASE( "applyForcedMultiQubitMeasurement", TEST_CATEGORY_OPS ) { // below validation tests assume the above parameters are valid (not impossibly unlikely) initDebugState(qureg); - REQUIRE( calcProbOfMultiQubitOutcome(qureg, targets, outcomes, numTargets) > getValidationEpsilon() ); + REQUIRE( calcProbOfMultiQubitOutcome(qureg, targets, outcomes, numTargets) > getQuESTValidationEpsilon() ); SECTION( "qureg uninitialised" ) { @@ -1920,7 +1920,7 @@ TEST_CASE( "applyForcedMultiQubitMeasurement", TEST_CATEGORY_OPS ) { applyRotateX(qureg, targets[2], goodTheta); int goodOutcomes[] = {0, 0, 1}; REQUIRE( - calcProbOfMultiQubitOutcome(qureg, targets, goodOutcomes, numTargets) > getValidationEpsilon() + calcProbOfMultiQubitOutcome(qureg, targets, goodOutcomes, numTargets) > getQuESTValidationEpsilon() ); REQUIRE_NOTHROW( applyForcedMultiQubitMeasurement(qureg, targets, goodOutcomes, numTargets) @@ -2291,7 +2291,7 @@ TEST_CASE( "applyFullStateDiagMatrPower", TEST_CATEGORY_OPS LABEL_MIXED_DEPLOY_T GENERATE( range(0, getNumTestedMixedDeploymentRepetitions()) ); if (!testRealExp) - setValidationEpsilon(0); + setQuESTValidationEpsilon(0); SECTION( LABEL_STATEVEC ) { @@ -2313,7 +2313,7 @@ TEST_CASE( "applyFullStateDiagMatrPower", TEST_CATEGORY_OPS LABEL_MIXED_DEPLOY_T TEST_ON_CACHED_QUREG_AND_MATRIX( cachedDM, cachedMatrs, apiFunc, refDM, refMatr, refFunc); } - setValidationEpsilonToDefault(); + setQuESTValidationEpsilonToDefault(); } /// @todo input validation diff --git a/tests/unit/trotterisation.cpp b/tests/unit/trotterisation.cpp index 5e264ad53..216d5e8d8 100644 --- a/tests/unit/trotterisation.cpp +++ b/tests/unit/trotterisation.cpp @@ -268,8 +268,8 @@ TEST_CASE( "applyTrotterizedUnitaryTimeEvolution", TEST_CATEGORY ) { // - 1E-5 at single precision // - 1E-12 at double precision // - 1E-13 at quad precision - qreal initialValidationEps = getValidationEpsilon(); - setValidationEpsilon(2 * initialValidationEps); + qreal initialValidationEps = getQuESTValidationEpsilon(); + setQuESTValidationEpsilon(2 * initialValidationEps); const int NUM_QUBITS = 8; qreal dt = 0.1; @@ -331,7 +331,7 @@ TEST_CASE( "applyTrotterizedUnitaryTimeEvolution", TEST_CATEGORY ) { } // Restore validation epsilon - setValidationEpsilon(initialValidationEps); + setQuESTValidationEpsilon(initialValidationEps); destroyPauliStrSum(hamil); destroyPauliStrSum(observ); diff --git a/tests/utils/random.cpp b/tests/utils/random.cpp index 65d087518..5c2fe143c 100644 --- a/tests/utils/random.cpp +++ b/tests/utils/random.cpp @@ -44,10 +44,10 @@ void setRandomTestStateSeeds() { unsigned seed = cspnrg(); // seed QuEST, which uses only the root node's seed - setSeeds(&seed, 1); + setQuESTSeeds(&seed, 1); // broadcast root node seed to all nodes - getSeeds(&seed); + getQuESTSeeds(&seed); // seed RNG RNG.seed(seed);