diff --git a/include/qneuron.hpp b/include/qneuron.hpp index 03831e273..64df5efb6 100644 --- a/include/qneuron.hpp +++ b/include/qneuron.hpp @@ -48,13 +48,13 @@ class QNeuron { std::unique_ptr angles; QInterfacePtr qReg; - static real1_f applyRelu(real1_f angle) { return std::max(ZERO_R1_F, angle); } + static real1_f applyRelu(real1_f angle) { return std::max((real1_f)ZERO_R1_F, (real1_f)angle); } - static real1_f negApplyRelu(real1_f angle) { return -std::max(ZERO_R1_F, angle); } + static real1_f negApplyRelu(real1_f angle) { return -std::max((real1_f)ZERO_R1_F, (real1_f)angle); } - static real1_f applyGelu(real1_f angle) { return angle * (1 + erf(angle * SQRT1_2_R1)); } + static real1_f applyGelu(real1_f angle) { return angle * (1 + erf((real1_s)(angle * SQRT1_2_R1))); } - static real1_f negApplyGelu(real1_f angle) { return -angle * (1 + erf(angle * SQRT1_2_R1)); } + static real1_f negApplyGelu(real1_f angle) { return -angle * (1 + erf((real1_s)(angle * SQRT1_2_R1))); } static real1_f applyAlpha(real1_f angle, real1_f alpha) { diff --git a/include/qunit.hpp b/include/qunit.hpp index 895d6c80d..575695e20 100644 --- a/include/qunit.hpp +++ b/include/qunit.hpp @@ -484,10 +484,10 @@ class QUnit : public QParity, public QInterface { } if (IS_NORM_0(shard.amp1)) { - logFidelity += log(clampProb(ONE_R1_F - norm(shard.amp1))); + logFidelity += (double)log(clampProb(ONE_R1_F - norm(shard.amp1))); SeparateBit(false, qubit); } else if (IS_NORM_0(shard.amp0)) { - logFidelity += log(clampProb(ONE_R1_F - norm(shard.amp0))); + logFidelity += (double)log(clampProb(ONE_R1_F - norm(shard.amp0))); SeparateBit(true, qubit); } } diff --git a/src/pinvoke_api.cpp b/src/pinvoke_api.cpp index 96e8deab5..3d6916d96 100644 --- a/src/pinvoke_api.cpp +++ b/src/pinvoke_api.cpp @@ -2897,7 +2897,11 @@ MICROSOFT_QUANTUM_DECL void destroy_qneuron(_In_ uintq nid) neuronReservations[nid] = false; } -MICROSOFT_QUANTUM_DECL void set_qneuron_angles(_In_ uintq nid, _In_ real1_f* angles) +#if FPPOW < 6 +MICROSOFT_QUANTUM_DECL void set_qneuron_angles(_In_ uintq nid, _In_ float* angles) +#else +MICROSOFT_QUANTUM_DECL void set_qneuron_angles(_In_ uintq nid, _In_ double* angles) +#endif { NEURON_LOCK_GUARD_VOID(nid) #if (FPPOW == 5) || (FPPOW == 6) @@ -2905,12 +2909,20 @@ MICROSOFT_QUANTUM_DECL void set_qneuron_angles(_In_ uintq nid, _In_ real1_f* ang #else const bitCapIntOcl inputPower = (bitCapIntOcl)neuron->GetInputPower(); std::unique_ptr _angles(new real1[inputPower]); +#if (FPPOW == 4) std::copy(angles, angles + inputPower, _angles.get()); +#else + std::transform(angles, angles + inputPower, _angles.get(), [](double d) { return (real1)d; }); +#endif neuron->SetAngles(_angles.get()); #endif } -MICROSOFT_QUANTUM_DECL void get_qneuron_angles(_In_ uintq nid, _In_ real1_f* angles) +#if FPPOW < 6 +MICROSOFT_QUANTUM_DECL void get_qneuron_angles(_In_ uintq nid, _In_ float* angles) +#else +MICROSOFT_QUANTUM_DECL void get_qneuron_angles(_In_ uintq nid, _In_ double* angles) +#endif { NEURON_LOCK_GUARD_VOID(nid) #if (FPPOW == 5) || (FPPOW == 6) @@ -2919,7 +2931,11 @@ MICROSOFT_QUANTUM_DECL void get_qneuron_angles(_In_ uintq nid, _In_ real1_f* ang const bitCapIntOcl inputPower = (bitCapIntOcl)neuron->GetInputPower(); std::unique_ptr _angles(new real1[inputPower]); neuron->GetAngles(_angles.get()); +#if (FPPOW == 4) std::copy(_angles.get(), _angles.get() + inputPower, angles); +#else + std::transform(_angles.get(), _angles.get() + inputPower, angles, [](real1 d) { return (double)d; }); +#endif #endif } diff --git a/src/qunit.cpp b/src/qunit.cpp index e97c4ff04..097b86db1 100644 --- a/src/qunit.cpp +++ b/src/qunit.cpp @@ -129,22 +129,22 @@ void QUnit::SetQuantumState(const complex* inputState) shard.amp1 = inputState[1U]; shard.pauliBasis = PauliZ; if (IS_AMP_0(shard.amp0 - shard.amp1)) { - logFidelity += log(clampProb(ONE_R1_F - norm(shard.amp0 - shard.amp1))); + logFidelity += (double)log(clampProb(ONE_R1_F - norm(shard.amp0 - shard.amp1))); shard.pauliBasis = PauliX; shard.amp0 = shard.amp0 / abs(shard.amp0); shard.amp1 = ZERO_R1; } else if (IS_AMP_0(shard.amp0 + shard.amp1)) { - logFidelity += log(clampProb(ONE_R1_F - norm(shard.amp0 + shard.amp1))); + logFidelity += (double)log(clampProb(ONE_R1_F - norm(shard.amp0 + shard.amp1))); shard.pauliBasis = PauliX; shard.amp1 = shard.amp0 / abs(shard.amp0); shard.amp0 = ZERO_R1; } else if (IS_AMP_0((I_CMPLX * inputState[0U]) - inputState[1U])) { - logFidelity += log(clampProb(ONE_R1_F - norm((I_CMPLX * inputState[0U]) - inputState[1U]))); + logFidelity += (double)log(clampProb(ONE_R1_F - norm((I_CMPLX * inputState[0U]) - inputState[1U]))); shard.pauliBasis = PauliY; shard.amp0 = shard.amp0 / abs(shard.amp0); shard.amp1 = ZERO_R1; } else if (IS_AMP_0((I_CMPLX * inputState[0U]) + inputState[1U])) { - logFidelity += log(clampProb(ONE_R1_F - norm((I_CMPLX * inputState[0U]) - inputState[1U]))); + logFidelity += (double)log(clampProb(ONE_R1_F - norm((I_CMPLX * inputState[0U]) - inputState[1U]))); shard.pauliBasis = PauliY; shard.amp1 = shard.amp0 / abs(shard.amp0); shard.amp0 = ZERO_R1; @@ -766,7 +766,7 @@ bool QUnit::TrySeparate(bitLenInt qubit) SeparateBit(false, qubit); ShardAI(qubit, azimuth, inclination); - logFidelity += log(clampProb(1.0 - oneMinR / 2)); + logFidelity += (double)log(clampProb(1.0 - oneMinR / 2)); return true; } @@ -976,22 +976,22 @@ real1_f QUnit::ProbBase(bitLenInt qubit) shard.unit->GetQuantumState(amps); if (IS_AMP_0(amps[0U] - amps[1U])) { - logFidelity += log(clampProb(ONE_R1_F - norm(amps[0U] - amps[1U]))); + logFidelity += (double)log(clampProb(ONE_R1_F - norm(amps[0U] - amps[1U]))); shard.pauliBasis = PauliX; amps[0U] = amps[0U] / abs(amps[0U]); amps[1U] = ZERO_CMPLX; } else if (IS_AMP_0(amps[0U] + amps[1U])) { - logFidelity += log(clampProb(ONE_R1_F - norm(amps[0U] + amps[1U]))); + logFidelity += (double)log(clampProb(ONE_R1_F - norm(amps[0U] + amps[1U]))); shard.pauliBasis = PauliX; amps[1U] = amps[0U] / abs(amps[0U]); amps[0U] = ZERO_CMPLX; } else if (IS_AMP_0((I_CMPLX * amps[0U]) - amps[1U])) { - logFidelity += log(clampProb(ONE_R1_F - norm((I_CMPLX * amps[0U]) - amps[1U]))); + logFidelity += (double)log(clampProb(ONE_R1_F - norm((I_CMPLX * amps[0U]) - amps[1U]))); shard.pauliBasis = PauliY; amps[0U] = amps[0U] / abs(amps[0U]); amps[1U] = ZERO_CMPLX; } else if (IS_AMP_0((I_CMPLX * amps[0U]) + amps[1U])) { - logFidelity += log(clampProb(ONE_R1_F - norm((I_CMPLX * amps[0U]) + amps[1U]))); + logFidelity += (double)log(clampProb(ONE_R1_F - norm((I_CMPLX * amps[0U]) + amps[1U]))); shard.pauliBasis = PauliY; amps[1U] = amps[0U] / abs(amps[0U]); amps[0U] = ZERO_CMPLX; @@ -1019,10 +1019,10 @@ real1_f QUnit::ProbBase(bitLenInt qubit) } if (IS_NORM_0(shard.amp1)) { - logFidelity += log(clampProb(ONE_R1_F - norm(shard.amp1))); + logFidelity += (double)log(clampProb(ONE_R1_F - norm(shard.amp1))); SeparateBit(false, qubit); } else if (IS_NORM_0(shard.amp0)) { - logFidelity += log(clampProb(ONE_R1_F - norm(shard.amp0))); + logFidelity += (double)log(clampProb(ONE_R1_F - norm(shard.amp0))); SeparateBit(true, qubit); } diff --git a/test/benchmarks.cpp b/test/benchmarks.cpp index 0f8e62a77..90e1b8700 100644 --- a/test/benchmarks.cpp +++ b/test/benchmarks.cpp @@ -4517,7 +4517,7 @@ real1_f diophantine_fidelity_correction(real1_f sigmoid, real1_f sdrp) // Reverse variance normalization: sigmoid = pow(sigmoid, 1 / (1 - sqrt(sdrp))); - if (std::isnan(sigmoid)) { + if (std::isnan((real1_s)sigmoid)) { return 0; } diff --git a/test/tests.cpp b/test/tests.cpp index de9544d98..2e64f97b7 100644 --- a/test/tests.cpp +++ b/test/tests.cpp @@ -3346,7 +3346,8 @@ TEST_CASE_METHOD(QInterfaceTestFixture, "test_getamplitude") qftReg->H(0); qftReg->T(0); REQUIRE(abs(norm(qftReg->GetAmplitude(0x00)) - 0.5f) < 0.01); - REQUIRE(norm(qftReg->GetAmplitude(0x00) + complex(SQRT1_2_R1, SQRT1_2_R1) * I_CMPLX * qftReg->GetAmplitude(0x01)) < 0.01); + REQUIRE(norm(qftReg->GetAmplitude(0x00) + complex(SQRT1_2_R1, SQRT1_2_R1) * I_CMPLX * qftReg->GetAmplitude(0x01)) < + 0.01); } TEST_CASE_METHOD(QInterfaceTestFixture, "test_getquantumstate")