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>) { ... }
fn finalizes_layer(&self) -> bool { ... }
fn finalize_layer_partitioned(
&self,
local: &mut PauliSum<W>,
collectives: &dyn Collectives,
) { ... }
fn supports_partitioned(&self) -> bool { ... }
}Expand description
A truncation strategy: a per-term filter, a per-layer pass, or both.
Built-ins: CoefficientThreshold and WeightCutoff filter terms, TopN, ApproxTopN and CollapseSample run a layer pass, And and Or compose, and BuiltinTruncation holds any of them as one value.
Above one partition every partition sees a disjoint slice of the layer, so a layer pass must be collective: a policy whose finalizes_layer() is true runs partitioned only if it overrides finalize_layer_partitioned and supports_partitioned.
Every built-in does except exact TopN, which is not yet supported partitioned; ApproxTopN is the partitioned alternative.
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
Per-term filter, run inside the merge on every output, so it must be cheap.
c is the coefficient summed over every contribution to the key (x, z).
Sourcefn finalize_layer(&self, _sum: &mut PauliSum<W>)
fn finalize_layer(&self, _sum: &mut PauliSum<W>)
Pass over the whole sum after each layer; PauliSum::retain is the easy way to write a filter here.
Sourcefn finalizes_layer(&self) -> bool
fn finalizes_layer(&self) -> bool
Whether finalize_layer does anything, a hint that lets the engine skip it.
Return false only if finalize_layer is a no-op: the engine may then skip it, which is a wrong answer otherwise.
Sourcefn finalize_layer_partitioned(
&self,
local: &mut PauliSum<W>,
collectives: &dyn Collectives,
)
fn finalize_layer_partitioned( &self, local: &mut PauliSum<W>, collectives: &dyn Collectives, )
The layer pass over one partition’s slice of the layer, run on every layer on every partition in lock-step.
The default runs finalize_layer at one partition and nothing above it.
An override must issue the same collective calls on every partition, never skipping one on a partition with nothing to do, and decide only from all-reduced values.
§Panics
Above one partition, if the policy reports finalizes_layer() and has not overridden this method.
Sourcefn supports_partitioned(&self) -> bool
fn supports_partitioned(&self) -> bool
Whether finalize_layer_partitioned runs above one partition; every partitioned driver checks it before the first layer.
The default is true exactly when there is no layer pass; a policy that overrides finalize_layer_partitioned with a collective pass returns true.