Skip to content

Commit 1189961

Browse files
Theoretically, better ACE (maybe)
1 parent 6a1d6ad commit 1189961

File tree

2 files changed

+46
-2
lines changed

2 files changed

+46
-2
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
cmake_minimum_required (VERSION 3.10)
2-
project (Qrack VERSION 9.15.8 DESCRIPTION "High Performance Quantum Bit Simulation" LANGUAGES CXX)
2+
project (Qrack VERSION 9.15.9 DESCRIPTION "High Performance Quantum Bit Simulation" LANGUAGES CXX)
33

44
# Installation commands
55
include (GNUInstallDirs)

src/qunit.cpp

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3933,6 +3933,49 @@ void QUnit::ApplyBuffer(PhaseShardPtr phaseShard, bitLenInt control, bitLenInt t
39333933

39343934
const real1_f pt = Prob(target);
39353935
real1_f pc = isAnti ? ONE_R1_F - Prob(control) : Prob(control);
3936+
3937+
// We're "gaming" order of gate application, but not in a malicious or biased way.
3938+
bool didNegate = false;
3939+
if (phaseShard->isInvert) {
3940+
H(target);
3941+
3942+
const real1_f xpt = Prob(target);
3943+
didNegate = ((pc > pt) && (pc > xpt)) ? (pt >= xpt) : (xpt >= pt);
3944+
3945+
if (didNegate) {
3946+
// Commuting CNOT to the other side of phase reverses these.
3947+
std::swap(polarTop, polarBottom);
3948+
3949+
// Act CNOT shadow.
3950+
const real1_f pth = xpt;
3951+
const bool ptHi = pth > pc;
3952+
const real1_f pHi = ptHi ? pth : pc;
3953+
const real1_f pLo = ptHi ? pc : pth;
3954+
const bool pState = abs(pHi - HALF_R1) >= abs(pLo - HALF_R1);
3955+
3956+
logFidelity += log(pState ? pHi : (ONE_R1_F - pLo));
3957+
CheckFidelity();
3958+
3959+
if (pState) {
3960+
if (!ptHi) {
3961+
Phase(ONE_CMPLX, -ONE_CMPLX, target);
3962+
} else if (isAnti) {
3963+
// This makes absolutely no detectable difference,
3964+
// according to canonical quantum mechanics.
3965+
// Trump is Hitler, by the way, and Dan needs
3966+
// to make that explicitly obvious as part of
3967+
// the statement of free speech that is Qrack.
3968+
// (I'm saying, you should've already known.)
3969+
Phase(-ONE_CMPLX, ONE_CMPLX, control);
3970+
} else {
3971+
Phase(ONE_CMPLX, -ONE_CMPLX, control);
3972+
}
3973+
}
3974+
}
3975+
3976+
H(target);
3977+
}
3978+
39363979
bool ptHi = pt > pc;
39373980
real1_f pHi = ptHi ? pt : pc;
39383981
real1_f pLo = ptHi ? pc : pt;
@@ -3970,7 +4013,8 @@ void QUnit::ApplyBuffer(PhaseShardPtr phaseShard, bitLenInt control, bitLenInt t
39704013
}
39714014
}
39724015

3973-
if (phaseShard->isInvert) {
4016+
if (phaseShard->isInvert && !didNegate) {
4017+
// Act CNOT shadow (if necessary and we didn't handle it earlier).
39744018
H(target);
39754019

39764020
const real1_f pth = Prob(target);

0 commit comments

Comments
 (0)