GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing quest-kit.github.io โ The Quantum Exact Simulation Toolkit: Validation
Loading...
Searching...
No Matches
Functions to control QuEST's user-input validation. More...
Detailed DescriptionFunctions to control QuEST's user-input validation. These can be used to adjust the precision with which properties like unitarity are checked/enforced, or otherwise disable all input validation (e.g. is the given qubit index valid?). Note passing erroneous input while validation is disabled can result in runtime errors like segmentation faults. Function Documentationโ getQuESTValidationEpsilon()
Returns the threshold used by QuEST's numerical validation. This is the value last passed to setQuESTValidationEpsilon(), unless overridden by setQuESTValidationEpsilonToDefault(), or similarly if never called. It indicates the precision and correctness demanded of input numerical quantities to the QuEST API. A larger epsilon corresponds to more permissive validation, while a smaller epsilon means validation is harder to pass and input quantities must be more carefully prepared.
The exact usage of the validation epsilon is function specific. For an example, see applyCompMatr1(). The validation has no effect when validation has been disabled entirely via setQuESTValidationOff().
Definition at line 115 of file debug.cpp. 115 {
116 validate_envIsInit(__func__);
117
118 return validateconfig_getEpsilon();
119}
โ setQuESTInputErrorHandler()
Sets the function which QuEST will call when encountering an invalid input. By default, when a user passes an invalid input to QuEST (such as a negative qubit index), an internal function QuEST endeavours to perform input validation upfront before proceeding to any mutation of passed objects (like a Qureg). This permits gracefully catching validation errors through custom handling without corrupting QuEST's state. For example,
Note validation can be changed or disabled with setQuESTValidationEpsilon() and setQuESTValidationOff(), which affects when
void myErrorHandler(const char* errFunc, const char* errMsg) {
printf("Ruh-roh, Raggy! Function '%s' has reported '%s'.\n", errFunc, errMsg);
printf("We will now be very good children and exit immediately!\n");
exit(0);
}
int main() {
initQuESTEnv();
setQuESTInputErrorHandler(myErrorHandler);
createQureg(9999); // invokes myErrorHandler
...
}
void setQuESTInputErrorHandler(void(*callback)(const char *func, const char *msg)) Definition debug.cpp:74
Definition at line 74 of file debug.cpp. 74 {
75 validate_envIsInit(__func__);
76
77 validateconfig_setErrorHandler(callback);
78}
โ setQuESTValidationEpsilon()
Modifies QuEST's validation threshold for testing numerical or approximate quantities, to Many of QuEST's API functions validate that expected numerical properties of the input are satisfied. For example, that the matrix passed to applyCompMatr1() is unitary, and ergo that the product of the matrix with its own adjoint produces the identity matrix. Due to floating-point error, such properties cannot be evaluated exactly, and small disagreement between the expected and given property is tolerated. This difference is the validation epsilon, as overridden by this function. Precisely how the validation epsilon is used by numerical validation is function specific, and individually documented.
The validation epsilon has no effect on non-numerical validation, such as whether qubit incices are valid. In general, it is therefore safe to modify and disable numerical validation via this function. The default validation epsilon, which can itself be controlled by the Note that many data structures (e.g. CompMatr, DiagMatr, KrausMap) will assess epsilon-dependent validation properties such as unitarity once, recording the result in a persistent heap field (like KrausMap.isApproxCPTP) to avoid superfluous re-calculation. Updating the global validation epsilon via this function will update all persistent heap fields, marking epsilon-dependent properties as "unknown", which will be lazily re-evaluated when validation is next performed. Ergo, calling this function can cause later additional function overheads.
// | max [matr . adj(matr) - identity] |^2 = 576
setQuESTValidationEpsilon(576.0);
applyCompMatr1(qureg, 0, matr); // no error
matr.elems[0][0] = 999;
setQuESTValidationEpsilon(0); // disable all numerical validation
applyCompMatr1(qureg, 0, matr); // no error
// target=-1 would still trigger an error
// applyCompMatr1(qureg, -1, matr);
CompMatr1 getInlineCompMatr1({{ matrix }}) void applyCompMatr1(Qureg qureg, int target, CompMatr1 matrix) Definition operations.cpp:75 Definition matrices.h:85
Definition at line 100 of file debug.cpp. 100 {
101 validate_envIsInit(__func__);
102 validate_newEpsilonValue(eps, __func__);
103
104 validateconfig_setEpsilon(eps);
105 util_setEpsilonSensitiveHeapFlagsToUnknown();
106}
Referenced by TEST_CASE(), and TEST_CASE(). โ setQuESTValidationEpsilonToDefault()
Restores QuEST's validation threshold for testing numerical or approximate quantities, to its default value. The default value is informed by the environment variable
Definition at line 108 of file debug.cpp. 108 {
109 validate_envIsInit(__func__);
110
111 validateconfig_setEpsilonToDefault();
112 util_setEpsilonSensitiveHeapFlagsToUnknown();
113}
Referenced by TEST_CASE(), and TEST_CASE(). โ setQuESTValidationOff()
Disables all of QuEST's input validation. When a QuEST API function encounters an invalid input, the error will be ignored and execution of the function will proceed. This is useful in order to call a QuEST function in a manner which is ordinarily forbidden to avoid user mistakes.
Users wishing only to adjust numerical validation tolerances, or disable numerical validations such as matrix unitarity checks, should instead use the safer setQuESTValidationEpsilon(). If it is essential to disable all validation, it should be later restored with setQuESTValidationOn().
CompMatr1 matr = getInlineCompMatr1({{1,2},{3,4}});
int target = 4; // 0-2 valid, 3-5 hacky, 6+ seg-fault
leftapplyCompMatr1(qureg, target, matr);
void leftapplyCompMatr1(Qureg qureg, int target, CompMatr1 matrix) Definition multiplication.cpp:40 Definition qureg.h:49
Definition at line 86 of file debug.cpp. 86 {
87 validate_envIsInit(__func__);
88
89 // disables all validation and computation
90 // of matrix properties like isUnitary. Also
91 // means pre-computed matrix properties are
92 // ignored. It does not however erase pre-
93 // computed properties; subsequently restoring
94 // validation will not necessitate re-eval.
95
96 validateconfig_disable();
97}
Referenced by TEST_CASE(). โ setQuESTValidationOn()
Restores QuEST's input validation. This means that invalid inputs to other QuEST API functions will call the error handler (the default, or one passed to setQuESTInputErrorHandler()), rather than be silently ignored. This function only has an affect if setQuESTValidationOff() was prior called. This function does not affect the validation epsilon controlled with setQuESTValidationEpsilon(), which when zero, will still see the skipping of numerically-approximated validations (such as unitarity checks).
Definition at line 80 of file debug.cpp. 80 {
81 validate_envIsInit(__func__);
82
83 validateconfig_enable();
84}
Referenced by TEST_CASE(). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| You are visitor 01402775 โ GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800ร600. No cookies required. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||