Skip to content

Commit 347d7e5

Browse files
minor code cleanup (#672)
which had only the below 4 changes visible to users: - changed the significant figures from 3 to 4 of reported memory (e.g. `3.23e1 KiB` becomes `32.30 KiB`) - fixed a README doc link - renamed to clarify the `setQuregToClone` parameters - suppressed illegitimate unused-variable compiler warnings and otherwise merely tidied internal code. See #672 for all changes.
1 parent 5bd864b commit 347d7e5

File tree

11 files changed

+27
-31
lines changed

11 files changed

+27
-31
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
[![DOI](https://img.shields.io/badge/DOI-10.1038%2Fs41598--019--47174--9-yellow.svg)](https://doi.org/10.1038/s41598-019-47174-9)
2020
<br>
2121
[![GitHub release](https://img.shields.io/github/release/QuEST-Kit/QuEST)](https://GitHub.com/QuEST-Kit/QuEST/releases/)
22-
[![Doc](https://img.shields.io/badge/doc-Github.io-orange.svg)](https://quest-kit.github.io/QuEST/modules.html)
22+
[![Doc](https://img.shields.io/badge/doc-Github.io-orange.svg)](https://quest-kit.github.io/QuEST/group__api.html)
2323
[![MIT license](https://img.shields.io/badge/license-MIT-lightgrey.svg)](LICENCE.txt)
2424

2525

quest/include/initialisations.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ void setDensityQuregFlatAmps(Qureg qureg, qindex startInd, qcomp* amps, qindex n
113113

114114
/// @notyetdoced
115115
/// @notyettested
116-
void setQuregToClone(Qureg targetQureg, Qureg copyQureg);
116+
void setQuregToClone(Qureg outQureg, Qureg inQureg);
117117

118118

119119
/// @notyetdoced

quest/src/api/initialisations.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -171,17 +171,17 @@ void setDensityQuregFlatAmps(Qureg qureg, qindex startInd, qcomp* amps, qindex n
171171
}
172172

173173

174-
void setQuregToClone(Qureg targetQureg, Qureg copyQureg) {
175-
validate_quregFields(targetQureg, __func__);
176-
validate_quregFields(copyQureg, __func__);
177-
validate_quregsCanBeCloned(targetQureg, copyQureg, __func__);
174+
void setQuregToClone(Qureg outQureg, Qureg inQureg) {
175+
validate_quregFields(outQureg, __func__);
176+
validate_quregFields(inQureg, __func__);
177+
validate_quregsCanBeCloned(outQureg, inQureg, __func__);
178178

179179
// we invoke mixing/superposing, which involves superfluous
180180
// floating-point operators but is not expected to cause an
181-
// appreciable slowdown since simulation is memory-bound
182-
(targetQureg.isDensityMatrix)?
183-
localiser_densmatr_mixQureg(0, targetQureg, 1, copyQureg):
184-
localiser_statevec_setQuregToClone(targetQureg, copyQureg);
181+
// appreciable slowdown since simulation is often memory-bound
182+
(outQureg.isDensityMatrix)?
183+
localiser_densmatr_mixQureg(0, outQureg, 1, inQureg):
184+
localiser_statevec_setQuregToClone(outQureg, inQureg);
185185
}
186186

187187

quest/src/api/matrices.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,14 +121,14 @@ template <class T>
121121
bool didAnyLocalAllocsFail(T matr) {
122122

123123
// god help us if these single-integer malloc failed
124-
if (!mem_isAllocated(matr.isApproxUnitary)) return true;
125-
if (!mem_isAllocated(matr.isApproxHermitian)) return true;
126-
if (!mem_isAllocated(matr.wasGpuSynced)) return true;
124+
if (!mem_isAllocated(matr.isApproxUnitary)) return true;
125+
if (!mem_isAllocated(matr.isApproxHermitian)) return true;
126+
if (!mem_isAllocated(matr.wasGpuSynced)) return true;
127127

128128
// only diagonal matrices (which can be raised to
129129
// exponents) have these addtional fields
130130
if constexpr (!util_isDenseMatrixType<T>()) {
131-
if (!mem_isAllocated(matr.isApproxNonZero)) return true;
131+
if (!mem_isAllocated(matr.isApproxNonZero)) return true;
132132
if (!mem_isAllocated(matr.isStrictlyNonNegative)) return true;
133133
}
134134

@@ -280,7 +280,7 @@ FullStateDiagMatr validateAndCreateCustomFullStateDiagMatr(int numQubits, int us
280280
// validate parameters before passing them to autodeployer
281281
validate_newFullStateDiagMatrParams(numQubits, useDistrib, useGpuAccel, useMultithread, caller);
282282

283-
// overwrite useDistrib and useGpuAccel if they were left as AUTO_FLAG
283+
// overwrite all args left as AUTO_FLAG
284284
autodep_chooseFullStateDiagMatrDeployment(numQubits, useDistrib, useGpuAccel, useMultithread, env);
285285

286286
// validation ensures this never overflows

quest/src/core/errors.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -161,11 +161,6 @@ void error_commButEnvNotDistributed() {
161161
raiseInternalError("A function attempted to invoke communication despite QuEST being compiled in non-distributed mode.");
162162
}
163163

164-
void error_commButQuregNotDistributed() {
165-
166-
raiseInternalError("A function attempted to invoke communication of a Qureg which was not distributed.");
167-
}
168-
169164
void error_commOutOfBounds() {
170165

171166
raiseInternalError("A function invoked communication which attempted to exchange amplitudes between arrays at invalid bounds.");
@@ -209,7 +204,7 @@ void assert_commPayloadIsPowerOf2(qindex numAmps) {
209204
void assert_commQuregIsDistributed(Qureg qureg) {
210205

211206
if (!qureg.isDistributed)
212-
error_commButQuregNotDistributed();
207+
raiseInternalError("A function attempted to invoke communication of a Qureg which was not distributed.");
213208
}
214209

215210
void assert_commFullStateDiagMatrIsDistributed(FullStateDiagMatr matr) {

quest/src/core/errors.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,6 @@ void error_commAlreadyInit();
7777

7878
void error_commButEnvNotDistributed();
7979

80-
void error_commButQuregNotDistributed();
81-
8280
void error_commOutOfBounds();
8381

8482
void error_commWithSameRank();

quest/src/core/localiser.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1232,6 +1232,10 @@ void localiser_statevec_anyCtrlAnyTargAnyMatr(Qureg qureg, vector<int> ctrls, ve
12321232
bool transp = false;
12331233
qcomp expo = 1;
12341234

1235+
// suppress warnings since not used by all compile-time expansions below
1236+
(void) transp;
1237+
(void) expo;
1238+
12351239
if constexpr (util_isDiagMatr <T>()) localiser_statevec_anyCtrlAnyTargDiagMatr(qureg, ctrls, ctrlStates, targs, matr, expo, conj);
12361240
if constexpr (util_isDiagMatr1<T>()) localiser_statevec_anyCtrlOneTargDiagMatr(qureg, ctrls, ctrlStates, targs[0], matr, conj);
12371241
if constexpr (util_isDiagMatr2<T>()) localiser_statevec_anyCtrlTwoTargDiagMatr(qureg, ctrls, ctrlStates, targs[0], targs[1], matr, conj);

quest/src/core/printer.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -460,10 +460,9 @@ string printer_getMemoryWithUnitStr(size_t numBytes) {
460460
ind++;
461461
ind--;
462462

463-
// express numBytes in terms of new unit, forcefully rounding to 3 sig-figs max,
464-
// except when the chosen unit is bytes (then we permit all 4 digits)
463+
// express numBytes in terms of new unit, forcefully rounding to 4 sig-figs max
465464
qreal frac = numBytes / static_cast<qreal>(sizes[ind]);
466-
return floatToStr(frac, false, (ind==0)? 4 : 3) + " " + units[ind];
465+
return floatToStr(frac, false, 4) + " " + units[ind];
467466
}
468467

469468

quest/src/core/validation.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3994,6 +3994,9 @@ void validate_quregCanBeWorkspace(Qureg qureg, Qureg workspace, const char* call
39943994
assertThat(
39953995
doQuregsHaveIdenticalMemoryLayouts(qureg, workspace),
39963996
report::QUREG_IS_INCOMPATIBLE_WITH_WORKSPACE, caller);
3997+
3998+
// @todo
3999+
// check whether any of their memories overlap, which is forbidden
39974000
}
39984001

39994002
void validate_numQuregsInSum(int numQuregs, const char* caller) {

quest/src/gpu/gpu_cuquantum.cuh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ void cuquantum_densmatr_oneQubitDephasing_subA(Qureg qureg, int qubit, qreal pro
260260
cu_qcomp a = {1, 0};
261261
cu_qcomp b = {1-2*prob, 0};
262262
cu_qcomp elems[] = {a, b, b, a};
263-
vector<int> targs {qubit, qubit + qureg.numQubits};
263+
vector<int> targs {qubit, util_getBraQubit(qubit,qureg)};
264264

265265
bool conj = false;
266266
cuquantum_statevec_anyCtrlAnyTargDiagMatr_sub(qureg, {}, {}, targs, elems, conj);
@@ -297,7 +297,7 @@ void cuquantum_densmatr_twoQubitDephasing_subA(Qureg qureg, int qubitA, int qubi
297297
cu_qcomp a = {1, 0};
298298
cu_qcomp b = {1-4*prob/3, 0};
299299
cu_qcomp elems[] = {a,b,b,b, b,a,b,b, b,b,a,b, b,b,b,a};
300-
vector<int> targs {qubitA, qubitB, qubitA + qureg.numQubits, qubitB + qureg.numQubits};
300+
vector<int> targs {qubitA, qubitB, util_getBraQubit(qubitA,qureg), util_getBraQubit(qubitB,qureg)};
301301

302302
bool conj = false;
303303
cuquantum_statevec_anyCtrlAnyTargDiagMatr_sub(qureg, {}, {}, targs, elems, conj);

0 commit comments

Comments
 (0)