The Quantum Exact Simulation Toolkit v4.2.0
Loading...
Searching...
No Matches

Functions for applying one-qubit rotations around Pauli and arbitrary axis. More...

Functions

void applyControlledRotateAroundAxis (Qureg qureg, int ctrl, int targ, qreal angle, qreal axisX, qreal axisY, qreal axisZ)
 
void applyControlledRotateX (Qureg qureg, int control, int target, qreal angle)
 
void applyControlledRotateY (Qureg qureg, int control, int target, qreal angle)
 
void applyControlledRotateZ (Qureg qureg, int control, int target, qreal angle)
 
void applyMultiControlledRotateAroundAxis (Qureg qureg, int *ctrls, int numCtrls, int targ, qreal angle, qreal axisX, qreal axisY, qreal axisZ)
 
void applyMultiControlledRotateX (Qureg qureg, int *controls, int numControls, int target, qreal angle)
 
void applyMultiControlledRotateY (Qureg qureg, int *controls, int numControls, int target, qreal angle)
 
void applyMultiControlledRotateZ (Qureg qureg, int *controls, int numControls, int target, qreal angle)
 
void applyMultiStateControlledRotateAroundAxis (Qureg qureg, int *ctrls, int *states, int numCtrls, int targ, qreal angle, qreal axisX, qreal axisY, qreal axisZ)
 
void applyMultiStateControlledRotateX (Qureg qureg, int *controls, int *states, int numControls, int target, qreal angle)
 
void applyMultiStateControlledRotateY (Qureg qureg, int *controls, int *states, int numControls, int target, qreal angle)
 
void applyMultiStateControlledRotateZ (Qureg qureg, int *controls, int *states, int numControls, int target, qreal angle)
 
void applyRotateAroundAxis (Qureg qureg, int target, qreal angle, qreal axisX, qreal axisY, qreal axisZ)
 
void applyRotateX (Qureg qureg, int target, qreal angle)
 
void applyRotateY (Qureg qureg, int target, qreal angle)
 
void applyRotateZ (Qureg qureg, int target, qreal angle)
 

Detailed Description

Functions for applying one-qubit rotations around Pauli and arbitrary axis.

Function Documentation

◆ applyControlledRotateAroundAxis()

void applyControlledRotateAroundAxis ( Qureg qureg,
int ctrl,
int targ,
qreal angle,
qreal axisX,
qreal axisY,
qreal axisZ )
Note
Documentation for this function or struct is under construction!

Definition at line 1182 of file operations.cpp.

1182 {
1183 validate_quregFields(qureg, __func__);
1184 validate_controlAndTarget(qureg, ctrl, targ, __func__);
1185 validate_rotationAxisNotZeroVector(axisX, axisY, axisZ, __func__);
1186
1187 applyMultiStateControlledRotateAroundAxis(qureg, &ctrl, nullptr, 1, targ, angle, axisX, axisY, axisZ);
1188}
void applyMultiStateControlledRotateAroundAxis(Qureg qureg, int *ctrls, int *states, int numCtrls, int targ, qreal angle, qreal axisX, qreal axisY, qreal axisZ)

◆ applyControlledRotateX()

void applyControlledRotateX ( Qureg qureg,
int control,
int target,
qreal angle )
Note
Documentation for this function or struct is under construction!

Definition at line 1038 of file operations.cpp.

1038 {
1039 validate_quregFields(qureg, __func__);
1040 validate_controlAndTarget(qureg, control, target, __func__);
1041
1042 // harmlessly re-validates
1043 applyMultiStateControlledRotateX(qureg, &control, nullptr, 1, target, angle);
1044}
void applyMultiStateControlledRotateX(Qureg qureg, int *controls, int *states, int numControls, int target, qreal angle)

◆ applyControlledRotateY()

void applyControlledRotateY ( Qureg qureg,
int control,
int target,
qreal angle )
Note
Documentation for this function or struct is under construction!

Definition at line 1046 of file operations.cpp.

1046 {
1047 validate_quregFields(qureg, __func__);
1048 validate_controlAndTarget(qureg, control, target, __func__);
1049
1050 // harmlessly re-validates
1051 applyMultiStateControlledRotateY(qureg, &control, nullptr, 1, target, angle);
1052}
void applyMultiStateControlledRotateY(Qureg qureg, int *controls, int *states, int numControls, int target, qreal angle)

◆ applyControlledRotateZ()

