The Quantum Exact Simulation Toolkit v4.0.0
Loading...
Searching...
No Matches
debug.cpp
1/** @file
2 * API definitions for debugging QuEST behaviour,
3 * controlling input validation, changing reporter
4 * parameters or seeding random generation.
5 *
6 * @author Tyson Jones
7 */
8
9#include "quest/include/types.h"
10
11#include "quest/src/core/validation.hpp"
12#include "quest/src/core/printer.hpp"
13#include "quest/src/core/utilities.hpp"
14#include "quest/src/core/randomiser.hpp"
15#include "quest/src/gpu/gpu_config.hpp"
16
17#include <vector>
18#include <limits>
19
20// enable invocation by both C and C++ binaries
21extern "C" {
22
23
24
25/*
26 * SEEDING
27 */
28
29
30void setSeeds(unsigned* seeds, int numSeeds) {
31 validate_envIsInit(__func__);
32 validate_randomSeeds(seeds, numSeeds, __func__);
33
34 // consults only root-node seeds
35 rand_setSeeds(std::vector<unsigned>(seeds, seeds+numSeeds));
36}
37
39 validate_envIsInit(__func__);
40
41 rand_setSeedsToDefault();
42}
43
44
46 validate_envIsInit(__func__);
47
48 return rand_getNumSeeds();
49}
50
51void getSeeds(unsigned* seeds) {
52 validate_envIsInit(__func__);
53
54 auto vec = rand_getSeeds();
55 auto num = rand_getNumSeeds();
56
57 for (int i=0; i<num; i++)
58 seeds[i] = vec[i];
59}
60
61
62
63/*
64 * VALIDATION
65 */
66
67
69 validate_envIsInit(__func__);
70
71 validateconfig_enable();
72}
73
75 validate_envIsInit(__func__);
76
77 // disables all validation and computation
78 // of matrix properties like isUnitary. Also
79 // means pre-computed matrix properties are
80 // ignored. It does not however erase pre-
81 // computed properties; subsequently restoring
82 // validation will not necessitate re-eval.
83
84 validateconfig_disable();
85}
86
87
88void setValidationEpsilon(qreal eps) {
89 validate_envIsInit(__func__);
90 validate_newEpsilonValue(eps, __func__);
91
92 validateconfig_setEpsilon(eps);
93 util_setEpsilonSensitiveHeapFlagsToUnknown();
94}
95
97 validate_envIsInit(__func__);
98
99 validateconfig_setEpsilonToDefault();
100 util_setEpsilonSensitiveHeapFlagsToUnknown();
101}
102
104 validate_envIsInit(__func__);
105
106 return validateconfig_getEpsilon();
107}
108
109
110
111/*
112 * REPORTER CONFIGURATION
113 */
114
115
116void setMaxNumReportedItems(qindex numRows, qindex numCols) {
117 validate_envIsInit(__func__);
118 validate_newMaxNumReportedScalars(numRows, numCols, __func__);
119
120 // replace 0 values (indicating no truncation) with max-val,
121 // since there can never be max(qindex)-many amps
122 qindex max = std::numeric_limits<qindex>::max();
123 numRows = (numRows == 0)? max : numRows;
124 numCols = (numCols == 0)? max : numCols;
125
126 printer_setMaxNumPrintedScalars(numRows, numCols);
127}
128
129
130void setMaxNumReportedSigFigs(int numSigFigs) {
131 validate_envIsInit(__func__);
132 validate_newMaxNumReportedSigFigs(numSigFigs, __func__);
133
134 printer_setMaxNumPrintedSigFig(numSigFigs);
135}
136
137
138void setNumReportedNewlines(int numNewlines) {
139 validate_envIsInit(__func__);
140 validate_newNumReportedNewlines(numNewlines, __func__);
141
142 printer_setNumTrailingNewlines(numNewlines);
143}
144
145
146
147/*
148 * GPU CACHE
149 */
150
151
153 validate_envIsInit(__func__);
154
155 if (getQuESTEnv().isGpuAccelerated)
156 return gpu_getCacheMemoryInBytes();
157
158 // safely returns 0 if not GPU accelerated
159 return 0;
160}
161
162
164 validate_envIsInit(__func__);
165
166 // safely do nothing if not GPU accelerated
167 if (getQuESTEnv().isGpuAccelerated)
168 gpu_clearCache();
169}
170
171
172
173} // end de-name mangler
qindex getGpuCacheSize()
Definition debug.cpp:152
void clearGpuCache()
Definition debug.cpp:163
void setMaxNumReportedItems(qindex numRows, qindex numCols)
Definition debug.cpp:116
void setMaxNumReportedSigFigs(int numSigFigs)
Definition debug.cpp:130
void setNumReportedNewlines(int numNewlines)
Definition debug.cpp:138
void setSeedsToDefault()
Definition debug.cpp:38
int getNumSeeds()
Definition debug.cpp:45
void setSeeds(unsigned *seeds, int numSeeds)
Definition debug.cpp:30
void getSeeds(unsigned *seeds)
Definition debug.cpp:51
void setValidationOff()
Definition debug.cpp:74
void setValidationEpsilonToDefault()
Definition debug.cpp:96
void setValidationOn()
Definition debug.cpp:68
qreal getValidationEpsilon()
Definition debug.cpp:103
void setValidationEpsilon(qreal eps)
Definition debug.cpp:88
QuESTEnv getQuESTEnv()