Skip to content

Commit

Permalink
Fix Windows/Mac builds
Browse files Browse the repository at this point in the history
  • Loading branch information
WrathfulSpatula committed Jun 26, 2024
1 parent db6d4d5 commit 7ef95f0
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 1 deletion.
4 changes: 4 additions & 0 deletions include/qbdt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,11 @@ class QBdt : public QParity, public QInterface {
scale *= leaf->scale;
}

#if defined(__APPLE__) || (defined(_WIN32) && !defined(__CYGWIN__))
getLambda((bitCapIntOcl)i, scale);
#else
getLambda((bitCapIntOcl)i, complex((real1)(real(scale).to_double()), (real1)(imag(scale).to_double())));
#endif
});
}
template <typename Fn> void SetTraversal(Fn setLambda)
Expand Down
30 changes: 29 additions & 1 deletion src/qbdt/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,18 @@ void QBdtNode::Prune(bitLenInt depth, bitLenInt parDepth)

if (IS_NODE_0(b0->scale)) {
b0->SetZero();
#if defined(__APPLE__) || (defined(_WIN32) && !defined(__CYGWIN__))
b1->scale /= abs(b1->scale);
#else
b1->scale /= (complex_x)sqrt(norm(b1->scale).to_double());
#endif
} else if (IS_NODE_0(b1->scale)) {
b1->SetZero();
#if defined(__APPLE__) || (defined(_WIN32) && !defined(__CYGWIN__))
b0->scale /= abs(b0->scale);
#else
b0->scale /= (complex_x)sqrt(norm(b0->scale).to_double());
#endif
}

const complex_x phaseFac = (complex_x)std::polar(ONE_R1,
Expand Down Expand Up @@ -311,7 +319,11 @@ void QBdtNode::Normalize(bitLenInt depth)
std::lock_guard<std::mutex> lock(b0->mtx);
#endif

#if defined(__APPLE__) || (defined(_WIN32) && !defined(__CYGWIN__))
const real1_x nrm = (real1_x)sqrt(2 * norm(b0->scale));
#else
const real1_x nrm = (real1_x)sqrt(2 * (norm(b0->scale).to_double()));
#endif

b0->Normalize(depth);
b0->scale *= ONE_R1_X / nrm;
Expand All @@ -322,7 +334,11 @@ void QBdtNode::Normalize(bitLenInt depth)
std::lock_guard<std::mutex> lock1(b1->mtx, std::adopt_lock);
#endif

#if defined(__APPLE__) || (defined(_WIN32) && !defined(__CYGWIN__))
const real1_x nrm = (real1_x)sqrt(norm(b0->scale) + norm(b1->scale));
#else
const real1_x nrm = (real1_x)sqrt((norm(b0->scale) + norm(b1->scale)).to_double());
#endif

b0->Normalize(depth);
b1->Normalize(depth);
Expand Down Expand Up @@ -358,7 +374,11 @@ void QBdtNode::PopStateVector(bitLenInt depth, bitLenInt parDepth)
#endif
b0->PopStateVector(depth);

const real1_x nrm = (real1_x)(2 * (norm(b0->scale).to_double()));
#if defined(__APPLE__) || (defined(_WIN32) && !defined(__CYGWIN__))
const real1_x nrm = (real1_x)sqrt(2 * norm(b0->scale));
#else
const real1_x nrm = (real1_x)sqrt(2 * (norm(b0->scale).to_double()));
#endif

if (nrm <= _qrack_qbdt_sep_thresh) {
scale = ZERO_CMPLX;
Expand All @@ -368,7 +388,11 @@ void QBdtNode::PopStateVector(bitLenInt depth, bitLenInt parDepth)
return;
}

#if defined(__APPLE__) || (defined(_WIN32) && !defined(__CYGWIN__))
scale = std::polar(sqrt(nrm), std::arg(b0->scale));
#else
scale = (complex_x)std::polar((real1)sqrt(nrm.to_double()), std::arg(complexFixedToFloating(b0->scale)));
#endif
b0->scale /= scale;

return;
Expand Down Expand Up @@ -410,7 +434,11 @@ void QBdtNode::PopStateVector(bitLenInt depth, bitLenInt parDepth)
return;
}

#if defined(__APPLE__) || (defined(_WIN32) && !defined(__CYGWIN__))
scale = std::polar(sqrt(nrm0 + nrm1), std::arg(b0->scale));
#else
scale = (complex_x)std::polar((real1)sqrt((nrm0 + nrm1).to_double()), std::arg(complexFixedToFloating(b0->scale)));
#endif
b0->scale /= scale;
b1->scale /= scale;
}
Expand Down
4 changes: 4 additions & 0 deletions src/qbdt/node_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,11 @@ QBdtNodeInterfacePtr QBdtNodeInterface::RemoveSeparableAtDepth(
}

QBdtNodeInterfacePtr toRet = ShallowClone();
#if defined(__APPLE__) || (defined(_WIN32) && !defined(__CYGWIN__))
toRet->scale /= abs(toRet->scale);
#else
toRet->scale /= (complex_x)sqrt((real1)(norm(toRet->scale).to_double()));
#endif

if (!size) {
branches[0U] = NULL;
Expand Down
12 changes: 12 additions & 0 deletions src/qbdt/tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -541,13 +541,21 @@ bool QBdt::ForceM(bitLenInt qubit, bool result, bool doForce, bool doApply)
return;
}
b0->SetZero();
#if defined(__APPLE__) || (defined(_WIN32) && !defined(__CYGWIN__))
b1->scale /= abs(b1->scale);
#else
b1->scale /= (complex_x)sqrt(norm(b1->scale).to_double());
#endif
} else {
if (IS_NODE_0(b0->scale)) {
b0->SetZero();
return;
}
#if defined(__APPLE__) || (defined(_WIN32) && !defined(__CYGWIN__))
b0->scale /= abs(b0->scale);
#else
b0->scale /= (complex_x)sqrt(norm(b0->scale).to_double());
#endif
b1->SetZero();
}
});
Expand All @@ -571,7 +579,11 @@ bitCapInt QBdt::MAllOptionalCollapse(bool isCollapsing)
}

for (bitLenInt i = 0U; i < qubitCount; ++i) {
#if defined(__APPLE__) || (defined(_WIN32) && !defined(__CYGWIN__))
real1_f oneChance = clampProb((real1_f)norm(leaf->branches[1U]->scale));
#else
real1_f oneChance = clampProb((real1_f)(norm(leaf->branches[1U]->scale).to_double()));
#endif
bool bitResult;
if (oneChance >= ONE_R1) {
bitResult = true;
Expand Down

0 comments on commit 7ef95f0

Please sign in to comment.