Skip to content

Commit

Permalink
removed defunct debugging routines
Browse files Browse the repository at this point in the history
which were unavailable in the API, and were not used internally nor in tests. Furthermore, some of them (`initStateOfSingleQubit`) did something *very* different to what its comments suggested - and inefficiently!
  • Loading branch information
TysonRayJones authored Aug 24, 2023
1 parent d34dc21 commit 2c465c2
Show file tree
Hide file tree
Showing 5 changed files with 0 additions and 268 deletions.
103 changes: 0 additions & 103 deletions QuEST/src/CPU/QuEST_cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -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; index<chunkSize; index++) {
bit = extractBit(qubitId, index+chunkId*chunkSize);
if (bit==outcome) {
stateVecReal[index] = normFactor;
stateVecImag[index] = 0.0;
} else {
stateVecReal[index] = 0.0;
stateVecImag[index] = 0.0;
}
}
}
}


/**
* 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
Expand Down Expand Up @@ -1726,62 +1679,6 @@ void statevec_initDebugState (Qureg qureg)
}
}

// 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];

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 && totalIndex<stateVecSize){
if (line[0]!='#'){
int chunkId = (int) (totalIndex/chunkSize);
if (chunkId==qureg->chunkId){
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; i<chunkSize; i++){
diff = absReal(mq1.stateVec.real[i] - mq2.stateVec.real[i]);
if (diff>precision) 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;
Expand Down
81 changes: 0 additions & 81 deletions QuEST/src/GPU/QuEST_gpu.cu
Original file line number Diff line number Diff line change
Expand Up @@ -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<<<CUDABlocks, threadsPerCUDABlock>>>(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 && totalIndex<stateVecSize){
if (line[0]!='#'){
int chunkId = totalIndex/chunkSize;
if (chunkId==qureg->chunkId){
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; i<chunkSize; i++){
diff = mq1.stateVec.real[i] - mq2.stateVec.real[i];
if (diff<0) diff *= -1;
if (diff>precision) 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
Expand Down
17 changes: 0 additions & 17 deletions QuEST/src/QuEST.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
61 changes: 0 additions & 61 deletions QuEST/src/QuEST_debug.h

This file was deleted.

6 changes: 0 additions & 6 deletions QuEST/src/QuEST_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 2c465c2

Please sign in to comment.