void applyControlledRotateZ ( Qureg qureg,
int control,
int target,
qreal angle )
Note
Documentation for this function or struct is under construction!

Definition at line 1054 of file operations.cpp.

1054 {
1055 validate_quregFields(qureg, __func__);
1056 validate_controlAndTarget(qureg, control, target, __func__);
1057
1058 // harmlessly re-validates
1059 applyMultiStateControlledRotateZ(qureg, &control, nullptr, 1, target, angle);
1060}
void applyMultiStateControlledRotateZ(Qureg qureg, int *controls, int *states, int numControls, int target, qreal angle)

◆ applyMultiControlledRotateAroundAxis()

void applyMultiControlledRotateAroundAxis ( Qureg qureg,
int * ctrls,
int numCtrls,
int targ,
qreal angle,
qreal axisX,
qreal axisY,
qreal axisZ )
Note
Documentation for this function or struct is under construction!

Definition at line 1190 of file operations.cpp.

1190 {
1191 validate_quregFields(qureg, __func__);
1192 validate_controlsAndTarget(qureg, ctrls, numCtrls, targ, __func__);
1193 validate_rotationAxisNotZeroVector(axisX, axisY, axisZ, __func__);
1194
1195 applyMultiStateControlledRotateAroundAxis(qureg, ctrls, nullptr, numCtrls, targ, angle, axisX, axisY, axisZ);
1196}

Referenced by applyMultiControlledRotateAroundAxis().

◆ applyMultiControlledRotateX()

void applyMultiControlledRotateX ( Qureg qureg,
int * controls,
int numControls,
int target,
qreal angle )
Note
Documentation for this function or struct is under construction!

Definition at line 1062 of file operations.cpp.

1062 {
1063 validate_quregFields(qureg, __func__);
1064 validate_controlsAndTarget(qureg, controls, numControls, target, __func__);
1065
1066 // harmlessly re-validates
1067 applyMultiStateControlledRotateX(qureg, controls, nullptr, numControls, target, angle);
1068}

Referenced by applyMultiControlledRotateX().

◆ applyMultiControlledRotateY()

void applyMultiControlledRotateY ( Qureg qureg,
int * controls,
int numControls,
int target,
qreal angle )
Note
Documentation for this function or struct is under construction!

Definition at line 1070 of file operations.cpp.

1070 {
1071 validate_quregFields(qureg, __func__);
1072 validate_controlsAndTarget(qureg, controls, numControls, target, __func__);
1073
1074 // harmlessly re-validates
1075 applyMultiStateControlledRotateY(qureg, controls, nullptr, numControls, target, angle);
1076}

Referenced by applyMultiControlledRotateY().

◆ applyMultiControlledRotateZ()

void applyMultiControlledRotateZ ( Qureg qureg,
int * controls,
int numControls,
int target,
qreal angle )
Note
Documentation for this function or struct is under construction!

Definition at line 1078 of file operations.cpp.

1078 {
1079 validate_quregFields(qureg, __func__);
1080 validate_controlsAndTarget(qureg, controls, numControls, target, __func__);
1081
1082 // harmlessly re-validates
1083 applyMultiStateControlledRotateZ(qureg, controls, nullptr, numControls, target, angle);
1084}

Referenced by applyMultiControlledRotateZ().

◆ applyMultiStateControlledRotateAroundAxis()

void applyMultiStateControlledRotateAroundAxis ( Qureg qureg,
int * ctrls,
int * states,
int numCtrls,
int targ,
qreal angle,
qreal axisX,
qreal axisY,
qreal axisZ )
Note
Documentation for this function or struct is under construction!
See also

Definition at line 1198 of file operations.cpp.

1198 {
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}
static CompMatr1 getCompMatr1(qcomp **in)
Definition matrices.h:325
void applyMultiStateControlledCompMatr1(Qureg qureg, int *controls, int *states, int numControls, int target, CompMatr1 matrix)

Referenced by applyControlledRotateAroundAxis(), applyMultiControlledRotateAroundAxis(), applyMultiStateControlledRotateAroundAxis(), and applyRotateAroundAxis().

◆ applyMultiStateControlledRotateX()

void applyMultiStateControlledRotateX ( Qureg qureg,
int * controls,
int * states,
int numControls,
int target,
qreal angle )
Note
Documentation for this function or struct is under construction!
See also

Definition at line 1086 of file operations.cpp.

