pub struct PauliSum<const W: usize> { /* private fields */ }Expand description
Weighted sum of Pauli operators, stored SoA, sorted and deduplicated.
Implementations§
Source§impl<const W: usize> PauliSum<W>
impl<const W: usize> PauliSum<W>
Sourcepub fn empty(num_qubits: usize) -> Self
pub fn empty(num_qubits: usize) -> Self
Empty sum on num_qubits qubits.
§Panics
Panics in debug builds if num_qubits > 64 · W. Caller is responsible
for ensuring num_qubits <= 64 · W.
Sourcepub fn num_qubits(&self) -> usize
pub fn num_qubits(&self) -> usize
Number of qubits this sum is defined over.
Sourcepub fn add(&self, other: &Self) -> Self
pub fn add(&self, other: &Self) -> Self
Sum of two PauliSums. Linear-time merge; preserves the sorted
invariant. Terms whose coefficients sum to exactly 0+0i are dropped.
§Examples
Disjoint keys interleave in sort order; equal keys sum, and an exact-zero combined coefficient drops the term.
use paulistrings::{BuildAccumulator, PauliString, Phase};
use num_complex::Complex64;
let mut a = BuildAccumulator::<1>::new(2);
a.add_term(PauliString::<1>::z(0), Phase::ONE, Complex64::new(1.0, 0.0));
a.add_term(PauliString::<1>::x(1), Phase::ONE, Complex64::new(0.5, 0.0));
let a = a.finalize();
let mut b = BuildAccumulator::<1>::new(2);
b.add_term(PauliString::<1>::z(0), Phase::ONE, Complex64::new(-1.0, 0.0));
let b = b.finalize();
// Z₀ cancels exactly; only X₁ survives.
let r = a.add(&b);
assert_eq!(r.len(), 1);
assert_eq!(r.coeff()[0], Complex64::new(0.5, 0.0));Sourcepub fn find(&self, x: &[u64; W], z: &[u64; W]) -> Result<usize, usize>
pub fn find(&self, x: &[u64; W], z: &[u64; W]) -> Result<usize, usize>
Locate a Pauli key by binary search; returns Ok(idx) if present,
Err(idx) for the insertion point otherwise.
Sourcepub fn truncate_by_magnitude(&mut self, eps: f64)
pub fn truncate_by_magnitude(&mut self, eps: f64)
Drop terms whose coefficient magnitude is <= eps. Preserves sort.
Sourcepub fn assert_invariants(&self)
pub fn assert_invariants(&self)
Debug-only invariant check. No-op in release builds.
Trait Implementations§
Auto Trait Implementations§
impl<const W: usize> Freeze for PauliSum<W>
impl<const W: usize> RefUnwindSafe for PauliSum<W>
impl<const W: usize> Send for PauliSum<W>
impl<const W: usize> Sync for PauliSum<W>
impl<const W: usize> Unpin for PauliSum<W>
impl<const W: usize> UnwindSafe for PauliSum<W>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more