ham_bp_to_ham_operator

ham_bp_to_ham_operator#

iqm.qaoa.transforming_functions.ham_bp_to_ham_operator(ham_bp)[source]#

A function to transform a Hamiltonian represented as a BP into a SparsePauliOp.

A Hamiltonian as SparsePauliOp may be used by qiskit functions that e.g., calculate expectation values. The input dimod.higherorder.BinaryPolynomial needs to have sortable variables. This is already the case if the ham_bp comes from a HUBOInstance.

Parameters:

ham_bp (BinaryPolynomial) – A BinaryPolynomial with vartype=SPIN, where each term corresponds to a product of spin variables and its coefficient represents the prefactor of the associated multi-qubit Z…Z Pauli operator in the problem Hamiltonian.

Returns:

The Hamiltonian as SparsePauliOp to be used by qiskit.

Raises:

TypeError – If the variables of the input ham_bp are not sortable.

Return type:

SparsePauliOp