1086 {
1087 validate_quregFields(qureg, __func__);
1088 validate_controlsAndTarget(qureg, controls, numControls, target, __func__);
1089 validate_controlStates(states, numControls, __func__); // permits states==nullptr
1090
1091 // note that for the single-target scenario, we do not call the backend of
1092 // applyMultiStateControlledPauliGadget() since it contains sub-optimal logic
1093 // which sees the factor of every amplitude dynamically evaluated (based on
1094 // index parity, etc); the dense-matrix element lookup is faster
1095
1096 // harmlessly re-validates, including hardcoded matrix unitarity
1097 CompMatr1 matrix = util_getExpPauliX(angle);
1098 validateAndApplyAnyCtrlAnyTargUnitaryMatrix(qureg, controls, states, numControls, &target, 1, matrix, __func__);
1099}

Referenced by applyControlledRotateX(), applyMultiControlledRotateX(), applyMultiStateControlledRotateX(), and applyRotateX().

◆ applyMultiStateControlledRotateY()

void applyMultiStateControlledRotateY ( Qureg qureg,
int * controls,
int * states,
int numControls,
int target,
qreal angle )
Note
Documentation for this function or struct is under construction!
See also

Definition at line 1101 of file operations.cpp.

1101 {
1102 validate_quregFields(qureg, __func__);
1103 validate_controlsAndTarget(qureg, controls, numControls, target, __func__);
1104 validate_controlStates(states, numControls, __func__); // permits states==nullptr
1105
1106 // note that for the single-target scenario, we do not call the backend of
1107 // applyMultiStateControlledPauliGadget() since it contains sub-optimal logic
1108 // which sees the factor of every amplitude dynamically evaluated (based on
1109 // index parity, etc); the dense-matrix element lookup is faster
1110
1111 // harmlessly re-validates, including hardcoded matrix unitarity
1112 CompMatr1 matrix = util_getExpPauliY(angle);
1113 validateAndApplyAnyCtrlAnyTargUnitaryMatrix(qureg, controls, states, numControls, &target, 1, matrix, __func__);
1114}

Referenced by applyControlledRotateY(), applyMultiControlledRotateY(), applyMultiStateControlledRotateY(), and applyRotateY().

◆ applyMultiStateControlledRotateZ()

void applyMultiStateControlledRotateZ ( Qureg qureg,
int * controls,
int * states,
int numControls,
int target,
qreal angle )
Note
Documentation for this function or struct is under construction!
See also

Definition at line 1116 of file operations.cpp.

1116 {
1117 validate_quregFields(qureg, __func__);
1118 validate_controlsAndTarget(qureg, controls, numControls, target, __func__);
1119 validate_controlStates(states, numControls, __func__); // permits states==nullptr
1120
1121 // note that for the single-target scenario, we do not call the backend of
1122 // applyMultiStateControlledPauliGadget() since it contains sub-optimal logic
1123 // which sees the factor of every amplitude dynamically evaluated (based on
1124 // index parity, etc); the dense-matrix element lookup is faster
1125
1126 // harmlessly re-validates, including hardcoded matrix unitarity
1127 DiagMatr1 matrix = util_getExpPauliZ(angle);
1128 validateAndApplyAnyCtrlAnyTargUnitaryMatrix(qureg, controls, states, numControls, &target, 1, matrix, __func__);
1129}

Referenced by applyControlledRotateZ(), applyMultiControlledRotateZ(), applyMultiStateControlledRotateZ(), and applyRotateZ().

◆ applyRotateAroundAxis()

void applyRotateAroundAxis ( Qureg qureg,
int target,
qreal angle,
qreal axisX,
qreal axisY,
qreal axisZ )
Note
Documentation for this function or struct is under construction!
Formulae

Let \( \theta = \) angle and \( \vec{n} = ( \) axisX, axisY, axisZ \( ) \), with corresponding unit vector \( \bar{n} \). Further, let \( \vec{\sigma} = (\hat{\sigma}_x, \hat{\sigma}_y, \hat{\sigma}_z) \) denote a vector of the Pauli matrices.

This function effects unitary

\[ \hat{R}_{\bar{n}}(\theta) = \exp \left( - \iu \frac{\theta}{2} \bar{n} \cdot \vec{\sigma} \right) \]

upon the target qubit. Explicitly,

