pprop.pauli.sentence module

This module defines PauliDict, a mapping from PauliOp to a list of trigonometric coefficient terms.

Coefficient representation

Each coefficient is stored as a CoeffTerms, a list of CoeffTerm tuples of the form (coeff, sin_idx, cos_idx), encoding the product:

\[c \prod_{i \in \text{sin\_idx}} \sin(\theta_i) \prod_{j \in \text{cos\_idx}} \cos(\theta_j)\]
class pprop.pauli.sentence.PauliDict(data=None)[source]

Bases: object

A mapping from PauliOp to CoeffTerms.

Each PauliOp key maps to a list of CoeffTerm tuples, where each tuple encodes one trigonometric product term. The full coefficient at parameters \(\boldsymbol{\theta}\) is:

\[\sum_k c_k \prod_{i \in S_k} \sin(\theta_i) \prod_{j \in C_k} \cos(\theta_j)\]

where \((c_k, S_k, C_k)\) ranges over the list stored for that key.

Parameters:

data (dict, optional) – Initial mapping of PauliOp -> CoeffTerms. If None (default), an empty dict is used.

Examples

>>> d = PauliDict()
>>> key = PauliOp(0b01, 0b00)    # X on qubit 0
>>> d.add_term(key, (0.5, [0], [1]))    # 0.5 * sin(θ₀) * cos(θ₁)
>>> d.add_term(key, (0.5, [], [0, 1]))  # 0.5 * cos(θ₀) * cos(θ₁)
add_term(key, term)[source]

Append a single CoeffTerm to the list for key.

This is the primary accumulation method during Heisenberg propagation: each evolved term is appended without any simplification.

Parameters:
  • key (PauliOp) – The Pauli word to which the term belongs.

  • term (CoeffTerm) – A (coeff, sin_indices, cos_indices) tuple to append.

Return type:

None

add_terms(key, terms)[source]

Extend the coefficient list for key with multiple CoeffTerm tuples.

Parameters:
  • key (PauliOp) – The Pauli word to update.

  • terms (CoeffTerms) – A list of (coeff, sin_indices, cos_indices) tuples to append.

Return type:

None

add_terms_from_dict(other)[source]

Merge all entries from other into self.

For keys present in both dicts the term lists are concatenated; for keys only in other a copy of their list is inserted.

Parameters:

other (PauliDict) – The source mapping to merge from.

Return type:

None

classmethod from_qml(qml_op)[source]

Construct a PauliDict from a PennyLane operator.

The operator is decomposed into a sum of Pauli words via pennylane.ops.op_math.sum(). Each Pauli word receives a constant (parameter-independent) coefficient, encoded as a CoeffTerm with empty sin_idx and cos_idx lists.

Parameters:

qml_op (pennylane.operation.Operator) – A PennyLane observable, typically the output of qml.expval(...).

Return type:

PauliDict

items()[source]

Return a view of (PauliOp, CoeffTerms) pairs.

Return type:

ItemsView[PauliOp, list[tuple[float, list[int], list[int]]]]

keys()[source]

Return a view of all PauliOp keys.

Return type:

KeysView[PauliOp]

remove_keys_from_dict(other)[source]

Remove all keys from self that also appear in other.

Used by __isub__() to discard Pauli words that have been replaced by their evolved counterparts during propagation.

Parameters:

other (PauliDict) – Keys to remove.

Return type:

None

values()[source]

Return a view of all CoeffTerms values.

Return type:

ValuesView[list[tuple[float, list[int], list[int]]]]