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

Functions for applying many-qubit rotations around Pauli Z axis, and phase flips and shifts. More...

Functions

void applyControlledPhaseGadget (Qureg qureg, int control, int *targets, int numTargets, qreal angle)
 
void applyMultiControlledPhaseGadget (Qureg qureg, int *controls, int numControls, int *targets, int numTargets, qreal angle)
 
void applyMultiQubitPhaseFlip (Qureg qureg, int *targets, int numTargets)
 
void applyMultiQubitPhaseShift (Qureg qureg, int *targets, int numTargets, qreal angle)
 
void applyMultiStateControlledPhaseGadget (Qureg qureg, int *controls, int *states, int numControls, int *targets, int numTargets, qreal angle)
 
void applyPhaseFlip (Qureg qureg, int target)
 
void applyPhaseGadget (Qureg qureg, int *targets, int numTargets, qreal angle)
 
void applyPhaseShift (Qureg qureg, int target, qreal angle)
 
void applyTwoQubitPhaseFlip (Qureg qureg, int target1, int target2)
 
void applyTwoQubitPhaseShift (Qureg qureg, int target1, int target2, qreal angle)
 

Detailed Description

Functions for applying many-qubit rotations around Pauli Z axis, and phase flips and shifts.

Function Documentation

◆ applyControlledPhaseGadget()

void applyControlledPhaseGadget ( Qureg qureg,
int control,
int * targets,
int numTargets,
qreal angle )
Note
Documentation for this function or struct is under construction!

Definition at line 1337 of file operations.cpp.

1337 {
1338 validate_quregFields(qureg, __func__);
1339 validate_controlAndTargets(qureg, control, targets, numTargets, __func__);
1340
1341 // harmlessly re-validates
1342 applyMultiStateControlledPhaseGadget(qureg, &control, nullptr, 1, targets, numTargets, angle);
1343}
void applyMultiStateControlledPhaseGadget(Qureg qureg, int *controls, int *states, int numControls, int *targets, int numTargets, qreal angle)

Referenced by applyControlledPhaseGadget().

◆ applyMultiControlledPhaseGadget()

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

Definition at line 1345 of file operations.cpp.

1345 {
1346 validate_quregFields(qureg, __func__);
1347 validate_controlsAndTargets(qureg, controls, numControls, targets, numTargets, __func__);
1348
1349 // harmlessly re-validates
1350 applyMultiStateControlledPhaseGadget(qureg, controls, nullptr, numControls, targets, numTargets, angle);
1351}

Referenced by applyMultiControlledPhaseGadget().

◆ applyMultiQubitPhaseFlip()

void applyMultiQubitPhaseFlip ( Qureg qureg,
int * targets,
int numTargets )
Note
Documentation for this function or struct is under construction!
Formulae

This function flips the sign of all computational basis states for which the targeted qubits are all in state \( \ket{1} \). This is equivalent to the diagonal unitary

\[ \hat{U}(\theta) = \begin{pmatrix} 1 \\ & \ddots \\ & & 1 \\ & & & -1 \end{pmatrix}, \]

effected upon the target qubits.

Equivalences
  • The ordering of targets has no affect on the effected operation.
  • This function is entirely equivalent to a multi-controlled Pauli-Z unitary (or a hypothetical many-controlled variant of applyPhaseFlip()) with all but one arbitrary target qubit becoming control qubits.
    applyMultiControlledPauliZ(qureg, targets, numTargets-1, targets[0]);
    void applyMultiControlledPauliZ(Qureg qureg, int *controls, int numControls, int target)
  • This function is faster and more accurate than, but otherwise equivalent to, a multi-qubit phase shift with angle \( = \pi \).
    applyMultiQubitPhaseShift(qureg, targets, numTargets, 3.141592653); // approx equiv
    void applyMultiQubitPhaseShift(Qureg qureg, int *targets, int numTargets, qreal angle)

Definition at line 1464 of file operations.cpp.

1464 {
1465 validate_quregFields(qureg, __func__);
1466 validate_targets(qureg, targets, numTargets, __func__);
1467
1468 // treat as a (numTargets-1)-controlled 1-target Pauli Z
1469 DiagMatr1 matr = getDiagMatr1({1, -1});
1470
1471 // harmlessly re-validates
1472 applyMultiStateControlledDiagMatr1(qureg, &targets[1], nullptr, numTargets-1, targets[0], matr);
1473}
static DiagMatr1 getDiagMatr1(qcomp *in)
Definition matrices.h:378
void applyMultiStateControlledDiagMatr1(Qureg qureg, int *controls, int *states, int numControls, int target, DiagMatr1 matrix)

