The Quantum Exact Simulation Toolkit v4.0.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 1349 of file operations.cpp.

1349 {
1350 validate_quregFields(qureg, __func__);
1351 validate_controlAndTarget(qureg, ctrl, targ, __func__);
1352 validate_rotationAxisNotZeroVector(axisX, axisY, axisZ, __func__);
1353
1354 applyMultiStateControlledRotateAroundAxis(qureg, &ctrl, nullptr, 1, targ, angle, axisX, axisY, axisZ);
1355}
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 1223 of file operations.cpp.

1223 {
1224 validate_quregFields(qureg, __func__);
1225 validate_controlAndTarget(qureg, control, target, __func__);
1226
1227 // harmlessly re-validates
1228 applyMultiStateControlledRotateX(qureg, &control, nullptr, 1, target, angle);
1229}
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 1231 of file operations.cpp.

1231 {
1232 validate_quregFields(qureg, __func__);
1233 validate_controlAndTarget(qureg, control, target, __func__);
1234
1235 // harmlessly re-validates
1236 applyMultiStateControlledRotateY(qureg, &control, nullptr, 1, target, angle);
1237}
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 1239 of file operations.cpp.

1239 {
1240 validate_quregFields(qureg, __func__);
1241 validate_controlAndTarget(qureg, control, target, __func__);
1242
1243 // harmlessly re-validates
1244 applyMultiStateControlledRotateZ(qureg, &control, nullptr, 1, target, angle);
1245}
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 1357 of file operations.cpp.

1357 {
1358 validate_quregFields(qureg, __func__);
1359 validate_controlsAndTarget(qureg, ctrls, numCtrls, targ, __func__);
1360 validate_rotationAxisNotZeroVector(axisX, axisY, axisZ, __func__);
1361
1362 applyMultiStateControlledRotateAroundAxis(qureg, ctrls, nullptr, numCtrls, targ, angle, axisX, axisY, axisZ);
1363}

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 1247 of file operations.cpp.

1247 {
1248 validate_quregFields(qureg, __func__);
1249 validate_controlsAndTarget(qureg, controls, numControls, target, __func__);
1250
1251 // harmlessly re-validates
1252 applyMultiStateControlledRotateX(qureg, controls, nullptr, numControls, target, angle);
1253}

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 1255 of file operations.cpp.

1255 {
1256 validate_quregFields(qureg, __func__);
1257 validate_controlsAndTarget(qureg, controls, numControls, target, __func__);
1258
1259 // harmlessly re-validates
1260 applyMultiStateControlledRotateY(qureg, controls, nullptr, numControls, target, angle);
1261}

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 1263 of file operations.cpp.

1263 {
1264 validate_quregFields(qureg, __func__);
1265 validate_controlsAndTarget(qureg, controls, numControls, target, __func__);
1266
1267 // harmlessly re-validates
1268 applyMultiStateControlledRotateZ(qureg, controls, nullptr, numControls, target, angle);
1269}

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 1365 of file operations.cpp.

1365 {
1366 validate_quregFields(qureg, __func__);
1367 validate_controlsAndTarget(qureg, ctrls, numCtrls, targ, __func__);
1368 validate_controlStates(states, numCtrls, __func__); // permits states==nullptr
1369 validate_rotationAxisNotZeroVector(axisX, axisY, axisZ, __func__);
1370
1371 // defer division of vector norm to improve numerical accuracy
1372 qreal norm = std::sqrt(std::pow(axisX,2) + std::pow(axisY,2) + std::pow(axisZ,2)); // != 0
1373
1374 // treat as generic 1-qubit matrix
1375 qreal c = std::cos(angle/2);
1376 qreal s = std::sin(angle/2);
1377 qcomp u11 = c - (s * axisZ * 1_i) / norm;
1378 qcomp u12 = - (s * (axisY + axisX * 1_i)) / norm;
1379 qcomp u21 = (s * (axisY - axisX * 1_i)) / norm;
1380 qcomp u22 = c + (s * axisZ * 1_i) / norm;
1381 auto matr = getCompMatr1({{u11,u12},{u21,u22}});
1382
1383 // harmlessly re-validates, and checks unitarity of matr
1384 applyMultiStateControlledCompMatr1(qureg, ctrls, states, numCtrls, targ, matr);
1385}
static CompMatr1 getCompMatr1(qcomp **in)
Definition matrices.h:321
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 1271 of file operations.cpp.

1271 {
1272 validate_quregFields(qureg, __func__);
1273 validate_controlsAndTarget(qureg, controls, numControls, target, __func__);
1274 validate_controlStates(states, numControls, __func__); // permits states==nullptr
1275
1276 // harmlessly re-validates
1277 applyMultiStateControlledPauliGadget(qureg, controls, states, numControls, getPauliStr("X", {target}), angle);
1278}
void applyMultiStateControlledPauliGadget(Qureg qureg, int *controls, int *states, int numControls, PauliStr str, qreal angle)
PauliStr getPauliStr(const char *paulis, int *indices, int numPaulis)
Definition paulis.cpp:296

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 1280 of file operations.cpp.

1280 {
1281 validate_quregFields(qureg, __func__);
1282 validate_controlsAndTarget(qureg, controls, numControls, target, __func__);
1283 validate_controlStates(states, numControls, __func__); // permits states==nullptr
1284
1285 // harmlessly re-validates
1286 applyMultiStateControlledPauliGadget(qureg, controls, states, numControls, getPauliStr("Y", {target}), angle);
1287}

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 1289 of file operations.cpp.

1289 {
1290 validate_quregFields(qureg, __func__);
1291 validate_controlsAndTarget(qureg, controls, numControls, target, __func__);
1292 validate_controlStates(states, numControls, __func__); // permits states==nullptr
1293
1294 // harmlessly re-validates
1295 applyMultiStateControlledPauliGadget(qureg, controls, states, numControls, getPauliStr("Z", {target}), angle);
1296}

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 1341 of file operations.cpp.

1341 {
1342 validate_quregFields(qureg, __func__);
1343 validate_target(qureg, targ, __func__);
1344 validate_rotationAxisNotZeroVector(axisX, axisY, axisZ, __func__);
1345
1346 applyMultiStateControlledRotateAroundAxis(qureg, nullptr, nullptr, 0, targ, angle, axisX, axisY, axisZ);
1347}

◆ 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 1199 of file operations.cpp.

1199 {
1200 validate_quregFields(qureg, __func__);
1201 validate_target(qureg, target, __func__);
1202
1203 // harmlessly re-validates
1204 applyMultiStateControlledRotateX(qureg, nullptr, nullptr, 0, target, angle);
1205}

◆ 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 1207 of file operations.cpp.

1207 {
1208 validate_quregFields(qureg, __func__);
1209 validate_target(qureg, target, __func__);
1210
1211 // harmlessly re-validates
1212 applyMultiStateControlledRotateY(qureg, nullptr, nullptr, 0, target, angle);
1213}

◆ 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 1215 of file operations.cpp.

1215 {
1216 validate_quregFields(qureg, __func__);
1217 validate_target(qureg, target, __func__);
1218
1219 // harmlessly re-validates
1220 applyMultiStateControlledRotateZ(qureg, nullptr, nullptr, 0, target, angle);
1221}