qiskit/releasenotes/notes/0.22/operator-parameters-c81b7c0...

27 lines
957 B
YAML

---
features:
- |
:class:`.SparsePauliOp`\ s can now be constructed with coefficient arrays
that are general Python objects. This is intended for use with
:class:`.ParameterExpression` objects; other objects may work, but do not
have first-class support. Some :class:`.SparsePauliOp` methods (such as
conversion to other class representations) may not work when using
``object`` arrays, if the desired target cannot represent these general
arrays.
For example, a :class:`.ParameterExpression` :class:`.SparsePauliOp` could
be constructed by::
import numpy as np
from qiskit.circuit import Parameter
from qiskit.quantum_info import SparsePauliOp
print(SparsePauliOp(["II", "XZ"], np.array([Parameter("a"), Parameter("b")])))
which gives
.. code-block:: text
SparsePauliOp(['II', 'XZ'],
coeffs=[ParameterExpression(1.0*a), ParameterExpression(1.0*b)])