Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 42 additions & 13 deletions quest/src/api/operations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -859,27 +859,38 @@ void applyMultiStateControlledPauliX(Qureg qureg, int* controls, int* states, in
validate_controlsAndTarget(qureg, controls, numControls, target, __func__);
validate_controlStates(states, numControls, __func__); // permits states==nullptr

// harmlessly re-validates
applyMultiStateControlledPauliStr(qureg, controls, states, numControls, getPauliStr("X", {target}));
// note that for the single-target scenario, we do not call the backend of
// applyMultiStateControlledPauliStr() since it contains sub-optimal logic
// which sees the factor of every amplitude dynamically evaluated (based on
// index parity, etc); the dense-matrix element lookup is faster

/// @todo
/// a bespoke all-pauli-X function (like in QuEST v3) will be faster still
/// since it avoids all superfluous flops; check worthwhile for multi-qubit

// harmlessly re-validates, including hardcoded matrix unitarity
CompMatr1 matrix = util_getPauliX();
validateAndApplyAnyCtrlAnyTargUnitaryMatrix(qureg, controls, states, numControls, &target, 1, matrix, __func__);
}

void applyMultiStateControlledPauliY(Qureg qureg, int* controls, int* states, int numControls, int target) {
validate_quregFields(qureg, __func__);
validate_controlsAndTarget(qureg, controls, numControls, target, __func__);
validate_controlStates(states, numControls, __func__); // permits states==nullptr

// harmlessly re-validates
applyMultiStateControlledPauliStr(qureg, controls, states, numControls, getPauliStr("Y", {target}));
// harmlessly re-validates, including hardcoded matrix unitarity
CompMatr1 matrix = util_getPauliY();
validateAndApplyAnyCtrlAnyTargUnitaryMatrix(qureg, controls, states, numControls, &target, 1, matrix, __func__);
}

void applyMultiStateControlledPauliZ(Qureg qureg, int* controls, int* states, int numControls, int target) {
validate_quregFields(qureg, __func__);
validate_controlsAndTarget(qureg, controls, numControls, target, __func__);
validate_controlStates(states, numControls, __func__); // permits states==nullptr

// harmlessly re-validates
DiagMatr1 matr = getDiagMatr1({1, -1});
applyMultiStateControlledDiagMatr1(qureg, controls, states, numControls, target, matr);
// harmlessly re-validates, including hardcoded matrix unitarity
DiagMatr1 matrix = util_getPauliZ();
validateAndApplyAnyCtrlAnyTargUnitaryMatrix(qureg, controls, states, numControls, &target, 1, matrix, __func__);
}

} // end de-mangler
Expand Down Expand Up @@ -1077,26 +1088,44 @@ void applyMultiStateControlledRotateX(Qureg qureg, int* controls, int* states, i
validate_controlsAndTarget(qureg, controls, numControls, target, __func__);
validate_controlStates(states, numControls, __func__); // permits states==nullptr

// harmlessly re-validates
applyMultiStateControlledPauliGadget(qureg, controls, states, numControls, getPauliStr("X", {target}), angle);
// note that for the single-target scenario, we do not call the backend of
// applyMultiStateControlledPauliGadget() since it contains sub-optimal logic
// which sees the factor of every amplitude dynamically evaluated (based on
// index parity, etc); the dense-matrix element lookup is faster

// harmlessly re-validates, including hardcoded matrix unitarity
CompMatr1 matrix = util_getExpPauliX(angle);
validateAndApplyAnyCtrlAnyTargUnitaryMatrix(qureg, controls, states, numControls, &target, 1, matrix, __func__);
}

void applyMultiStateControlledRotateY(Qureg qureg, int* controls, int* states, int numControls, int target, qreal angle) {
validate_quregFields(qureg, __func__);
validate_controlsAndTarget(qureg, controls, numControls, target, __func__);
validate_controlStates(states, numControls, __func__); // permits states==nullptr

// harmlessly re-validates
applyMultiStateControlledPauliGadget(qureg, controls, states, numControls, getPauliStr("Y", {target}), angle);
// note that for the single-target scenario, we do not call the backend of
// applyMultiStateControlledPauliGadget() since it contains sub-optimal logic
// which sees the factor of every amplitude dynamically evaluated (based on
// index parity, etc); the dense-matrix element lookup is faster

// harmlessly re-validates, including hardcoded matrix unitarity
CompMatr1 matrix = util_getExpPauliY(angle);
validateAndApplyAnyCtrlAnyTargUnitaryMatrix(qureg, controls, states, numControls, &target, 1, matrix, __func__);
}

void applyMultiStateControlledRotateZ(Qureg qureg, int* controls, int* states, int numControls, int target, qreal angle) {
validate_quregFields(qureg, __func__);
validate_controlsAndTarget(qureg, controls, numControls, target, __func__);
validate_controlStates(states, numControls, __func__); // permits states==nullptr

// harmlessly re-validates
applyMultiStateControlledPauliGadget(qureg, controls, states, numControls, getPauliStr("Z", {target}), angle);
// note that for the single-target scenario, we do not call the backend of
// applyMultiStateControlledPauliGadget() since it contains sub-optimal logic
// which sees the factor of every amplitude dynamically evaluated (based on
// index parity, etc); the dense-matrix element lookup is faster

// harmlessly re-validates, including hardcoded matrix unitarity
DiagMatr1 matrix = util_getExpPauliZ(angle);
validateAndApplyAnyCtrlAnyTargUnitaryMatrix(qureg, controls, states, numControls, &target, 1, matrix, __func__);
}

} // end de-mangler
Expand Down
48 changes: 48 additions & 0 deletions quest/src/core/utilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1007,6 +1007,54 @@ qcomp util_getPhaseFromGateAngle(qcomp angle) {
return - angle / 2;
}

CompMatr1 util_getPauliX() {
return getCompMatr1({
{0,1},
{1,0}
});
}
CompMatr1 util_getPauliY() {
return getCompMatr1({
{0,qcomp(0,-1)},
{qcomp(0,1),0}
});
}
DiagMatr1 util_getPauliZ() {
return getDiagMatr1({1,-1});
}

CompMatr1 util_getExpPauliX(qreal angle) {

qreal x = util_getPhaseFromGateAngle(angle);
qreal c = std::cos(x);
qreal s = std::sin(x);

return getCompMatr1({
{qcomp(c,0), qcomp(0,s)},
{qcomp(0,s), qcomp(c,0)}
});
}

CompMatr1 util_getExpPauliY(qreal angle) {

qreal x = util_getPhaseFromGateAngle(angle);
qreal c = std::cos(x);
qreal s = std::sin(x);

return getCompMatr1({
{ c, s},
{-s, c}
});
}

DiagMatr1 util_getExpPauliZ(qreal angle) {

qreal x = util_getPhaseFromGateAngle(angle);
qcomp y = qcomp(0, x);

return getDiagMatr1({std::exp(y), std::exp(-y)});
}



/*
Expand Down
8 changes: 8 additions & 0 deletions quest/src/core/utilities.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,14 @@ std::pair<qindex, qindex> util_getBlockMultipleSubRange(qindex rangeLen, qindex
qreal util_getPhaseFromGateAngle(qreal angle);
qcomp util_getPhaseFromGateAngle(qcomp angle);

CompMatr1 util_getPauliX();
CompMatr1 util_getPauliY();
DiagMatr1 util_getPauliZ();

CompMatr1 util_getExpPauliX(qreal angle);
CompMatr1 util_getExpPauliY(qreal angle);
DiagMatr1 util_getExpPauliZ(qreal angle);



/*
Expand Down
Loading