to_spo¶
- to_spo(op, *, wires=None)[source]¶
Convert a PennyLane operator,
SparsePauliOp, or Pauli-string dict toSparsePauliOp, validating Hermiticity in every case.The PennyLane branch builds a new
SparsePauliOpby walking the operator tree. The dict branch accepts{pauli_string: coefficient}mappings such as{"XXIY": 1.0, "ZIII": -0.5}— every key must be a non-empty string over{I, X, Y, Z}, all keys must share a length, and coefficients must be real.Note
Pauli strings are read in divi convention: the leftmost character is qubit 0 (so
"XXIY"meansX(0) X(1) I(2) Y(3)). Qiskit’s nativefrom_list()and the.to_labels()output of the returned SPO use the opposite convention (qubit 0 rightmost), so dict keys you type in and the labels you read back will look reversed — the symplectic representation is what stays consistent across both forms.- Parameters:
op (
Operator|SparsePauliOp|dict[str,float]) – Operator to convert.wires – Optional wire register to resolve a PennyLane operator against. When
None(default), falls back toop.wires, which yields an SPO whose qubit count equals the operator’s own wire count. Pass an explicit wires register when the surrounding circuit is wider than the operator’s own support (e.g. a single-qubit observable inside an n-qubit script). Ignored forSparsePauliOpand dict inputs.
- Return type:
For repeated use on the same observable, convert once at setup and reuse the returned
SparsePauliOp.