ppvm_pauli_sum::prelude
prelude¶
ppvm_pauli_sum::prelude
Drop-in replacement for the old `ppvm_runtime::prelude`.
classPauliSum¶source
ppvm_pauli_sum::prelude::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.
Examples
Section titled “Examples”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); ```
sourcemethodaux¶source
ppvm_pauli_sum::prelude::PauliSum::aux
pub fn aux(&self) -> &<T as >::MapReturns
&<T as >::Map
Reference to the auxiliary map — the scratch buffer gates write into.
sourcemethodaux_mut¶source
ppvm_pauli_sum::prelude::PauliSum::aux_mut
pub fn aux_mut(&mut self) -> &mut <T as >::MapReturns
&mut <T as >::Map
Mutable reference to the auxiliary map.
sourcemethodbuilder¶source
ppvm_pauli_sum::prelude::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.
methodcapacity¶source
ppvm_pauli_sum::prelude::PauliSum::capacity
pub fn capacity(&self) -> usizeReturns
usize
Capacity (in entries) reserved in the underlying maps.
sourcemethodconsume¶source
ppvm_pauli_sum::prelude::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()`.
sourcemethodcontains¶source
ppvm_pauli_sum::prelude::PauliSum::contains
Signature
pub fn contains(&self, key: &<T as Config>::PauliWordType, value: &<T as >::Coeff) -> boolParameters
| Name | Type | Description |
|---|---|---|
key | &<T as Config>::PauliWordType | |
value | &<T as >::Coeff |
Returns
bool
`true` if `(key, value)` is present in the primary map.
sourcemethoddata¶source
ppvm_pauli_sum::prelude::PauliSum::data
pub fn data(&self) -> &<T as >::MapReturns
&<T as >::Map
Reference to the primary map — the one that currently holds the “active” entries.
sourcemethoddata_aux¶source
ppvm_pauli_sum::prelude::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.
sourcemethoddata_aux_mut¶source
ppvm_pauli_sum::prelude::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.
sourcemethoddata_mut¶source
ppvm_pauli_sum::prelude::PauliSum::data_mut
pub fn data_mut(&mut self) -> &mut <T as >::MapReturns
&mut <T as >::Map
Mutable reference to the primary map.
sourcemethodis_empty¶source
ppvm_pauli_sum::prelude::PauliSum::is_empty
methoditer¶source
ppvm_pauli_sum::prelude::PauliSum::iter
pub fn iter(&'a self) -> <<T as Config>::Map as ACMapIter<'a>>::IterReturns
<<T as Config>::Map as ACMapIter<'a>>::Iter
Iterate over the primary map’s entries.
sourcemethodlen¶source
ppvm_pauli_sum::prelude::PauliSum::len
methodmap_add¶source
ppvm_pauli_sum::prelude::PauliSum::map_add
pub fn map_add<F>(&mut self, f: F)Parameters
| Name | Type | Description |
|---|---|---|
f | F |
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.
sourcemethodmap_insert¶source
ppvm_pauli_sum::prelude::PauliSum::map_insert
pub fn map_insert<F>(&mut self, f: F)Parameters
| Name | Type | Description |
|---|---|---|
f | F |
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.
sourcemethodmap_insert_multiple¶source
ppvm_pauli_sum::prelude::PauliSum::map_insert_multiple
pub fn map_insert_multiple<F>(&mut self, f: F)Parameters
| Name | Type | Description |
|---|---|---|
f | F |
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.
sourcemethodn_qubits¶source
ppvm_pauli_sum::prelude::PauliSum::n_qubits
methodoverlap¶source
ppvm_pauli_sum::prelude::PauliSum::overlap
pub fn overlap(&self, other: &Self) -> <T as >::CoeffParameters
| Name | Type | Description |
|---|---|---|
other | &Self |
Returns
<T as >::Coeff
Inner-product-style overlap with another sum: `Σ_k self[k] · other[k]`.
sourcemethodpreserve_strings¶source
ppvm_pauli_sum::prelude::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.
sourcemethodscale¶source
ppvm_pauli_sum::prelude::PauliSum::scale
pub fn scale<F>(&mut self, f: F)Parameters
| Name | Type | Description |
|---|---|---|
f | F |
scale all coefficients by a function of the corresponding PauliWord key.
sourcemethodswap¶source
ppvm_pauli_sum::prelude::PauliSum::swap
methodtruncate¶source
ppvm_pauli_sum::prelude::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