Referenced by applyMultiQubitPhaseFlip(), applyPhaseFlip(), and applyTwoQubitPhaseFlip().

◆ applyMultiQubitPhaseShift()

void applyMultiQubitPhaseShift ( Qureg qureg,
int * targets,
int numTargets,
qreal angle )
Note
Documentation for this function or struct is under construction!
Formulae

Let \( \theta = \) angle. This function multiplies factor \( e^{\iu \theta} \) upon all computational basis states for which all targeted qubits are in state \( \ket{1} \). This is equivalent to the diagonal unitary

\[ \hat{U}(\theta) = \begin{pmatrix} 1 \\ & \ddots \\ & & 1 \\ & & & e^{\iu \theta} \end{pmatrix}, \]

effected upon the target qubits.

Diagram
Equivalences
  • The ordering of targets has no affect on the effected operation.
  • This function is equivalent to a multi-controlled variant of applyPhaseShift(), treating all but one arbitrary target qubit as control qubits.
  • This function generalises applyMultiQubitPhaseFlip() to arbitrary changes in phase.
  • Passing angle=0 is equivalent to effecting the identity, leaving the state unchanged.

Definition at line 1421 of file operations.cpp.

1421 {
1422 validate_quregFields(qureg, __func__);
1423 validate_targets(qureg, targets, numTargets, __func__);
1424
1425 // treat as a (numTargets-1)-controlled 1-target diagonal matrix
1426 DiagMatr1 matr = getDiagMatr1({1, std::exp(1_i * angle)});
1427
1428 // harmlessly re-validates
1429 applyMultiStateControlledDiagMatr1(qureg, &targets[1], nullptr, numTargets-1, targets[0], matr);
1430}

Referenced by applyMultiQubitPhaseShift(), applyPhaseShift(), and applyTwoQubitPhaseShift().

◆ applyMultiStateControlledPhaseGadget()

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

Definition at line 1353 of file operations.cpp.

1353 {
1354 validate_quregFields(qureg, __func__);
1355 validate_controlsAndTargets(qureg, controls, numControls, targets, numTargets, __func__);
1356 validate_controlStates(states, numControls, __func__);
1357
1358 qreal phase = util_getPhaseFromGateAngle(angle);
1359 auto ctrlVec = util_getVector(controls, numControls);
1360 auto targVec = util_getVector(targets, numTargets);
1361 auto stateVec = util_getVector(states, numControls); // empty if states==nullptr
1362 localiser_statevec_anyCtrlPhaseGadget(qureg, ctrlVec, stateVec, targVec, phase);
1363
1364 if (!qureg.isDensityMatrix)
1365 return;
1366
1367 phase *= -1;
1368 ctrlVec = util_getBraQubits(ctrlVec, qureg);
1369 targVec = util_getBraQubits(targVec, qureg);
1370 localiser_statevec_anyCtrlPhaseGadget(qureg, ctrlVec, stateVec, targVec, phase);
1371}

Referenced by applyControlledPhaseGadget(), applyMultiControlledPhaseGadget(), applyMultiStateControlledPhaseGadget(), and applyPhaseGadget().

◆ applyPhaseFlip()

void applyPhaseFlip ( Qureg qureg,
int target )
Note
Documentation for this function or struct is under construction!

This function is a mere alias of applyPauliZ(), meaningfully differing only for many targets.

Definition at line 1447 of file operations.cpp.

1447 {
1448 validate_quregFields(qureg, __func__);
1449 validate_target(qureg, target, __func__);
1450
1451 // harmlessly re-validates
1452 applyMultiQubitPhaseFlip(qureg, &target, 1);
1453}
void applyMultiQubitPhaseFlip(Qureg qureg, int *targets, int numTargets)

◆ applyPhaseGadget()

void applyPhaseGadget ( Qureg qureg,
int * targets,
int numTargets,
qreal angle )
Note
Documentation for this function or struct is under construction!
Formulae

Let \( \vec{t} = \) targets and \( \theta = \) angle.

This function effects diagonal unitary

\[ R_{\hat{Z}}(\theta) = \exp \left( - \iu \, \frac{\theta}{2} \, \bigotimes_{t \,\in\, \vec{t}} \hat{Z}_t \right). \]

Equivalences
  • This function is equivalent to calling applyPauliGadget() with a PauliStr containing only \( \hat{Z} \) and \( \id \). This latter function will actually automatically invoke applyPhaseGadget() which has an optimised implementation.
  • This function is equivalent to, albeit much faster than, preparing a DiagMatr with \( \pm 1 \) elements (depending upon the parity of the targeted set bits) and effecting it with applyDiagMatr().
  • Passing angle=0 is equivalent to effecting the identity, leaving the state unchanged.

