The Quantum Exact Simulation Toolkit v4.1.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)
 
void multiplyPhaseGadget (Qureg qureg, int *targets, int numTargets, 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 1516 of file operations.cpp.

1516 {
1517 validate_quregFields(qureg, __func__);
1518 validate_controlAndTargets(qureg, control, targets, numTargets, __func__);
1519
1520 // harmlessly re-validates
1521 applyMultiStateControlledPhaseGadget(qureg, &control, nullptr, 1, targets, numTargets, angle);
1522}
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 1524 of file operations.cpp.

1524 {
1525 validate_quregFields(qureg, __func__);
1526 validate_controlsAndTargets(qureg, controls, numControls, targets, numTargets, __func__);
1527
1528 // harmlessly re-validates
1529 applyMultiStateControlledPhaseGadget(qureg, controls, nullptr, numControls, targets, numTargets, angle);
1530}

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

1648 {
1649 validate_quregFields(qureg, __func__);
1650 validate_targets(qureg, targets, numTargets, __func__);
1651
1652 // treat as a (numTargets-1)-controlled 1-target Pauli Z
1653 DiagMatr1 matr = getDiagMatr1({1, -1});
1654
1655 // harmlessly re-validates
1656 applyMultiStateControlledDiagMatr1(qureg, &targets[1], nullptr, numTargets-1, targets[0], matr);
1657}
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 1605 of file operations.cpp.

1605 {
1606 validate_quregFields(qureg, __func__);
1607 validate_targets(qureg, targets, numTargets, __func__);
1608
1609 // treat as a (numTargets-1)-controlled 1-target diagonal matrix
1610 DiagMatr1 matr = getDiagMatr1({1, std::exp(1_i * angle)});
1611
1612 // harmlessly re-validates
1613 applyMultiStateControlledDiagMatr1(qureg, &targets[1], nullptr, numTargets-1, targets[0], matr);
1614}

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

1532 {
1533 validate_quregFields(qureg, __func__);
1534 validate_controlsAndTargets(qureg, controls, numControls, targets, numTargets, __func__);
1535 validate_controlStates(states, numControls, __func__);
1536
1537 qreal phase = util_getPhaseFromGateAngle(angle);
1538 auto ctrlVec = util_getVector(controls, numControls);
1539 auto targVec = util_getVector(targets, numTargets);
1540 auto stateVec = util_getVector(states, numControls); // empty if states==nullptr
1541 localiser_statevec_anyCtrlPhaseGadget(qureg, ctrlVec, stateVec, targVec, phase);
1542
1543 if (!qureg.isDensityMatrix)
1544 return;
1545
1546 phase *= -1;
1547 ctrlVec = util_getBraQubits(ctrlVec, qureg);
1548 targVec = util_getBraQubits(targVec, qureg);
1549 localiser_statevec_anyCtrlPhaseGadget(qureg, ctrlVec, stateVec, targVec, phase);
1550}

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

1631 {
1632 validate_quregFields(qureg, __func__);
1633 validate_target(qureg, target, __func__);
1634
1635 // harmlessly re-validates
1636 applyMultiQubitPhaseFlip(qureg, &target, 1);
1637}
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 1508 of file operations.cpp.

1508 {
1509 validate_quregFields(qureg, __func__);
1510 validate_targets(qureg, targets, numTargets, __func__);
1511
1512 // harmlessly re-validates
1513 applyMultiStateControlledPhaseGadget(qureg, nullptr, nullptr, 0, targets, numTargets, angle);
1514}

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:306
  • Passing angle=0 is equivalent to effecting the identity, leaving the state unchanged.

Definition at line 1588 of file operations.cpp.

1588 {
1589 validate_quregFields(qureg, __func__);
1590 validate_target(qureg, target, __func__);
1591
1592 // harmlessly re-validates
1593 applyMultiQubitPhaseShift(qureg, &target, 1, angle);
1594}

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

1639 {
1640 validate_quregFields(qureg, __func__);
1641 validate_twoTargets(qureg, target1, target2, __func__);
1642
1643 // harmlessly re-validates
1644 int targets[] = {target1, target2};
1645 applyMultiQubitPhaseFlip(qureg, targets, 2);
1646}

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

1596 {
1597 validate_quregFields(qureg, __func__);
1598 validate_twoTargets(qureg, target1, target2, __func__);
1599
1600 // harmlessly re-validates
1601 int targets[] = {target1, target2};
1602 applyMultiQubitPhaseShift(qureg, targets, 2, angle);
1603}

Referenced by applyQuantumFourierTransform().

◆ multiplyPhaseGadget()

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

Definition at line 1500 of file operations.cpp.

1500 {
1501 validate_quregFields(qureg, __func__);
1502 validate_targets(qureg, targets, numTargets, __func__);
1503
1504 qreal phase = util_getPhaseFromGateAngle(angle);
1505 localiser_statevec_anyCtrlPhaseGadget(qureg, {}, {}, util_getVector(targets,numTargets), phase);
1506}

Referenced by multiplyPhaseGadget().