diff --git a/README.md b/README.md index 39e193f1..c0c510ba 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) diff --git a/quest/include/initialisations.h b/quest/include/initialisations.h index 99f415bd..468bb794 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 e027ae7e..f49ae472 100644 --- a/quest/src/api/initialisations.cpp +++ b/quest/src/api/initialisations.cpp @@ -171,17 +171,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_setQuregToClone(targetQureg, copyQureg); + // appreciable slowdown since simulation is often memory-bound + (outQureg.isDensityMatrix)? + localiser_densmatr_mixQureg(0, outQureg, 1, inQureg): + localiser_statevec_setQuregToClone(outQureg, inQureg); } diff --git a/quest/src/api/matrices.cpp b/quest/src/api/matrices.cpp index 2c817253..d1c118d1 100644 --- a/quest/src/api/matrices.cpp +++ b/quest/src/api/matrices.cpp @@ -121,14 +121,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; } @@ -280,7 +280,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 diff --git a/quest/src/core/errors.cpp b/quest/src/core/errors.cpp index 4d9d77e1..9e72b1e0 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 dccaaf46..950ac17e 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(); diff --git a/quest/src/core/localiser.cpp b/quest/src/core/localiser.cpp index 8e64814d..9d4dbce0 100644 --- a/quest/src/core/localiser.cpp +++ b/quest/src/core/localiser.cpp @@ -1232,6 +1232,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); diff --git a/quest/src/core/printer.cpp b/quest/src/core/printer.cpp index 016d0525..3d2a4d9f 100644 --- a/quest/src/core/printer.cpp +++ b/quest/src/core/printer.cpp @@ -460,10 +460,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]; } diff --git a/quest/src/core/validation.cpp b/quest/src/core/validation.cpp index 83935bf2..2639b46f 100644 --- a/quest/src/core/validation.cpp +++ b/quest/src/core/validation.cpp @@ -3994,6 +3994,9 @@ void validate_quregCanBeWorkspace(Qureg qureg, Qureg workspace, const char* call assertThat( doQuregsHaveIdenticalMemoryLayouts(qureg, workspace), report::QUREG_IS_INCOMPATIBLE_WITH_WORKSPACE, caller); + + // @todo + // check whether any of their memories overlap, which is forbidden } void validate_numQuregsInSum(int numQuregs, const char* caller) { diff --git a/quest/src/gpu/gpu_cuquantum.cuh b/quest/src/gpu/gpu_cuquantum.cuh index 13afaae8..f627990f 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); diff --git a/tests/unit/initialisations.cpp b/tests/unit/initialisations.cpp index 8890c8ab..649b9290 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());