Definition at line 1329 of file operations.cpp.

1329 {
1330 validate_quregFields(qureg, __func__);
1331 validate_targets(qureg, targets, numTargets, __func__);
1332
1333 // harmlessly re-validates
1334 applyMultiStateControlledPhaseGadget(qureg, nullptr, nullptr, 0, targets, numTargets, angle);
1335}

Referenced by applyPhaseGadget().

◆ applyPhaseShift()

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

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

\[ \hat{U}(\theta) = \begin{pmatrix} 1 & 0 \\ 0 & e^{\iu \theta} \end{pmatrix} \]

upon the target qubit.

Equivalences
  • This function is equivalent to, albeit much faster than, a Z-axis rotation with an adjustment to the global phase (which is redundant upon density matrices).

    \[ \hat{U}(\theta) \equiv \hat{R}_z(\theta) \cdot e^{\iu \frac{\theta}{2}} \hat{\id} \]

    applyRotateZ(qureg, target, angle);
    applyPauliGadget(qureg, getPauliStr("I"), angle); // global phase
    void applyPauliGadget(Qureg qureg, PauliStr str, qreal angle)
    void applyRotateZ(Qureg qureg, int target, qreal angle)
    PauliStr getPauliStr(const char *paulis, int *indices, int numPaulis)
    Definition paulis.cpp:76
  • Passing angle=0 is equivalent to effecting the identity, leaving the state unchanged.

Definition at line 1404 of file operations.cpp.

1404 {
1405 validate_quregFields(qureg, __func__);
1406 validate_target(qureg, target, __func__);
1407
1408 // harmlessly re-validates
1409 applyMultiQubitPhaseShift(qureg, &target, 1, angle);
1410}

◆ applyTwoQubitPhaseFlip()

void applyTwoQubitPhaseFlip ( Qureg qureg,
int target1,
int target2 )
Note
Documentation for this function or struct is under construction!

Applies a two-qubit phase flip upon qubits target1 and target2 of qureg.

Formulae

This function flips the sign of all computational basis states for which the targeted qubits are in state \( \ket{1}\ket{1} \). This is equivalent to the diagonal unitary

\[ \hat{U}(\theta) = \begin{pmatrix} 1 \\ & 1 \\ & & 1 \\ & & & -1 \end{pmatrix}, \]

effected upon the target qubits.

Diagram
Equivalences

Definition at line 1455 of file operations.cpp.

1455 {
1456 validate_quregFields(qureg, __func__);
1457 validate_twoTargets(qureg, target1, target2, __func__);
1458
1459 // harmlessly re-validates
1460 int targets[] = {target1, target2};
1461 applyMultiQubitPhaseFlip(qureg, targets, 2);
1462}

◆ applyTwoQubitPhaseShift()

void applyTwoQubitPhaseShift ( Qureg qureg,
int target1,
int target2,
qreal angle )
Note
Documentation for this function or struct is under construction!

Applies a two-qubit phase shift upon qubits target1 and target2 of qureg.

Formulae

Let \( \theta = \) angle. This function multiplies factor \( e^{\iu \theta} \) upon all computational basis states for which the targeted qubits are in state \( \ket{1}\ket{1} \). This is equivalent to the diagonal unitary

\[ \hat{U}(\theta) = \begin{pmatrix} 1 \\ & 1 \\ & & 1 \\ & & & e^{\iu \theta} \end{pmatrix}, \]

effected upon the target qubits.

Diagram
Equivalences
  • The target qubits are interchangeable, ergo
    applyTwoQubitPhaseShift(qureg, target1, target2, angle);
    applyTwoQubitPhaseShift(qureg, target2, target1, angle); // equivalent
  • This function is equivalent to a controlled variant of applyPhaseShift(), treating either target qubit as the control qubit.
  • This function generalises applyTwoQubitPhaseFlip() to arbitrary changes in phase.
  • Passing angle=0 is equivalent to effecting the identity, leaving the state unchanged.

Definition at line 1412 of file operations.cpp.

1412 {
1413 validate_quregFields(qureg, __func__);
1414 validate_twoTargets(qureg, target1, target2, __func__);
1415
1416 // harmlessly re-validates
1417 int targets[] = {target1, target2};
1418 applyMultiQubitPhaseShift(qureg, targets, 2, angle);
1419}

Referenced by applyQuantumFourierTransform().