Skip to content

ppvm_pauli_sum::sum

sum

ppvm_pauli_sum::sum

classPauliSumsource

ppvm_pauli_sum::sum::PauliSum

Bases: Clifford, CliffordExtensions, CliffordBatch, CliffordExtensionsBatch, Clone, IntoIterator, PartialEq, Extend<(<T as Config>::PauliWordType, <T as Config>::Coeff)>, Debug, Display, PauliError<T>, TwoQubitPauliError<T>, Depolarizing<T>, Depolarizing2<T>, AmplitudeDamping<T>, LossChannel<T>, CorrelatedLossChannel<T>, ResetLossChannel<T>, MulAssign<f64>, Mul, Mul<W>, MulAssign, MulAssign<PauliWord<<T as Config>::Storage, <T as Config>::BuildHasher>>, AddAssign, AddAssign<&'a PauliSum<T>>, AddAssign<(P, <T as Config>::Coeff)>, AddAssign<P>, Projection, RotationOne<T>, RotXY<T>, RotationTwo<T>, Trace<'a, Rhs>, AbsDiffEq, RelativeEq

Rust struct. A sparse formal sum `Σ cᵢ Pᵢ` of Pauli strings.

pub struct PauliSum<T: Config>

The central data type of the Pauli-propagation backend. Keys are PauliWord-shaped Pauli strings; values are numeric coefficients. Generic over a Config that fixes the concrete storage / hasher / coefficient / strategy.

Internally `PauliSum` holds two maps — a primary and an auxiliary — and swaps between them during gate propagation to avoid repeated allocations. The PauliSum::data / PauliSum::aux accessors expose the current orientation; most callers will only ever touch the primary side via the high-level gate / measurement traits.

Heisenberg-picture propagation of `ZZ` through the GHZ circuit:

``` use ppvm_pauli_sum::prelude::*;

let mut state: PauliSum<config::indexmap::ByteFxHashF64<1>> = PauliSum::builder().n_qubits(2).build(); state += (“ZZ”, 1.0);

// Circuit: H(0); CNOT(0, 1) — apply in reverse for Heisenberg propagation. state.cnot(0, 1); state.h(0);

// ZZ → IZ under the GHZ circuit, with coefficient 1.0. assert_eq!(state.len(), 1); ```

source

methodauxsource

ppvm_pauli_sum::sum::PauliSum::aux

pub fn aux(&self) -> &<T as >::Map

Returns

&<T as >::Map

Reference to the auxiliary map — the scratch buffer gates write into.

source

methodaux_mutsource

ppvm_pauli_sum::sum::PauliSum::aux_mut

pub fn aux_mut(&mut self) -> &mut <T as >::Map

Returns

&mut <T as >::Map

Mutable reference to the auxiliary map.

source

methodbuildersource

ppvm_pauli_sum::sum::PauliSum::builder

pub fn builder() -> PauliSumBuilder<T>

Returns

PauliSumBuilder<T>

create a new empty PauliSum with given number of qubits.

One can optionally set

  • the strategy for truncation, initialization etc.
  • the capacity of the internal maps, default is strategy.capacity(n_qubits)
  • a set of `preserve_strings` that truncate must never drop, on top of whatever the strategy decides.
source

methodcapacitysource

ppvm_pauli_sum::sum::PauliSum::capacity

pub fn capacity(&self) -> usize

Returns

usize

Capacity (in entries) reserved in the underlying maps.

source

methodconsumesource

ppvm_pauli_sum::sum::PauliSum::consume

pub fn consume(&mut self)

combine entries with the same key in either data or aux. The combined entries are stored in `.data()`.

source

methodcontainssource

ppvm_pauli_sum::sum::PauliSum::contains

Signature
pub fn contains(&self, key: &<T as Config>::PauliWordType, value: &<T as >::Coeff) -> bool

Parameters

NameTypeDescription
key&amp;&lt;T as Config&gt;::PauliWordType
value&amp;&lt;T as &gt;::Coeff

Returns

bool

`true` if `(key, value)` is present in the primary map.

source

methoddatasource

ppvm_pauli_sum::sum::PauliSum::data

pub fn data(&self) -> &<T as >::Map

Returns

&<T as >::Map

Reference to the primary map — the one that currently holds the “active” entries.

source

methoddata_auxsource

ppvm_pauli_sum::sum::PauliSum::data_aux

pub fn data_aux(&self) -> (&<T as >::Map, &<T as >::Map)

