Skip to main content

ppvm_traits/traits/
strategy.rs

1// SPDX-FileCopyrightText: 2026 The PPVM Authors
2// SPDX-License-Identifier: Apache-2.0
3
4use super::coefficient::Coefficient;
5use super::map::ACMap;
6use super::storage::PauliStorage;
7use super::word_trait::PauliWordTrait;
8
9/// A truncation policy applied to a `PauliSum`
10/// during Pauli propagation.
11///
12/// The strategy controls two things: the *initial* capacity allocated
13/// for the underlying map (estimating how many Pauli paths the
14/// simulation is expected to generate) and the *cut* applied when
15/// [`truncate`](Self::truncate) is called explicitly. Implementations
16/// include [`NoStrategy`], the coefficient-magnitude threshold, the
17/// max-Pauli-weight bound, etc.
18pub trait Strategy: Default + Clone + Copy {
19    /// Given the number of qubits, predict the initial capacity of the map.
20    /// Ideally this is about guessing the maximum Pauli paths will be generated
21    /// during the computation, the more precise the better.
22    fn capacity(&self, n_qubits: usize) -> usize;
23    /// Drop entries from `map` that fall outside this strategy's policy.
24    fn truncate<S, V, H, M, W>(&self, map: &mut M)
25    where
26        S: PauliStorage,
27        V: Coefficient,
28        H: std::hash::BuildHasher + Clone + Default,
29        W: PauliWordTrait,
30        M: ACMap<S, V, H, W>;
31}
32
33/// Strategy that never truncates — exact simulation, all entries kept.
34#[derive(Debug, Clone, Default, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
35pub struct NoStrategy;
36
37impl Strategy for NoStrategy {
38    fn capacity(&self, n_qubits: usize) -> usize {
39        // in exact simulation, let's guess there will be 4^n / 2 = 2^(2n - 1) paths
40        1 << (2 * n_qubits - 1)
41    }
42
43    fn truncate<S, V, H, M, W>(&self, _map: &mut M)
44    where
45        S: PauliStorage,
46        V: Coefficient,
47        H: std::hash::BuildHasher + Clone + Default,
48        W: PauliWordTrait,
49        M: ACMap<S, V, H, W>,
50    {
51    }
52}