qml.liealg.op_to_adjvec¶
- op_to_adjvec(ops, basis, is_orthogonal=True)[source]¶
Decompose a batch of operators into a given operator basis.
The adjoint vector representation is provided by the coefficients \(c_j\) in a given operator basis of the operator \(\hat{b}_j\) such that the input operator can be written as \(\hat{O} = \sum_j c_j \hat{b}_j\).
See also
- Parameters:
ops (Iterable[Union[PauliSentence, Operator, TensorLike]]) – List of operators to decompose.
basis (Iterable[Union[PauliSentence, Operator, TensorLike]]) – Operator basis.
is_orthogonal (bool) – Whether the basis is orthogonal with respect to the trace inner product. Defaults to
True, which allows to skip some computations.
- Returns:
The batch of coefficient vectors of the operators’
opsexpressed inbasis. The shape is(len(ops), len(basis).- Return type:
TensorLike
The format of the resulting operators is determined by the
typeinbasis. Ifis_orthogonal=True(the default), only normalization is taken into account in the projection. Foris_orthogonal=False, orthogonalization also is considered.Example
The basis can be numerical or operators.
>>> from pennylane.liealg import op_to_adjvec >>> op = qml.X(0) + 0.5 * qml.Y(0) >>> basis = [qml.X(0), qml.Y(0), qml.Z(0)] >>> op_to_adjvec([op], basis) array([[1. , 0.5, 0. ]]) >>> op_to_adjvec([op], [op.matrix() for op in basis]) array([[1. , 0.5, 0. ]])
Note how the function always expects an
Iterableof operators as input.The
opscan also be numerical, but thenbasishas to be numerical as well.>>> op = op.matrix() >>> op_to_adjvec([op], [op.matrix() for op in basis]) array([[1. , 0.5, 0. ]])