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

adjvec_to_op()

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’ ops expressed in basis. The shape is (len(ops), len(basis).

Return type:

TensorLike

The format of the resulting operators is determined by the type in basis. If is_orthogonal=True (the default), only normalization is taken into account in the projection. For is_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 Iterable of operators as input.

The ops can also be numerical, but then basis has to be numerical as well.

>>> op = op.matrix()
>>> op_to_adjvec([op], [op.matrix() for op in basis])
array([[1. , 0.5, 0. ]])