PauliSum

Struct PauliSum 

Source
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>

Source

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.

Source

pub fn clear(&mut self)

Drop every term, keeping the hash and the bucket storage.

Source

pub fn len(&self) -> usize

Total number of terms.

Source

pub fn is_empty(&self) -> bool

true if the sum has no terms.

Source

pub fn num_qubits(&self) -> usize

Number of qubits this sum acts on.

Source

pub fn num_buckets(&self) -> usize

Number of buckets, 1 << hash().bits().

Source

pub fn hash(&self) -> &Gf2Hash<W>

The partitioning hash.

Source

pub fn iter( &self, ) -> impl Iterator<Item = (&[u64; W], &[u64; W], Complex64)> + '_

Iterate every term in canonical order, which is not globally key-sorted.

Source

pub fn to_arrays(&self) -> (Vec<[u64; W]>, Vec<[u64; W]>, Vec<Complex64>)

Copy every term out as three parallel columns, in canonical order.

Source

pub fn get(&self, x: &[u64; W], z: &[u64; W]) -> Option<Complex64>

Coefficient of the term with key (x, z), or None if absent.

Source

pub fn identity_coefficient(&self) -> Complex64

Coefficient of the identity term, i.e. tr(O) / 2^n.

Source

pub fn scale(&mut self, c: Complex64)

Multiply every coefficient by c in place.

Source

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

pub fn overlap(&self, other: &Self) -> Complex64

Hilbert-Schmidt overlap tr(self† · other) / 2ⁿ, i.e. Σ conj(aᵢ)·bᵢ over the keys the two sums share.

§Panics

Panics if the two sums disagree about num_qubits.

Source

pub fn add(&self, other: &Self) -> Self

Sum of two sums, partitioned as self; terms summing to exactly zero are dropped.

§Panics

Panics if the two sums disagree about num_qubits.

Source§

impl<const W: usize> PauliSum<W>

Source

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>

Source

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§

Source§

impl<const W: usize> Clone for PauliSum<W>

Source§

fn clone(&self) -> PauliSum<W>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<const W: usize> Debug for PauliSum<W>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,