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

Function getSwapAndUnswapMatrices

tests/utils/evolve.cpp:78–114  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

76
77
78auto getSwapAndUnswapMatrices(vector<int> ctrls, vector<int> targs, size_t numQubits) {
79 DEMAND( numQubits >= ctrls.size() + targs.size() );
80
81 // matrices which swap targs+ctrls to be contiguous from 0
82 qmatrix swaps = getIdentityMatrix(getPow2(numQubits));
83 qmatrix unswaps = getIdentityMatrix(getPow2(numQubits));
84
85 // swap targs to {0, ..., ntargs - 1}
86 for (size_t i=0; i<targs.size(); i++) {
87
88 if (i == (size_t) targs[i])
89 continue;
90
91 qmatrix m = getSwapMatrix(i, targs[i], numQubits);
92 swaps = m * swaps;
93 unswaps = unswaps * m;
94
95 std::replace(ctrls.begin(), ctrls.end(), (int) i, targs[i]);
96 std::replace(targs.begin(), targs.end(), (int) i, targs[i]);
97 }
98
99 // swap ctrls to {ntargs, ..., ntargs + nctrls - 1}
100 for (size_t i=0; i<ctrls.size(); i++) {
101
102 size_t j = i + targs.size();
103 if (j == (size_t) ctrls[i])
104 continue;
105
106 qmatrix m = getSwapMatrix(j, ctrls[i], numQubits);
107 swaps = m * swaps;
108 unswaps = unswaps * m;
109
110 std::replace(ctrls.begin(), ctrls.end(), (int) j, ctrls[i]);
111 }
112
113 return std::tuple{swaps, unswaps};
114}
115
116
117qmatrix getFullStateOperator(vector<int> ctrls, vector<int> ctrlStates, vector<int> targs, qmatrix matrix, size_t numQubits) {

Callers 1

getFullStateOperatorFunction · 0.85

Calls 3

getPow2Function · 0.85
getIdentityMatrixFunction · 0.70
getSwapMatrixFunction · 0.70

Tested by

no test coverage detected