The Quantum Exact Simulation Toolkit v4.0.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 applyMultiControlledCompMatr1 (Qureg qureg, std::vector< int > controls, int target, CompMatr1 matrix)
 
void applyMultiStateControlledCompMatr1 (Qureg qureg, int *controls, int *states, int numControls, int target, CompMatr1 matrix)
 
void applyMultiStateControlledCompMatr1 (Qureg qureg, std::vector< int > controls, std::vector< int > states, int target, CompMatr1 matrix)
 
void multiplyCompMatr1 (Qureg qureg, 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 unitarity 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:279
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 80 of file operations.cpp.

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

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
Note
Documentation for this function or struct is under construction!

Definition at line 85 of file operations.cpp.

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

◆ applyMultiControlledCompMatr1() [1/2]

void applyMultiControlledCompMatr1 ( Qureg qureg,
int * controls,
int numControls,
int target,
CompMatr1 matrix )

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

Diagram
Note
Documentation for this function or struct is under construction!

Definition at line 90 of file operations.cpp.

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

Referenced by applyMultiControlledCompMatr1().

◆ applyMultiControlledCompMatr1() [2/2]

void applyMultiControlledCompMatr1 ( Qureg qureg,
std::vector< int > controls,
int target,
CompMatr1 matrix )
Warning
This function has not yet been unit tested and may contain bugs. Please use with caution!
Attention
This function's input validation has not yet been unit tested, so erroneous usage may produce unexpected output. Please use with caution!
Note
Documentation for this function or struct is under construction!
Remarks
This function is only available in C++.

Definition at line 102 of file operations.cpp.

102 {
103
104 applyMultiControlledCompMatr1(qureg, controls.data(), controls.size(), target, matrix);
105}
void applyMultiControlledCompMatr1(Qureg qureg, int *controls, int numControls, int target, CompMatr1 matrix)

◆ applyMultiStateControlledCompMatr1() [1/2]

void applyMultiStateControlledCompMatr1 ( Qureg qureg,
int * controls,
int * states,
int numControls,
int target,
CompMatr1 matrix )

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
Note
Documentation for this function or struct is under construction!

Definition at line 95 of file operations.cpp.

95 {
96
97 validateAndApplyAnyCtrlAnyTargUnitaryMatrix(qureg, controls, states, numControls, &target, 1, matrix, __func__);
98}

Referenced by applyMultiStateControlledCompMatr1(), and applyMultiStateControlledRotateAroundAxis().

◆ applyMultiStateControlledCompMatr1() [2/2]

void applyMultiStateControlledCompMatr1 ( Qureg qureg,
std::vector< int > controls,
std::vector< int > states,
int target,
CompMatr1 matrix )
Warning
This function has not yet been unit tested and may contain bugs. Please use with caution!
Attention
This function's input validation has not yet been unit tested, so erroneous usage may produce unexpected output. Please use with caution!
Note
Documentation for this function or struct is under construction!
Remarks
This function is only available in C++.

Definition at line 107 of file operations.cpp.

107 {
108 validate_controlsMatchStates(controls.size(), states.size(), __func__);
109
110 applyMultiStateControlledCompMatr1(qureg, controls.data(), states.data(), controls.size(), target, matrix);
111}
void applyMultiStateControlledCompMatr1(Qureg qureg, int *controls, int *states, int numControls, int target, CompMatr1 matrix)

◆ multiplyCompMatr1()

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

Multiplies a general one-qubit dense matrix upon the specified target qubit of qureg.

Formulae
Let \( \hat{M} = \) matrix and \( t = \) target, and notate \(\hat{M}_t\) as per applyCompMatr1(). Unlike applyCompMatr1() however, this function only ever left-multiplies matrix upon qureg, regardless of whether it is a statevector or density matrix.

Explicitly,

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

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

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

    \[ \dmrho \rightarrow \hat{M}_t \, \dmrho. \]

There are no additional constraints like unitarity.

Example
{0.1, 0.2},
{0.3i, 0.4i}
});
multiplyCompMatr1(qureg, 2, matrix);
void multiplyCompMatr1(Qureg qureg, int target, CompMatr1 matrix)
Qureg createDensityQureg(int numQubits)
Definition qureg.cpp:287
Parameters
[in,out]quregthe state to modify.
[in]targetthe index of the target qubit.
[in]matrixthe Z-basis matrix to multiply.
Exceptions
error
  • if qureg or matrix are uninitialised.
  • if target is an invalid qubit index.
See also
Author
Tyson Jones

Definition at line 71 of file operations.cpp.

71 {
72 validate_quregFields(qureg, __func__);
73 validate_target(qureg, target, __func__);
74 validate_matrixFields(matrix, __func__); // matrix can be non-unitary
75
76 bool conj = false;
77 localiser_statevec_anyCtrlOneTargDenseMatr(qureg, {}, {}, target, matrix, conj);
78}