pub trait TruncationPolicy<const W: usize>: Send + Sync {
// Provided methods
fn keep_term(&self, _x: &[u64; W], _z: &[u64; W], _c: Complex64) -> bool { ... }
fn finalize_layer(&self, _sum: &mut PauliSum<W>) { ... }
}Expand description
A truncation strategy. Both methods have sensible defaults so users only implement the one they need.
§Implementing
Override keep_term for per-output decisions (runs
inside the merge phase, must inline). Override
finalize_layer for global decisions that
depend on the whole layer’s output (e.g. partial sort for selecting the
top n terms).
use paulistrings::TruncationPolicy;
use num_complex::Complex64;
/// Drop the imaginary half: keep only terms whose coefficient is real.
struct RealOnly;
impl<const W: usize> TruncationPolicy<W> for RealOnly {
#[inline]
fn keep_term(&self, _x: &[u64; W], _z: &[u64; W], c: Complex64) -> bool {
c.im == 0.0
}
}Provided Methods§
Sourcefn keep_term(&self, _x: &[u64; W], _z: &[u64; W], _c: Complex64) -> bool
fn keep_term(&self, _x: &[u64; W], _z: &[u64; W], _c: Complex64) -> bool
Cheap per-term filter applied during the merge phase. Must inline.
c is the summed coefficient at the key (x, z) — i.e.
keep_term runs after all scratch entries with this key have been
reduced, not on individual scratch entries.
Sourcefn finalize_layer(&self, _sum: &mut PauliSum<W>)
fn finalize_layer(&self, _sum: &mut PauliSum<W>)
Optional global pass after each circuit layer. May be non-local
(e.g. partial sort for TopN).