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

Function applyMultiStateControlledRotateAroundAxis

quest/src/api/operations.cpp:1198–1218  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1196}
1197
1198void applyMultiStateControlledRotateAroundAxis(Qureg qureg, int* ctrls, int* states, int numCtrls, int targ, qreal angle, qreal axisX, qreal axisY, qreal axisZ) {
1199 validate_quregFields(qureg, __func__);
1200 validate_controlsAndTarget(qureg, ctrls, numCtrls, targ, __func__);
1201 validate_controlStates(states, numCtrls, __func__); // permits states==nullptr
1202 validate_rotationAxisNotZeroVector(axisX, axisY, axisZ, __func__);
1203
1204 // defer division of vector norm to improve numerical accuracy
1205 qreal norm = std::sqrt(std::pow(axisX,2) + std::pow(axisY,2) + std::pow(axisZ,2)); // != 0
1206
1207 // treat as generic 1-qubit matrix
1208 qreal c = std::cos(angle/2);
1209 qreal s = std::sin(angle/2);
1210 qcomp u11 = c - (s * axisZ * 1_i) / norm;
1211 qcomp u12 = - (s * (axisY + axisX * 1_i)) / norm;
1212 qcomp u21 = (s * (axisY - axisX * 1_i)) / norm;
1213 qcomp u22 = c + (s * axisZ * 1_i) / norm;
1214 auto matr = getCompMatr1({{u11,u12},{u21,u22}});
1215
1216 // harmlessly re-validates, and checks unitarity of matr
1217 applyMultiStateControlledCompMatr1(qureg, ctrls, states, numCtrls, targ, matr);
1218}
1219
1220} // end de-mangler
1221

Calls 7

validate_quregFieldsFunction · 0.85
validate_controlStatesFunction · 0.85
getCompMatr1Function · 0.70

Tested by

no test coverage detected