qp.pauli.to_operator¶
- to_operator(value, identity_wires=())[source]¶
Convert a
PauliWordorPauliSentenceinto a PennyLaneOperator.- Parameters:
value (PauliWord or PauliSentence) – The Pauli representation to convert.
identity_wires (Iterable) – Wires assigned to identity terms, including the identity used to represent zero. If empty, uses a nonempty sentence’s wires; otherwise defaults to no wires. Does not change the wires of non-identity terms.
- Returns:
The corresponding operator, without adding it to the queue.
- Return type:
- Raises:
TypeError – If
valueis not a Pauli word or sentence.
An empty word represents identity and an empty sentence represents zero. Zero coefficients are retained; no pruning is performed.
Example
>>> from pennylane.core.operator import Operator >>> word = qp.pauli.PauliWord({0: "X", 1: "Z"}) >>> word_op = qp.pauli.to_operator(word) >>> isinstance(word_op, Operator) True >>> word_op X(0) @ Z(1) >>> sentence = qp.pauli.PauliSentence({word: 2.0}) >>> sentence_op = qp.pauli.to_operator(sentence) >>> isinstance(sentence_op, Operator) True >>> sentence_op 2.0 * (X(0) @ Z(1))