pub struct PauliSum<const W: usize> { /* private fields */ }Expand description
Weighted sum of Pauli strings, stored as structure-of-arrays columns partitioned into buckets by a GF(2)-linear hash.
Terms come in canonical order: bucket index ascending, then lexicographic (x, z) within a bucket, with no repeated key.
A sum of at most 1024 terms built by crate::BuildAccumulator has one bucket and so is plain lex-sorted; a larger one interleaves buckets, so compare sums by key (Self::get), not by position.
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, in a single bucket.
§Panics
Panics in debug builds if num_qubits > 64 · W.
Sourcepub fn num_qubits(&self) -> usize
pub fn num_qubits(&self) -> usize
Number of qubits this sum acts on.
Sourcepub fn num_buckets(&self) -> usize
pub fn num_buckets(&self) -> usize
Number of buckets, 1 << hash().bits().
Sourcepub fn iter(
&self,
) -> impl Iterator<Item = (&[u64; W], &[u64; W], Complex64)> + '_
pub fn iter( &self, ) -> impl Iterator<Item = (&[u64; W], &[u64; W], Complex64)> + '_
Iterate every term in canonical order, which is not globally key-sorted.
Sourcepub fn to_arrays(&self) -> (Vec<[u64; W]>, Vec<[u64; W]>, Vec<Complex64>)
pub fn to_arrays(&self) -> (Vec<[u64; W]>, Vec<[u64; W]>, Vec<Complex64>)
Copy every term out as three parallel columns, in canonical order.
Sourcepub fn get(&self, x: &[u64; W], z: &[u64; W]) -> Option<Complex64>
pub fn get(&self, x: &[u64; W], z: &[u64; W]) -> Option<Complex64>
Coefficient of the term with key (x, z), or None if absent.
Sourcepub fn identity_coefficient(&self) -> Complex64
pub fn identity_coefficient(&self) -> Complex64
Coefficient of the identity term, i.e. tr(O) / 2^n.
Sourcepub fn retain(
&mut self,
f: impl Fn(&[u64; W], &[u64; W], Complex64) -> bool + Sync,
)
pub fn retain( &mut self, f: impl Fn(&[u64; W], &[u64; W], Complex64) -> bool + Sync, )
Keep only the terms for which f(x, z, coeff) is true; f may run on several threads at once.
Source§impl<const W: usize> PauliSum<W>
impl<const W: usize> PauliSum<W>
Sourcepub fn expectation_product(&self, basis: &ProductBasis<W>) -> Complex64
pub fn expectation_product(&self, basis: &ProductBasis<W>) -> Complex64
Expectation value ⟨ψ|O|ψ⟩ in the product state basis; complex since O need not be Hermitian.
Source§impl<const W: usize> PauliSum<W>
impl<const W: usize> PauliSum<W>
Sourcepub fn expectation_stabilizer(&self, state: &StabilizerState<W>) -> Complex64
pub fn expectation_stabilizer(&self, state: &StabilizerState<W>) -> Complex64
Expectation value ⟨ψ|O|ψ⟩ in a stabilizer state; complex since O need not be Hermitian.
§Panics
Panics if state.num_qubits() differs from Self::num_qubits.
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
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>
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>
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