pub unsafe extern "C" fn createSubDiagonalOp(
numQubits: c_int,
) -> SubDiagonalOpExpand description
Creates a ::SubDiagonalOp representing a diagonal operator which can act upon a subset of the qubits in a ::Qureg. This is similar to a ::DiagonalOp acting upon specific qubits.
The resulting operator (initially all zero) need not be unitary nor Hermitian, and can be applied to any ::Qureg of a compatible number of qubits.
This function allocates space for \f$2^{\text{numQubits}}\f$ complex amplitudes, which are initially zero. This is the same cost as a local state-vector of equal number of qubits; see the Serial section of createQureg(). Unlike ::DiagonalOp, this object is not distributed; instead, all nodes (during distributed simulation) store the full set of diagonal elements, similar to a ::ComplexMatrixN.
The returned ::SubDiagonalOp must be later freed with destroySubDiagonalOp().
For example, the below code creates an 8x8 identity operator.
SubDiagonalOp op = createSubDiagonalOp(3);
for (int i=0; i<op.numElems; i++)
op.real[i] = 1;\n
@see
- diagonalUnitary() to apply the created ::SubDiagonalOp upon a subset of qubits of a ::Qureg
- applyGateSubDiagonalOp() to relax the numerical unitarity requirement of diagonalUnitary()
- applySubDiagonalOp() to apply the SubDiagonalOp through left-multiplication only (as a non-unitary) upon a density matrix
- destroySubDiagonalOp()
- createDiagonalOp()
@ingroup type @returns a SubDiagonalOp instance initialised to diag(0,0,…). @param[in] numQubits number of qubits which inform the Hilbert dimension of the returned ::SubDiagonalOp. @throws invalidQuESTInputError()
- if \p numQubits <= 0
- if \p numQubits is so large that the number of elements cannot fit in a long long int type, @throws exit
- if the memory could not be allocated @author Tyson Jones