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

Functions for applying many-qubit rotations around the 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 the 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!

Applies a singly-controlled many-qubit Z rotation upon qureg, generated by a tensor product of Pauli Z operators upon targets.

‍- See applyPhaseGadget() for information about the base operation, angle, and targets.

Author
Tyson Jones

Definition at line 1338 of file operations.cpp.

1338 {
1339 validate_quregFields(qureg, __func__);
1340 validate_controlAndTargets(qureg, control, targets, numTargets, __func__);
1341
1342 // harmlessly re-validates
1343 applyMultiStateControlledPhaseGadget(qureg, &control, nullptr, 1, targets, numTargets, angle);
1344}
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!

Applies a multiply-controlled many-qubit Z rotation upon qureg, generated by a tensor product of Pauli Z operators upon targets.

‍- See applyPhaseGadget() for information about the base operation, angle, and targets.

Author
Tyson Jones

Definition at line 1346 of file operations.cpp.

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

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.

Remarks
This function is sometimes more efficient when targets are specified in increasing order, though the effect of this function is incidentally unaffected by the ordering of targets.
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 1466 of file operations.cpp.

1466 {
1467 validate_quregFields(qureg, __func__);
1468 validate_targets(qureg, targets, numTargets, __func__);
1469
1470 // treat as a (numTargets-1)-controlled 1-target Pauli Z
1471 static const DiagMatr1 matr = getDiagMatr1({1, -1});
1472
1473 // harmlessly re-validates
1474 applyMultiStateControlledDiagMatr1(qureg, &targets[1], nullptr, numTargets-1, targets[0], matr);
1475}
static DiagMatr1 getDiagMatr1(qcomp *in)
Definition matrices.h:864
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.

Remarks
This function is sometimes more efficient when targets are specified in increasing order, though the effect of this function is incidentally unaffected by the ordering of targets.
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 1422 of file operations.cpp.

1422 {
1423 validate_quregFields(qureg, __func__);
1424 validate_targets(qureg, targets, numTargets, __func__);
1425
1426 // treat as a (numTargets-1)-controlled 1-target diagonal matrix
1427 static DiagMatr1 matr = getDiagMatr1({1, /*un-init*/ 0});
1428 matr.elems[1] = std::exp(1_i * angle); // micro-optimisation
1429
1430 // harmlessly re-validates
1431 applyMultiStateControlledDiagMatr1(qureg, &targets[1], nullptr, numTargets-1, targets[0], matr);
1432}
qcomp elems[2]
Definition matrices.h:336

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!

Applies an arbitrarily-controlled many-qubit Z rotation upon qureg, generated by a tensor product of Pauli Z operators upon targets, and conditioned upon controls being in the corresponding states.

‍- See applyPhaseGadget() for information about the base operation, angle, and targets.

Author
Tyson Jones

Definition at line 1354 of file operations.cpp.

1354 {
1355 validate_quregFields(qureg, __func__);
1356 validate_controlsAndTargets(qureg, controls, numControls, targets, numTargets, __func__);
1357 validate_controlStates(states, numControls, __func__);
1358
1359 qreal phase = util_getPhaseFromGateAngle(angle);
1360 auto ctrlList = lists_getList64(controls, numControls);
1361 auto stateList = util_getList64OrAllOnes(states, numControls);
1362 auto targList = lists_getList64(targets, numTargets);
1363 localiser_statevec_anyCtrlPhaseGadget(qureg, ctrlList, stateList, targList, phase);
1364
1365 if (!qureg.isDensityMatrix)
1366 return;
1367
1368 phase *= -1;
1369 ctrlList = util_getBraQubits(ctrlList, qureg);
1370 targList = util_getBraQubits(targList, qureg);
1371 localiser_statevec_anyCtrlPhaseGadget(qureg, ctrlList, stateList, targList, phase);
1372}

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

1449 {
1450 validate_quregFields(qureg, __func__);
1451 validate_target(qureg, target, __func__);
1452
1453 // harmlessly re-validates
1454 applyMultiQubitPhaseFlip(qureg, &target, 1);
1455}
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!

Applies a many-qubit Z rotation upon qureg, generated by a tensor product of Pauli Z operators upon targets.

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). \]

Remarks
This function is sometimes more efficient when targets are specified in increasing order, though the effect of this function is incidentally unaffected by the ordering of targets.
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 1330 of file operations.cpp.

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

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

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

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

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

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

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

Referenced by applyQuantumFourierTransform().