Skip to content

Commit

Permalink
Debug
Browse files Browse the repository at this point in the history
  • Loading branch information
WrathfulSpatula committed Oct 20, 2024
1 parent c81b264 commit 7dde547
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 10 deletions.
33 changes: 27 additions & 6 deletions src/common/qengine.cl
Original file line number Diff line number Diff line change
Expand Up @@ -587,8 +587,8 @@ void kernel decomposeprob(global cmplx* stateVec, constant bitCapIntOcl4* bitCap
for (bitCapIntOcl k = 0U; k < partPower; k++) {
bitCapIntOcl l = j | (k << start);

cmplx amp = stateVec[l];
real1 nrm = dot(amp, amp);
const cmplx amp = stateVec[l];
const real1 nrm = dot(amp, amp);
partProb += nrm;
partStateAngle[k] += arg(amp) * nrm;
}
Expand All @@ -606,14 +606,28 @@ void kernel decomposeprob(global cmplx* stateVec, constant bitCapIntOcl4* bitCap
l |= (k ^ l) << len;
l = j | l;

cmplx amp = stateVec[l];
real1 nrm = dot(amp, amp);
const cmplx amp = stateVec[l];
const real1 nrm = dot(amp, amp);
partProb += nrm;
remainderStateAngle[k] += arg(amp) * nrm;
}

partStateProb[lcv] = partProb;
}

for (bitCapIntOcl lcv = ID; lcv < remainderPower; lcv += Nthreads) {
const real1 prob = remainderStateProb[lcv];
if (prob > REAL1_EPSILON) {
remainderStateAngle[lcv] /= prob;
}
}

for (bitCapIntOcl lcv = ID; lcv < partPower; lcv += Nthreads) {
const real1 prob = partStateProb[lcv];
if (prob > REAL1_EPSILON) {
partStateAngle[lcv] /= prob;
}
}
}

void kernel decomposeamp(
Expand Down Expand Up @@ -647,7 +661,7 @@ void kernel disposeprob(global cmplx* stateVec, constant bitCapIntOcl4* bitCapIn
for (bitCapIntOcl k = 0U; k < partPower; k++) {
bitCapIntOcl l = j | (k << start);

cmplx amp = stateVec[l];
const cmplx amp = stateVec[l];
partProb += dot(amp, amp);
}

Expand All @@ -662,10 +676,17 @@ void kernel disposeprob(global cmplx* stateVec, constant bitCapIntOcl4* bitCapIn
l |= (k ^ l) << len;
l = j | l;

cmplx amp = stateVec[l];
const cmplx amp = stateVec[l];
remainderStateAngle[k] += arg(amp) * dot(amp, amp);
}
}

for (bitCapIntOcl lcv = ID; lcv < remainderPower; lcv += Nthreads) {
const real1 prob = remainderStateProb[lcv];
if (prob > REAL1_EPSILON) {
remainderStateAngle[lcv] /= prob;
}
}
}

void kernel dispose(global cmplx* stateVec, constant bitCapIntOcl4* bitCapIntOclPtr, global cmplx* nStateVec)
Expand Down
23 changes: 19 additions & 4 deletions src/qengine/state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1290,6 +1290,18 @@ void QEngineCPU::DecomposeDispose(bitLenInt start, bitLenInt length, QEngineCPUP
remainderStateAngle[k] += arg(amp) * nrm;
}
});
par_for(0U, remainderPower, [&](const bitCapIntOcl& lcv, const unsigned& cpu) {
const real1 prob = remainderStateProb[lcv];
if (prob > amplitudeFloor) {
remainderStateAngle[lcv] /= prob;
}
});
par_for(0U, partPower, [&](const bitCapIntOcl& lcv, const unsigned& cpu) {
const real1 prob = partStateProb[lcv];
if (prob > amplitudeFloor) {
partStateAngle[lcv] /= prob;
}
});
} else {
par_for(0U, remainderPower, [&](const bitCapIntOcl& lcv, const unsigned& cpu) {
bitCapIntOcl j;
Expand All @@ -1298,10 +1310,7 @@ void QEngineCPU::DecomposeDispose(bitLenInt start, bitLenInt length, QEngineCPUP

for (bitCapIntOcl k = 0U; k < partPower; ++k) {
bitCapIntOcl l = j | (k << start);

const complex amp = stateVec->read(l);
const real1 nrm = norm(amp);
remainderStateProb[lcv] += nrm;
remainderStateProb[lcv] += norm(stateVec->read(l));
}
});

Expand All @@ -1317,6 +1326,12 @@ void QEngineCPU::DecomposeDispose(bitLenInt start, bitLenInt length, QEngineCPUP
remainderStateAngle[k] += arg(amp) * norm(amp);
}
});
par_for(0U, remainderPower, [&](const bitCapIntOcl& lcv, const unsigned& cpu) {
const real1 prob = remainderStateProb[lcv];
if (prob > amplitudeFloor) {
remainderStateAngle[lcv] /= prob;
}
});
}

if (destination) {
Expand Down

0 comments on commit 7dde547

Please sign in to comment.