diff --git a/QuEST/src/CPU/QuEST_cpu.c b/QuEST/src/CPU/QuEST_cpu.c index 56e82d54..1736de3c 100644 --- a/QuEST/src/CPU/QuEST_cpu.c +++ b/QuEST/src/CPU/QuEST_cpu.c @@ -1641,53 +1641,6 @@ void statevec_cloneQureg(Qureg targetQureg, Qureg copyQureg) { } } -/** - * Initialise the state vector of probability amplitudes such that one qubit is set to 'outcome' and all other qubits are in an equal superposition of zero and one. - * @param[in,out] qureg object representing the set of qubits to be initialised - * @param[in] qubitId id of qubit to set to state 'outcome' - * @param[in] outcome of qubit 'qubitId' - */ -void statevec_initStateOfSingleQubit(Qureg *qureg, int qubitId, int outcome) -{ - long long int chunkSize, stateVecSize; - long long int index; - int bit; - long long int chunkId=qureg->chunkId; - - // dimension of the state vector - chunkSize = qureg->numAmpsPerChunk; - stateVecSize = chunkSize*qureg->numChunks; - qreal normFactor = 1.0/sqrt((qreal)stateVecSize/2.0); - - // Can't use qureg->stateVec as a private OMP var - qreal *stateVecReal = qureg->stateVec.real; - qreal *stateVecImag = qureg->stateVec.imag; - - // initialise the state to |0000..0000> -# ifdef _OPENMP -# pragma omp parallel \ - default (none) \ - shared (chunkSize, stateVecReal, stateVecImag, normFactor, qubitId, outcome, chunkId) \ - private (index, bit) -# endif - { -# ifdef _OPENMP -# pragma omp for schedule (static) -# endif - for (index=0; indexnumAmpsPerChunk; - stateVecSize = chunkSize*qureg->numChunks; - - qreal *stateVecReal = qureg->stateVec.real; - qreal *stateVecImag = qureg->stateVec.imag; - - FILE *fp; - char line[200]; - - for (int rank=0; rank<(qureg->numChunks); rank++){ - if (rank==qureg->chunkId){ - fp = fopen(filename, "r"); - - // indicate file open failure - if (fp == NULL) - return 0; - - indexInChunk = 0; totalIndex = 0; - while (fgets(line, sizeof(char)*200, fp) != NULL && totalIndexchunkId){ - sscanf(line, REAL_SPECIFIER ", " REAL_SPECIFIER, &(stateVecReal[indexInChunk]), - &(stateVecImag[indexInChunk])); - indexInChunk += 1; - } - totalIndex += 1; - } - } - fclose(fp); - } - syncQuESTEnv(env); - } - - // indicate success - return 1; -} - -int statevec_compareStates(Qureg mq1, Qureg mq2, qreal precision){ - qreal diff; - long long int chunkSize = mq1.numAmpsPerChunk; - - for (long long int i=0; iprecision) return 0; - diff = absReal(mq1.stateVec.imag[i] - mq2.stateVec.imag[i]); - if (diff>precision) return 0; - } - return 1; -} - void statevec_compactUnitaryLocal (Qureg qureg, int targetQubit, Complex alpha, Complex beta) { long long int sizeBlock, sizeHalfBlock; diff --git a/QuEST/src/GPU/QuEST_gpu.cu b/QuEST/src/GPU/QuEST_gpu.cu index 3b2138a4..0ce3333d 100755 --- a/QuEST/src/GPU/QuEST_gpu.cu +++ b/QuEST/src/GPU/QuEST_gpu.cu @@ -702,87 +702,6 @@ void statevec_initDebugState(Qureg qureg) qureg.deviceStateVec.imag); } -__global__ void statevec_initStateOfSingleQubitKernel(long long int stateVecSize, qreal *stateVecReal, qreal *stateVecImag, int qubitId, int outcome){ - long long int index; - int bit; - - index = blockIdx.x*blockDim.x + threadIdx.x; - if (index>=stateVecSize) return; - - qreal normFactor = 1.0/sqrt((qreal)stateVecSize/2); - bit = extractBit(qubitId, index); - if (bit==outcome) { - stateVecReal[index] = normFactor; - stateVecImag[index] = 0.0; - } else { - stateVecReal[index] = 0.0; - stateVecImag[index] = 0.0; - } -} - -void statevec_initStateOfSingleQubit(Qureg *qureg, int qubitId, int outcome) -{ - int threadsPerCUDABlock, CUDABlocks; - threadsPerCUDABlock = 128; - CUDABlocks = ceil((qreal)(qureg->numAmpsPerChunk)/threadsPerCUDABlock); - statevec_initStateOfSingleQubitKernel<<>>(qureg->numAmpsPerChunk, qureg->deviceStateVec.real, qureg->deviceStateVec.imag, qubitId, outcome); -} - -// returns 1 if successful, else 0 -int statevec_initStateFromSingleFile(Qureg *qureg, char filename[200], QuESTEnv env){ - long long int chunkSize, stateVecSize; - long long int indexInChunk, totalIndex; - - chunkSize = qureg->numAmpsPerChunk; - stateVecSize = chunkSize*qureg->numChunks; - - qreal *stateVecReal = qureg->stateVec.real; - qreal *stateVecImag = qureg->stateVec.imag; - - FILE *fp; - char line[200]; - - fp = fopen(filename, "r"); - if (fp == NULL) - return 0; - - indexInChunk = 0; totalIndex = 0; - while (fgets(line, sizeof(char)*200, fp) != NULL && totalIndexchunkId){ - sscanf(line, REAL_SPECIFIER ", " REAL_SPECIFIER, &(stateVecReal[indexInChunk]), - &(stateVecImag[indexInChunk])); - indexInChunk += 1; - } - totalIndex += 1; - } - } - fclose(fp); - copyStateToGPU(*qureg); - - // indicate success - return 1; -} - -int statevec_compareStates(Qureg mq1, Qureg mq2, qreal precision){ - qreal diff; - int chunkSize = mq1.numAmpsPerChunk; - - copyStateFromGPU(mq1); - copyStateFromGPU(mq2); - - for (int i=0; iprecision) return 0; - diff = mq1.stateVec.imag[i] - mq2.stateVec.imag[i]; - if (diff<0) diff *= -1; - if (diff>precision) return 0; - } - return 1; -} - __global__ void statevec_compactUnitaryKernel (Qureg qureg, int rotQubit, Complex alpha, Complex beta){ // ----- sizes long long int sizeBlock, // size of blocks diff --git a/QuEST/src/QuEST.c b/QuEST/src/QuEST.c index aae1b433..ff18e5ef 100644 --- a/QuEST/src/QuEST.c +++ b/QuEST/src/QuEST.c @@ -1715,27 +1715,10 @@ void destroySubDiagonalOp(SubDiagonalOp op) { * debug */ -int compareStates(Qureg qureg1, Qureg qureg2, qreal precision) { - validateMatchingQuregDims(qureg1, qureg2, __func__); - return statevec_compareStates(qureg1, qureg2, precision); -} - void initDebugState(Qureg qureg) { statevec_initDebugState(qureg); } -void initStateFromSingleFile(Qureg *qureg, char filename[200], QuESTEnv env) { - int success = statevec_initStateFromSingleFile(qureg, filename, env); - validateFileOpened(success, filename, __func__); -} - -void initStateOfSingleQubit(Qureg *qureg, int qubitId, int outcome) { - validateStateVecQureg(*qureg, __func__); - validateTarget(*qureg, qubitId, __func__); - validateOutcome(outcome, __func__); - statevec_initStateOfSingleQubit(qureg, qubitId, outcome); -} - void reportStateToScreen(Qureg qureg, QuESTEnv env, int reportRank) { statevec_reportStateToScreen(qureg, env, reportRank); } diff --git a/QuEST/src/QuEST_debug.h b/QuEST/src/QuEST_debug.h deleted file mode 100755 index e3861f55..00000000 --- a/QuEST/src/QuEST_debug.h +++ /dev/null @@ -1,61 +0,0 @@ -// Distributed under MIT licence. See https://github.com/QuEST-Kit/QuEST/blob/master/LICENCE.txt for details - -/** @file - * Developer functions used for unit testing and debugging, which are not part of the public API. - * May contain functions that are incomplete or untested. - * - * @author Ania Brown - */ - -# ifndef QUEST_DEBUG_H -# define QUEST_DEBUG_H - -# include "QuEST_precision.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * Initialise the state vector of probability amplitudes such that one qubit is set to 'outcome' and all other qubits are in an equal superposition of zero and one. - * @param[in,out] qureg object representing the set of qubits to be initialised - * @param[in] qubitId id of qubit to set to state 'outcome' - * @param[in] outcome value of qubit 'qubitId' to set - */ -void initStateOfSingleQubit(Qureg *qureg, int qubitId, int outcome); - -/** - * Initialise the state vector of probability amplitudes to an (unphysical) state with - * each component of each probability amplitude a unique floating point value. For debugging processes - * @param[in,out] qureg object representing the set of qubits to be initialised - */ -void initStateDebug(Qureg qureg); - -/** Initialises the wavefunction amplitudes according to those specified in a file. - * For debugging purpsoses - */ -void initStateFromSingleFile(Qureg *qureg, char filename[200], QuESTEnv env); - -/** Return whether two given wavefunctions are equivalent within a given precision - * Global phase included in equivalence check. For debugging purposes. - */ -int compareStates(Qureg mq1, Qureg mq2, qreal precision); - -/** Set elements in the underlying state vector represenation of a density matrix. Not exposed in the public - * API as this requires an understanding of how the state vector is used to represent a density matrix. - * Currently can only be used to set all amps. - */ -void setDensityAmps(Qureg qureg, qreal* reals, qreal* imags); - - - -/** Return the precision of qreal for use in testing - * */ - -int QuESTPrecision(void); - -#ifdef __cplusplus -} -#endif - -# endif // QUEST_DEBUG_H diff --git a/QuEST/src/QuEST_internal.h b/QuEST/src/QuEST_internal.h index 48c2dc74..4fbf9976 100644 --- a/QuEST/src/QuEST_internal.h +++ b/QuEST/src/QuEST_internal.h @@ -119,12 +119,6 @@ void densmatr_setQuregToPauliHamil(Qureg qureg, PauliHamil hamil); void statevec_reportStateToScreen(Qureg qureg, QuESTEnv env, int reportRank); -int statevec_compareStates(Qureg mq1, Qureg mq2, qreal precision); - -int statevec_initStateFromSingleFile(Qureg *qureg, char filename[200], QuESTEnv env); - -void statevec_initStateOfSingleQubit(Qureg *qureg, int qubitId, int outcome); - void statevec_createQureg(Qureg *qureg, int numQubits, QuESTEnv env); void statevec_destroyQureg(Qureg qureg, QuESTEnv env);