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

Functions for applying general one-qubit dense matrices, as CompMatr1. More...

Functions

void applyCompMatr1 (Qureg qureg, int target, CompMatr1 matrix)
 
void applyControlledCompMatr1 (Qureg qureg, int control, int target, CompMatr1 matrix)
 
void applyMultiControlledCompMatr1 (Qureg qureg, int *controls, int numControls, int target, CompMatr1 matrix)
 
void applyMultiStateControlledCompMatr1 (Qureg qureg, int *controls, int *states, int numControls, int target, CompMatr1 matrix)
 

Detailed Description

Functions for applying general one-qubit dense matrices, as CompMatr1.

Function Documentation

◆ applyCompMatr1()

void applyCompMatr1 ( Qureg qureg,
int target,
CompMatr1 matrix )

Applies a general one-qubit dense unitary matrix to the specified target qubit of qureg.

Diagram
Formulae

Let \( \hat{U} = \) matrix, \( t = \) target, and let \(\hat{U}_t\) notate operating \(\hat{U}\) upon the \( t \)-th qubit among \( N \), i.e.

\[ \hat{U}_t \equiv \id^{N-t} \otimes \hat{U} \otimes \id^{t-1}. \]

Then,

  • When qureg is a statevector \( \svpsi \), this function effects

    \[ \svpsi \rightarrow \hat{U}_t \, \svpsi. \]

  • When qureg is a density matrix \(\dmrho\), this function effects

    \[ \dmrho \rightarrow \hat{U}_t \, \dmrho \, {\hat{U}_t}^\dagger. \]

Constraints
  • Unitarity of \( \hat{U} = \) matrix requires that \( \hat{U} \hat{U}^\dagger = \id \). Validation will check that matrix is approximately unitary via

    \[ \max\limits_{ij} \Big|\left(\hat{U} \hat{U}^\dagger - \id\right)_{ij}\Big|^2 \le \valeps \]

    where the validation epsilon \( \valeps \) can be adjusted with setValidationEpsilon().
Example
Qureg qureg = createQureg(5);
{-1i/sqrt(2), 1i/sqrt(2)},
{(1i-1)/2, (1i-1)/2}
});
applyCompMatr1(qureg, 2, matrix);
CompMatr1 getInlineCompMatr1({{ matrix }})
void applyCompMatr1(Qureg qureg, int target, CompMatr1 matrix)
Qureg createQureg(int numQubits)
Definition qureg.cpp:283
Definition qureg.h:49
Parameters
[in,out]quregthe state to modify.
[in]targetthe index of the target qubit.
[in]matrixthe Z-basis unitary matrix to effect.
Exceptions
error
  • if qureg or matrix are uninitialised.
  • if matrix is not approximately unitary.
  • if target is an invalid qubit index.
See also
Author
Tyson Jones

Definition at line 75 of file operations.cpp.

75 {
76
77 validateAndApplyAnyCtrlAnyTargUnitaryMatrix(qureg, nullptr, nullptr, 0, &target, 1, matrix, __func__);
78}

Referenced by TEST_CASE().

◆ applyControlledCompMatr1()

void applyControlledCompMatr1 ( Qureg qureg,
int control,
int target,
CompMatr1 matrix )

Applies a singly-controlled one-qubit dense unitary matrix to the specified target qubit of qureg.

Diagram
Formulae

Let \( \hat{U} = \) matrix, \( t = \) target, \( c = \) control, and let \(\hat{O}_q\) denote an operator upon the \(q\)-th qubit. This function effects operator

\[ C_c[\hat{U}_t] = \ketbra{0}{0}_c \otimes \id_t + \ketbra{1}{1}_c \otimes \hat{U}_t, \]

where \(\hat{U}\) is effected upon basis states for which qubit \(c\) has value 1. For illustration, when control=0 and target=1, this function would effect

\[ C_1[\hat{U}_0] \equiv \begin{pmatrix} 1 \\ & 1 \\ & & u_{00} & u_{01} \\ & & u_{10} & u_{11} \end{pmatrix}. \]