\[ \hat{R}_{\bar{n}}(\theta) \equiv \begin{pmatrix} \cos\left( \frac{\theta}{2} \right) - \iu \, \bar{n}_z \sin\left( \frac{\theta}{2} \right) & - \, (\bar{n}_y + \bar{n}_x \, \iu ) \sin\left( \frac{\theta}{2} \right) \\ (\bar{n}_y - \bar{n}_x \, \iu ) \sin\left( \frac{\theta}{2} \right) & \cos\left( \frac{\theta}{2} \right) + \iu \, \bar{n}_z \sin\left( \frac{\theta}{2} \right) \end{pmatrix} \]

where

\[ \bar{n}_i = \frac{\vec{n}_i}{\| \vec{n} \|_2} = \frac{\vec{n}_i}{ \sqrt{ {\vec{n}_x}^2 + {\vec{n}_y}^2 + {\vec{n}_z}^2 } }. \]

Equivalences
  • Assuming \( \| \vec{n} \|_2 \ne 0 \), this function is agnostic to the normalisation of the axis vector.
    applyRotateAroundAxis(qureg, target, angle, x, y, z);
    applyRotateAroundAxis(qureg, target, angle, 5*x,5*y,5*z); // equivalent
    void applyRotateAroundAxis(Qureg qureg, int target, qreal angle, qreal axisX, qreal axisY, qreal axisZ)
  • This function is entirely equivalent to preparing \( \hat{R}_{\bar{n}}(\theta) \) as a CompMatr1 and effecting it upon the state via applyCompMatr1().
  • This function is both more accurate and efficient than equivalently instantiating a three-term PauliStrSum \( \hat{H} = \bar{n} \cdot \vec{\sigma}\) and effecting \( \exp \left(\iu \alpha \hat{H} \right) \) via applyTrotterizedPauliStrSumGadget() with \( \alpha = - \theta/2 \) and very many repetitions.
  • Passing angle=0 is equivalent to effecting the identity, leaving the state unchanged.

Definition at line 1174 of file operations.cpp.

1174 {
1175 validate_quregFields(qureg, __func__);
1176 validate_target(qureg, targ, __func__);
1177 validate_rotationAxisNotZeroVector(axisX, axisY, axisZ, __func__);
1178
1179 applyMultiStateControlledRotateAroundAxis(qureg, nullptr, nullptr, 0, targ, angle, axisX, axisY, axisZ);
1180}

◆ applyRotateX()

void applyRotateX ( Qureg qureg,
int target,
qreal angle )
Note
Documentation for this function or struct is under construction!
Formulae

Let \( \theta = \) angle. This function effects unitary

\[ \hat{R}_{x}(\theta) = \exp \left( - \iu \frac{\theta}{2} \hat{\sigma}_x \right) \]

upon the target qubit, where \( \hat{\sigma}_x \) is the Pauli X matrix.

Equivalences

Definition at line 1014 of file operations.cpp.

1014 {
1015 validate_quregFields(qureg, __func__);
1016 validate_target(qureg, target, __func__);
1017
1018 // harmlessly re-validates
1019 applyMultiStateControlledRotateX(qureg, nullptr, nullptr, 0, target, angle);
1020}

◆ applyRotateY()

void applyRotateY ( Qureg qureg,
int target,
qreal angle )
Note
Documentation for this function or struct is under construction!
Formulae

Let \( \theta = \) angle. This function effects unitary

\[ \hat{R}_{y}(\theta) = \exp \left( - \iu \frac{\theta}{2} \hat{\sigma}_y \right) \]

upon the target qubit, where \( \hat{\sigma}_y \) is the Pauli Y matrix.

Equivalences

Definition at line 1022 of file operations.cpp.

1022 {
1023 validate_quregFields(qureg, __func__);
1024 validate_target(qureg, target, __func__);
1025
1026 // harmlessly re-validates
1027 applyMultiStateControlledRotateY(qureg, nullptr, nullptr, 0, target, angle);
1028}

◆ applyRotateZ()

void applyRotateZ ( Qureg qureg,
int target,
qreal angle )
Note
Documentation for this function or struct is under construction!
Formulae

Let \( \theta = \) angle. This function effects unitary

\[ \hat{R}_{z}(\theta) = \exp \left( - \iu \frac{\theta}{2} \hat{\sigma}_z \right) \]

upon the target qubit, where \( \hat{\sigma}_z \) is the Pauli Z matrix.

Equivalences

Definition at line 1030 of file operations.cpp.

1030 {
1031 validate_quregFields(qureg, __func__);
1032 validate_target(qureg, target, __func__);
1033
1034 // harmlessly re-validates
1035 applyMultiStateControlledRotateZ(qureg, nullptr, nullptr, 0, target, angle);
1036}