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

1361 {
1362 validate_quregFields(qureg, __func__);
1363 validate_controlAndTarget(qureg, ctrl, targ, __func__);
1364 validate_rotationAxisNotZeroVector(axisX, axisY, axisZ, __func__);
1365
1366 applyMultiStateControlledRotateAroundAxis(qureg, &ctrl, nullptr, 1, targ, angle, axisX, axisY, axisZ);
1367}
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 1235 of file operations.cpp.

1235 {
1236 validate_quregFields(qureg, __func__);
1237 validate_controlAndTarget(qureg, control, target, __func__);
1238
1239 // harmlessly re-validates
1240 applyMultiStateControlledRotateX(qureg, &control, nullptr, 1, target, angle);
1241}
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 1243 of file operations.cpp.

1243 {
1244 validate_quregFields(qureg, __func__);
1245 validate_controlAndTarget(qureg, control, target, __func__);
1246
1247 // harmlessly re-validates
1248 applyMultiStateControlledRotateY(qureg, &control, nullptr, 1, target, angle);
1249}
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 1251 of file operations.cpp.

1251 {
1252 validate_quregFields(qureg, __func__);
1253 validate_controlAndTarget(qureg, control, target, __func__);
1254
1255 // harmlessly re-validates
1256 applyMultiStateControlledRotateZ(qureg, &control, nullptr, 1, target, angle);
1257}
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 1369 of file operations.cpp.

1369 {
1370 validate_quregFields(qureg, __func__);
1371 validate_controlsAndTarget(qureg, ctrls, numCtrls, targ, __func__);
1372 validate_rotationAxisNotZeroVector(axisX, axisY, axisZ, __func__);
1373
1374 applyMultiStateControlledRotateAroundAxis(qureg, ctrls, nullptr, numCtrls, targ, angle, axisX, axisY, axisZ);
1375}

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

1259 {
1260 validate_quregFields(qureg, __func__);
1261 validate_controlsAndTarget(qureg, controls, numControls, target, __func__);
1262
1263 // harmlessly re-validates
1264 applyMultiStateControlledRotateX(qureg, controls, nullptr, numControls, target, angle);
1265}

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

1267 {
1268 validate_quregFields(qureg, __func__);
1269 validate_controlsAndTarget(qureg, controls, numControls, target, __func__);
1270
1271 // harmlessly re-validates
1272 applyMultiStateControlledRotateY(qureg, controls, nullptr, numControls, target, angle);
1273}

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

1275 {
1276 validate_quregFields(qureg, __func__);
1277 validate_controlsAndTarget(qureg, controls, numControls, target, __func__);
1278
1279 // harmlessly re-validates
1280 applyMultiStateControlledRotateZ(qureg, controls, nullptr, numControls, target, angle);
1281}

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

1377 {
1378 validate_quregFields(qureg, __func__);
1379 validate_controlsAndTarget(qureg, ctrls, numCtrls, targ, __func__);
1380 validate_controlStates(states, numCtrls, __func__); // permits states==nullptr
1381 validate_rotationAxisNotZeroVector(axisX, axisY, axisZ, __func__);
1382
1383 // defer division of vector norm to improve numerical accuracy
1384 qreal norm = std::sqrt(std::pow(axisX,2) + std::pow(axisY,2) + std::pow(axisZ,2)); // != 0
1385
1386 // treat as generic 1-qubit matrix
1387 qreal c = std::cos(angle/2);
1388 qreal s = std::sin(angle/2);
1389 qcomp u11 = c - (s * axisZ * 1_i) / norm;
1390 qcomp u12 = - (s * (axisY + axisX * 1_i)) / norm;
1391 qcomp u21 = (s * (axisY - axisX * 1_i)) / norm;
1392 qcomp u22 = c + (s * axisZ * 1_i) / norm;
1393 auto matr = getCompMatr1({{u11,u12},{u21,u22}});
1394
1395 // harmlessly re-validates, and checks unitarity of matr
1396 applyMultiStateControlledCompMatr1(qureg, ctrls, states, numCtrls, targ, matr);
1397}
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 1283 of file operations.cpp.

1283 {
1284 validate_quregFields(qureg, __func__);
1285 validate_controlsAndTarget(qureg, controls, numControls, target, __func__);
1286 validate_controlStates(states, numControls, __func__); // permits states==nullptr
1287
1288 // harmlessly re-validates
1289 applyMultiStateControlledPauliGadget(qureg, controls, states, numControls, getPauliStr("X", {target}), angle);
1290}
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:306

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

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

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

1301 {
1302 validate_quregFields(qureg, __func__);
1303 validate_controlsAndTarget(qureg, controls, numControls, target, __func__);
1304 validate_controlStates(states, numControls, __func__); // permits states==nullptr
1305
1306 // harmlessly re-validates
1307 applyMultiStateControlledPauliGadget(qureg, controls, states, numControls, getPauliStr("Z", {target}), angle);
1308}

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

1353 {
1354 validate_quregFields(qureg, __func__);
1355 validate_target(qureg, targ, __func__);
1356 validate_rotationAxisNotZeroVector(axisX, axisY, axisZ, __func__);
1357
1358 applyMultiStateControlledRotateAroundAxis(qureg, nullptr, nullptr, 0, targ, angle, axisX, axisY, axisZ);
1359}

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

1211 {
1212 validate_quregFields(qureg, __func__);
1213 validate_target(qureg, target, __func__);
1214
1215 // harmlessly re-validates
1216 applyMultiStateControlledRotateX(qureg, nullptr, nullptr, 0, target, angle);
1217}

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

1219 {
1220 validate_quregFields(qureg, __func__);
1221 validate_target(qureg, target, __func__);
1222
1223 // harmlessly re-validates
1224 applyMultiStateControlledRotateY(qureg, nullptr, nullptr, 0, target, angle);
1225}

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

1227 {
1228 validate_quregFields(qureg, __func__);
1229 validate_target(qureg, target, __func__);
1230
1231 // harmlessly re-validates
1232 applyMultiStateControlledRotateZ(qureg, nullptr, nullptr, 0, target, angle);
1233}