This operation can be performed upon statevectors and density matrices.

  • When qureg is a statevector \( \svpsi \), this function effects

    \[ \svpsi \rightarrow C_c[\hat{U}_t] \, \svpsi. \]

  • When qureg is a density matrix \(\dmrho\), this function effects

    \[ \dmrho \rightarrow C_c[\hat{U}_t] \, \dmrho \, {C_c[\hat{U}_t]}^\dagger. \]

Constraints
  • Unitarity of \( \hat{U} = \) matrix requires that \( \hat{U} \hat{U}^\dagger = \id \). Validation will check that matrix is approximately unitary via

    \[ \max\limits_{ij} \Big|\left(\hat{U} \hat{U}^\dagger - \id\right)_{ij}\Big|^2 \le \valeps \]

    where the validation epsilon \( \valeps \) can be adjusted with setValidationEpsilon().
Equivalences
Example
Qureg qureg = createQureg(5);
{-1i/sqrt(2), 1i/sqrt(2)},
{(1i-1)/2, (1i-1)/2}
});
// C_0[U_2]
applyControlledCompMatr1(qureg, 0, 2, matrix);
void applyControlledCompMatr1(Qureg qureg, int control, int target, CompMatr1 matrix)
Parameters
[in,out]quregthe state to modify.
[in]controlthe index of the control qubit.
[in]targetthe index of the target qubit.
[in]matrixthe Z-basis unitary matrix to effect.
Exceptions
error
  • if qureg or matrix are uninitialised.
  • if matrix is not approximately unitary.
  • if control or target are an invalid qubit index.
  • if control and target overlap.
See also
Author
Tyson Jones

Definition at line 80 of file operations.cpp.

80 {
81
82 validateAndApplyAnyCtrlAnyTargUnitaryMatrix(qureg, &control, nullptr, 1, &target, 1, matrix, __func__);
83}

◆ applyMultiControlledCompMatr1()

void applyMultiControlledCompMatr1 ( Qureg qureg,
int * controls,
int numControls,
int target,
CompMatr1 matrix )
Note
Documentation for this function or struct is under construction!

Applies a multiply-controlled one-qubit dense unitary matrix to the specified target qubit of qureg.

Diagram
Formulae

Let \( \vec{c} = \) controls, \( t = \) target, and \( \hat{U} = \) matrix. This functions effects operator

\[ C_{\vec{c}}[\hat{U}_t] \]

which is equivalent to applying \( \hat{U}_t \) upon only the computational basis states for which all control qubits are in the \( \ket{1} \) state.

Precisely, let \(n = 2^{|\vec{c}|}-1\). Then

\[ C_{\vec{c}}[\hat{U}_t] = \sum\limits_{i=0}^{n-1} \ketbra{i}{i}_{\vec{c}} \otimes \hat{\id}_t + \ketbra{n}{n}_{\vec{c}} \otimes \hat{U}_t \]

See also

Definition at line 85 of file operations.cpp.

85 {
86
87 validateAndApplyAnyCtrlAnyTargUnitaryMatrix(qureg, controls, nullptr, numControls, &target, 1, matrix, __func__);
88}

Referenced by applyMultiControlledCompMatr1().

◆ applyMultiStateControlledCompMatr1()

void applyMultiStateControlledCompMatr1 ( Qureg qureg,
int * controls,
int * states,
int numControls,
int target,
CompMatr1 matrix )
Note
Documentation for this function or struct is under construction!

Applies an arbitrarily-controlled one-qubit dense unitary matrix to the specified target qubit of qureg, conditioned upon the controls being in the given states.

Diagram
See also

Definition at line 90 of file operations.cpp.

90 {
91
92 validateAndApplyAnyCtrlAnyTargUnitaryMatrix(qureg, controls, states, numControls, &target, 1, matrix, __func__);
93}

Referenced by applyMultiStateControlledCompMatr1(), and applyMultiStateControlledRotateAroundAxis().