Returns

(&<T as >::Map, &<T as >::Map)

Both maps as a `(primary, auxiliary)` tuple.

source

methoddata_aux_mutsource

ppvm_pauli_sum::sum::PauliSum::data_aux_mut

pub fn data_aux_mut(&mut self) -> (&mut <T as >::Map, &mut <T as >::Map)

Returns

(&mut <T as >::Map, &mut <T as >::Map)

Both maps mutably as a `(primary, auxiliary)` tuple.

source

methoddata_mutsource

ppvm_pauli_sum::sum::PauliSum::data_mut

pub fn data_mut(&mut self) -> &mut <T as >::Map

Returns

&mut <T as >::Map

Mutable reference to the primary map.

source

methodis_emptysource

ppvm_pauli_sum::sum::PauliSum::is_empty

pub fn is_empty(&self) -> bool

Returns

bool

`true` if the primary map has no entries.

source

methoditersource

ppvm_pauli_sum::sum::PauliSum::iter

pub fn iter(&'a self) -> <<T as Config>::Map as ACMapIter<'a>>::Iter

Returns

<<T as Config>::Map as ACMapIter<'a>>::Iter

Iterate over the primary map’s entries.

source

methodlensource

ppvm_pauli_sum::sum::PauliSum::len

pub fn len(&self) -> usize

Returns

usize

Number of entries in the primary map.

source

methodmap_addsource

ppvm_pauli_sum::sum::PauliSum::map_add

pub fn map_add<F>(&mut self, f: F)

Parameters

NameTypeDescription
fF

apply a function to each entry (k,v) and store the results in aux. finally, swap data and aux.

This assumes the function `f` returns a different Pauli string `k’` from the input `k`, otherwise use `scale` to modify coefficients in place of the same entry.

source

methodmap_insertsource

ppvm_pauli_sum::sum::PauliSum::map_insert

pub fn map_insert<F>(&mut self, f: F)

Parameters

NameTypeDescription
fF

modify in place existing entries and insert some new entries if `f` return Some((k,v)) for an existing entry (k0,v0), then the existing entry is modified by `f` and a new entry (k,v) is added. if `f` return None, then the existing entry is only modified. finally, all entries are combined assuming unique keys.

source

methodmap_insert_multiplesource

ppvm_pauli_sum::sum::PauliSum::map_insert_multiple

pub fn map_insert_multiple<F>(&mut self, f: F)

Parameters

NameTypeDescription
fF

modify in place existing entries and insert some new entries if `f` returns Some(Vec<(k,v)>) for an existing entry (k0,v0), then the existing entry is modified by `f` and new entries contained in the vector are added. If `f` returns None, then the existing entry is only modified. finally, all entries are combined assuming unique keys.

source

methodn_qubitssource

ppvm_pauli_sum::sum::PauliSum::n_qubits

pub fn n_qubits(&self) -> usize

Returns

usize

Number of qubits the sum is defined over.

source

methodoverlapsource

ppvm_pauli_sum::sum::PauliSum::overlap

pub fn overlap(&self, other: &Self) -> <T as >::Coeff

Parameters

NameTypeDescription
other&amp;Self

Returns

<T as >::Coeff

Inner-product-style overlap with another sum: `Σ_k self[k] · other[k]`.

source

methodpreserve_stringssource

ppvm_pauli_sum::sum::PauliSum::preserve_strings

pub fn preserve_strings(&self) -> &HashSet<<T as >::PauliWordType>

Returns

&HashSet<<T as >::PauliWordType>

Read-only access to the active preserve set.

source

methodscalesource

ppvm_pauli_sum::sum::PauliSum::scale

pub fn scale<F>(&mut self, f: F)

Parameters

NameTypeDescription
fF

scale all coefficients by a function of the corresponding PauliWord key.

source

methodswapsource

ppvm_pauli_sum::sum::PauliSum::swap

pub fn swap(&mut self)

Swap the primary and auxiliary maps without touching their contents.

source

methodtruncatesource

ppvm_pauli_sum::sum::PauliSum::truncate

pub fn truncate(&mut self)

Apply the configured truncation Strategy to the primary map, dropping entries that fall outside its policy.

If `preserve_strings` is non-empty, any of those Pauli strings that the strategy would have dropped are re-inserted afterwards with their pre-truncate coefficient. The mechanism composes with any Strategy (coefficient-magnitude, max-weight, combinations — anything) because the strategy runs unchanged in the middle.

source