Expand description
TruncationPolicy<W> — composable per-term and per-layer term filters.
The split between TruncationPolicy::keep_term (hot, per-output, must
inline) and TruncationPolicy::finalize_layer (cold, once per layer,
may be non-local) is performance-critical: keep_term runs millions of
times per layer, finalize_layer runs once.
Both methods have default no-op implementations, so a policy only needs
to override the one it uses. Compose two policies with And (both must
accept) or Or (either accepts).
Built-ins: CoefficientThreshold drops terms below a magnitude;
WeightCutoff drops terms above a Pauli weight; TopN keeps the n
largest-magnitude terms via a layer-finalization partial sort.
See design doc §7.
§Examples
use paulistrings::truncation::{And, CoefficientThreshold, WeightCutoff};
use paulistrings::TruncationPolicy;
use num_complex::Complex64;
// Keep terms with |coeff| > 1e-9 AND weight ≤ 4.
let policy = And(CoefficientThreshold(1e-9), WeightCutoff(4));
// A weight-1 term with coeff 0.5: passes both.
assert!(<_ as TruncationPolicy<1>>::keep_term(
&policy, &[1], &[0], Complex64::new(0.5, 0.0),
));Re-exports§
pub use builtin::And;pub use builtin::CoefficientThreshold;pub use builtin::Or;pub use builtin::TopN;pub use builtin::WeightCutoff;
Modules§
- builtin
- Built-in truncation policies and combinators. See design doc §7.
Traits§
- Truncation
Policy - A truncation strategy. Both methods have sensible defaults so users only implement the one they need.