MCPcopy Create free account
hub / github.com/QuEST-Kit/QuEST / partialTraceOnPrefix

Function partialTraceOnPrefix

quest/src/core/localiser.cpp:1798–1818  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1796
1797
1798void partialTraceOnPrefix(Qureg inQureg, Qureg outQureg, vector<int> ketTargs) {
1799
1800 // all ketTargs (pre-sorted) are in the suffix, but one or more braTargs are in the prefix
1801 auto braTargs = util_getBraQubits(ketTargs, inQureg); // sorted
1802 auto allTargs = util_getSorted(ketTargs, braTargs); // sorted
1803 auto sufTargs = getQubitsSwappedToMaxSuffix(inQureg, allTargs); // arbitrarily ordered
1804
1805 // swap iniQureg's prefix bra-qubits into suffix, invoking communication
1806 anyCtrlMultiSwapBetweenPrefixAndSuffix(inQureg, {}, {}, sufTargs, allTargs);
1807
1808 // use the second half of sufTargs as the pair targs, which are now all in the suffix,
1809 // to perform embarrassingly parallel overwriting of outQureg
1810 vector<int> pairTargs(sufTargs.begin() + ketTargs.size(), sufTargs.end()); // arbitrarily ordered
1811 accel_densmatr_partialTrace_sub(inQureg, outQureg, ketTargs, pairTargs);
1812
1813 // restore the relative order of outQureg's remaining qubits using SWAPs
1814 reorderReducedQureg(inQureg, outQureg, allTargs, sufTargs);
1815
1816 // undo the swaps on inQureg
1817 anyCtrlMultiSwapBetweenPrefixAndSuffix(inQureg, {}, {}, sufTargs, allTargs);
1818}
1819
1820
1821void localiser_densmatr_partialTrace(Qureg inQureg, Qureg outQureg, vector<int> targs) {

Callers 1

Calls 6

util_getBraQubitsFunction · 0.85
util_getSortedFunction · 0.85
reorderReducedQuregFunction · 0.85

Tested by

no test coverage detected