From 19f0c4627aec0f4503392ae68a48487dde324a83 Mon Sep 17 00:00:00 2001 From: Tyson Jones Date: Wed, 13 Aug 2025 11:47:21 +0200 Subject: [PATCH 01/10] tidying indentation --- quest/src/api/matrices.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/quest/src/api/matrices.cpp b/quest/src/api/matrices.cpp index 019b70f79..8aa1a159b 100644 --- a/quest/src/api/matrices.cpp +++ b/quest/src/api/matrices.cpp @@ -120,14 +120,14 @@ template bool didAnyLocalAllocsFail(T matr) { // god help us if these single-integer malloc failed - if (!mem_isAllocated(matr.isApproxUnitary)) return true; - if (!mem_isAllocated(matr.isApproxHermitian)) return true; - if (!mem_isAllocated(matr.wasGpuSynced)) return true; + if (!mem_isAllocated(matr.isApproxUnitary)) return true; + if (!mem_isAllocated(matr.isApproxHermitian)) return true; + if (!mem_isAllocated(matr.wasGpuSynced)) return true; // only diagonal matrices (which can be raised to // exponents) have these addtional fields if constexpr (!util_isDenseMatrixType()) { - if (!mem_isAllocated(matr.isApproxNonZero)) return true; + if (!mem_isAllocated(matr.isApproxNonZero)) return true; if (!mem_isAllocated(matr.isStrictlyNonNegative)) return true; } @@ -279,7 +279,7 @@ FullStateDiagMatr validateAndCreateCustomFullStateDiagMatr(int numQubits, int us // validate parameters before passing them to autodeployer validate_newFullStateDiagMatrParams(numQubits, useDistrib, useGpuAccel, useMultithread, caller); - // overwrite useDistrib and useGpuAccel if they were left as AUTO_FLAG + // overwrite all args left as AUTO_FLAG autodep_chooseFullStateDiagMatrDeployment(numQubits, useDistrib, useGpuAccel, useMultithread, env); // validation ensures this never overflows From d375d99402e01661e942a7854ef5af8a02820ab4 Mon Sep 17 00:00:00 2001 From: Tyson Jones Date: Wed, 13 Aug 2025 11:47:46 +0200 Subject: [PATCH 02/10] removing superfluously exposed inner error function --- quest/src/core/errors.cpp | 7 +------ quest/src/core/errors.hpp | 2 -- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/quest/src/core/errors.cpp b/quest/src/core/errors.cpp index c1cfd2a02..f0a06111e 100644 --- a/quest/src/core/errors.cpp +++ b/quest/src/core/errors.cpp @@ -161,11 +161,6 @@ void error_commButEnvNotDistributed() { raiseInternalError("A function attempted to invoke communication despite QuEST being compiled in non-distributed mode."); } -void error_commButQuregNotDistributed() { - - raiseInternalError("A function attempted to invoke communication of a Qureg which was not distributed."); -} - void error_commOutOfBounds() { raiseInternalError("A function invoked communication which attempted to exchange amplitudes between arrays at invalid bounds."); @@ -209,7 +204,7 @@ void assert_commPayloadIsPowerOf2(qindex numAmps) { void assert_commQuregIsDistributed(Qureg qureg) { if (!qureg.isDistributed) - error_commButQuregNotDistributed(); + raiseInternalError("A function attempted to invoke communication of a Qureg which was not distributed."); } void assert_commFullStateDiagMatrIsDistributed(FullStateDiagMatr matr) { diff --git a/quest/src/core/errors.hpp b/quest/src/core/errors.hpp index 7097650a7..b79b0a8c7 100644 --- a/quest/src/core/errors.hpp +++ b/quest/src/core/errors.hpp @@ -77,8 +77,6 @@ void error_commAlreadyInit(); void error_commButEnvNotDistributed(); -void error_commButQuregNotDistributed(); - void error_commOutOfBounds(); void error_commWithSameRank(); From 382eb00c7ef48ed75869ffc1276a79bddf89950f Mon Sep 17 00:00:00 2001 From: Tyson Jones Date: Wed, 13 Aug 2025 11:48:07 +0200 Subject: [PATCH 03/10] suppressing unused var warning --- quest/src/core/localiser.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/quest/src/core/localiser.cpp b/quest/src/core/localiser.cpp index 2fa09c9f4..0447073d2 100644 --- a/quest/src/core/localiser.cpp +++ b/quest/src/core/localiser.cpp @@ -1226,6 +1226,10 @@ void localiser_statevec_anyCtrlAnyTargAnyMatr(Qureg qureg, vector ctrls, ve bool transp = false; qcomp expo = 1; + // suppress warnings since not used by all compile-time expansions below + (void) transp; + (void) expo; + if constexpr (util_isDiagMatr ()) localiser_statevec_anyCtrlAnyTargDiagMatr(qureg, ctrls, ctrlStates, targs, matr, expo, conj); if constexpr (util_isDiagMatr1()) localiser_statevec_anyCtrlOneTargDiagMatr(qureg, ctrls, ctrlStates, targs[0], matr, conj); if constexpr (util_isDiagMatr2()) localiser_statevec_anyCtrlTwoTargDiagMatr(qureg, ctrls, ctrlStates, targs[0], targs[1], matr, conj); From 8e519cc509fcb388321b40f3e61fa5d25d812f87 Mon Sep 17 00:00:00 2001 From: Tyson Jones Date: Wed, 13 Aug 2025 11:48:40 +0200 Subject: [PATCH 04/10] fixing missed use of utility functions --- quest/src/gpu/gpu_cuquantum.cuh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/quest/src/gpu/gpu_cuquantum.cuh b/quest/src/gpu/gpu_cuquantum.cuh index 13afaae87..f627990fd 100644 --- a/quest/src/gpu/gpu_cuquantum.cuh +++ b/quest/src/gpu/gpu_cuquantum.cuh @@ -260,7 +260,7 @@ void cuquantum_densmatr_oneQubitDephasing_subA(Qureg qureg, int qubit, qreal pro cu_qcomp a = {1, 0}; cu_qcomp b = {1-2*prob, 0}; cu_qcomp elems[] = {a, b, b, a}; - vector targs {qubit, qubit + qureg.numQubits}; + vector targs {qubit, util_getBraQubit(qubit,qureg)}; bool conj = false; cuquantum_statevec_anyCtrlAnyTargDiagMatr_sub(qureg, {}, {}, targs, elems, conj); @@ -297,7 +297,7 @@ void cuquantum_densmatr_twoQubitDephasing_subA(Qureg qureg, int qubitA, int qubi cu_qcomp a = {1, 0}; cu_qcomp b = {1-4*prob/3, 0}; cu_qcomp elems[] = {a,b,b,b, b,a,b,b, b,b,a,b, b,b,b,a}; - vector targs {qubitA, qubitB, qubitA + qureg.numQubits, qubitB + qureg.numQubits}; + vector targs {qubitA, qubitB, util_getBraQubit(qubitA,qureg), util_getBraQubit(qubitB,qureg)}; bool conj = false; cuquantum_statevec_anyCtrlAnyTargDiagMatr_sub(qureg, {}, {}, targs, elems, conj); From 3b57b6e6f67796e0bf845b9522360466e667481f Mon Sep 17 00:00:00 2001 From: Tyson Jones Date: Wed, 13 Aug 2025 11:49:11 +0200 Subject: [PATCH 05/10] changed printing of memory sizes to 4 sig-figs --- quest/src/core/printer.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/quest/src/core/printer.cpp b/quest/src/core/printer.cpp index 8a7bea15b..08bc8a96d 100644 --- a/quest/src/core/printer.cpp +++ b/quest/src/core/printer.cpp @@ -459,10 +459,9 @@ string printer_getMemoryWithUnitStr(size_t numBytes) { ind++; ind--; - // express numBytes in terms of new unit, forcefully rounding to 3 sig-figs max, - // except when the chosen unit is bytes (then we permit all 4 digits) + // express numBytes in terms of new unit, forcefully rounding to 4 sig-figs max qreal frac = numBytes / static_cast(sizes[ind]); - return floatToStr(frac, false, (ind==0)? 4 : 3) + " " + units[ind]; + return floatToStr(frac, false, 4) + " " + units[ind]; } From 15374b9ca26a05be2e9a740fb5215cc9ced61b6a Mon Sep 17 00:00:00 2001 From: Tyson Jones Date: Wed, 13 Aug 2025 11:49:25 +0200 Subject: [PATCH 06/10] fixed README doc link --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9b03e0578..8c801a07c 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ [![DOI](https://img.shields.io/badge/DOI-10.1038%2Fs41598--019--47174--9-yellow.svg)](https://doi.org/10.1038/s41598-019-47174-9)
[![GitHub release](https://img.shields.io/github/release/QuEST-Kit/QuEST)](https://GitHub.com/QuEST-Kit/QuEST/releases/) - [![Doc](https://img.shields.io/badge/doc-Github.io-orange.svg)](https://quest-kit.github.io/QuEST/modules.html) + [![Doc](https://img.shields.io/badge/doc-Github.io-orange.svg)](https://quest-kit.github.io/QuEST/group__api.html) [![MIT license](https://img.shields.io/badge/license-MIT-lightgrey.svg)](LICENCE.txt) From 864155fd183f763060d0e33db1a5137e82bb9d59 Mon Sep 17 00:00:00 2001 From: Tyson Jones Date: Mon, 18 Aug 2025 23:41:45 +0200 Subject: [PATCH 07/10] clarified setQuregToClone parameters --- quest/include/initialisations.h | 2 +- quest/src/api/initialisations.cpp | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/quest/include/initialisations.h b/quest/include/initialisations.h index 06599fdda..c817cfd0f 100644 --- a/quest/include/initialisations.h +++ b/quest/include/initialisations.h @@ -113,7 +113,7 @@ void setDensityQuregFlatAmps(Qureg qureg, qindex startInd, qcomp* amps, qindex n /// @notyetdoced /// @notyettested -void setQuregToClone(Qureg targetQureg, Qureg copyQureg); +void setQuregToClone(Qureg outQureg, Qureg inQureg); /** @notyetdoced diff --git a/quest/src/api/initialisations.cpp b/quest/src/api/initialisations.cpp index ce3a5949d..8b8071976 100644 --- a/quest/src/api/initialisations.cpp +++ b/quest/src/api/initialisations.cpp @@ -175,17 +175,17 @@ void setDensityQuregFlatAmps(Qureg qureg, qindex startInd, qcomp* amps, qindex n } -void setQuregToClone(Qureg targetQureg, Qureg copyQureg) { - validate_quregFields(targetQureg, __func__); - validate_quregFields(copyQureg, __func__); - validate_quregsCanBeCloned(targetQureg, copyQureg, __func__); +void setQuregToClone(Qureg outQureg, Qureg inQureg) { + validate_quregFields(outQureg, __func__); + validate_quregFields(inQureg, __func__); + validate_quregsCanBeCloned(outQureg, inQureg, __func__); // we invoke mixing/superposing, which involves superfluous // floating-point operators but is not expected to cause an // appreciable slowdown since simulation is memory-bound - (targetQureg.isDensityMatrix)? - localiser_densmatr_mixQureg(0, targetQureg, 1, copyQureg): - localiser_statevec_setQuregToSuperposition(0, targetQureg, 1, copyQureg, 0, copyQureg); + (outQureg.isDensityMatrix)? + localiser_densmatr_mixQureg(0, outQureg, 1, inQureg): + localiser_statevec_setQuregToSuperposition(0, outQureg, 1, inQureg, 0, inQureg); } From ee3f5c619ff22d1a1c2a27e1b96f1213eec636d0 Mon Sep 17 00:00:00 2001 From: Tyson Jones Date: Mon, 18 Aug 2025 23:42:03 +0200 Subject: [PATCH 08/10] removed accidental comment --- tests/unit/initialisations.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/unit/initialisations.cpp b/tests/unit/initialisations.cpp index 90a27ad75..528cdbe5d 100644 --- a/tests/unit/initialisations.cpp +++ b/tests/unit/initialisations.cpp @@ -315,9 +315,6 @@ TEST_CASE( "setDensityQuregFlatAmps", TEST_CATEGORY ) { TEST_CASE( "setDensityQuregAmps", TEST_CATEGORY ) { - //void setDensityQuregAmps(Qureg qureg, qindex startRow, qindex startCol, qcomp** amps, qindex numRows, qindex numCols); - - SECTION( LABEL_CORRECTNESS ) { int numTotalRowsCols = getPow2(getNumCachedQubits()); From 17d3a2afc9f9e741444f5c03c5501fd8cb8c1630 Mon Sep 17 00:00:00 2001 From: Tyson Jones Date: Mon, 18 Aug 2025 23:42:26 +0200 Subject: [PATCH 09/10] added note to improve Qureg workspace validation --- quest/src/core/validation.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/quest/src/core/validation.cpp b/quest/src/core/validation.cpp index a8223cb3f..ab9ebf3bf 100644 --- a/quest/src/core/validation.cpp +++ b/quest/src/core/validation.cpp @@ -3853,6 +3853,9 @@ void validate_quregCanBeWorkspace(Qureg qureg, Qureg workspace, const char* call (qureg.isDistributed == workspace.isDistributed ) && (qureg.isGpuAccelerated == workspace.isGpuAccelerated), report::QUREG_IS_INCOMPATIBLE_WITH_WORKSPACE, caller); + + // @todo + // check whether any of their memories overlap, which is forbidden } void validate_quregsCanBeMixed(Qureg quregOut, Qureg quregIn, const char* caller) { From 3d69a685e04775656f2fa3432b27dbc8e7bd8036 Mon Sep 17 00:00:00 2001 From: Tyson Jones Date: Thu, 4 Sep 2025 16:06:44 -0400 Subject: [PATCH 10/10] correcting merge-conflict mistake --- quest/src/api/initialisations.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/quest/src/api/initialisations.cpp b/quest/src/api/initialisations.cpp index 0cefb9c04..f49ae472c 100644 --- a/quest/src/api/initialisations.cpp +++ b/quest/src/api/initialisations.cpp @@ -179,7 +179,7 @@ void setQuregToClone(Qureg outQureg, Qureg inQureg) { // we invoke mixing/superposing, which involves superfluous // floating-point operators but is not expected to cause an // appreciable slowdown since simulation is often memory-bound - (targetQureg.isDensityMatrix)? + (outQureg.isDensityMatrix)? localiser_densmatr_mixQureg(0, outQureg, 1, inQureg): localiser_statevec_setQuregToClone(outQureg, inQureg); }