TruncationPolicy

Trait TruncationPolicy 

Source
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§

Source

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.

Source

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).

Implementors§

Source§

impl<const W: usize> TruncationPolicy<W> for CoefficientThreshold

Source§

impl<const W: usize> TruncationPolicy<W> for TopN

Source§

impl<const W: usize> TruncationPolicy<W> for WeightCutoff

Source§

impl<const W: usize, A, B> TruncationPolicy<W> for And<A, B>

Source§

impl<const W: usize, A, B> TruncationPolicy<W> for Or<A, B>