pub struct PauliObservable { /* private fields */ }Expand description
Weighted sum of joint Pauli observables, H = sum_k c_k P_k.
Terms are kept canonical: factors sorted by qubit, identical Pauli strings merged by summing coefficients, terms ordered by string. An empty factor list is the identity and contributes its coefficient as a constant offset. The qubit-wise-commuting grouping the grouped evaluation route uses is computed lazily and cached; mutation invalidates the cache.
Implementations§
Source§impl PauliObservable
impl PauliObservable
pub fn new() -> Self
Sourcepub fn from_terms(
terms: impl IntoIterator<Item = (f64, Vec<PauliTerm>)>,
) -> Result<Self>
pub fn from_terms( terms: impl IntoIterator<Item = (f64, Vec<PauliTerm>)>, ) -> Result<Self>
Build from (coefficient, factors) pairs, the Hamiltonian shape
Simulate::expectation_gradient takes.
Sourcepub fn add_term(
&mut self,
coefficient: f64,
factors: Vec<PauliTerm>,
) -> Result<()>
pub fn add_term( &mut self, coefficient: f64, factors: Vec<PauliTerm>, ) -> Result<()>
Add coefficient times the Pauli string factors, merging into an
existing term with the same string.
§Errors
Rejects a non-finite coefficient and duplicate factors on one qubit.
Sourcepub fn terms(&self) -> &[(f64, Vec<PauliTerm>)]
pub fn terms(&self) -> &[(f64, Vec<PauliTerm>)]
Canonical (coefficient, factors) pairs, ordered by Pauli string.
pub fn num_terms(&self) -> usize
Sourcepub fn num_groups(&self) -> usize
pub fn num_groups(&self) -> usize
Number of qubit-wise-commuting groups, computing the grouping if needed. Identity terms belong to no group.
Sourcepub fn split_identity(&self) -> (f64, PauliObservable)
pub fn split_identity(&self) -> (f64, PauliObservable)
The constant term’s coefficient and the rest of the sum.
Var(H + cI) = Var(H), so a variance squares the traceless part rather
than the whole sum: at a large c the constant dominates both <H^2>
and <H>^2 and the difference loses the spread it was meant to report.
Sourcepub fn square(&self) -> PauliObservable
pub fn square(&self) -> PauliObservable
H^2 as a Pauli sum, the second moment Simulate::observable_variance
reads Var(H) = <H^2> - <H>^2 from.
Every coefficient of the square is real. Two Pauli strings either
commute, and their product carries no phase, or anticommute, and the
(j, k) and (k, j) products carry opposite imaginary phases that
cancel. Phases are tracked as powers of i so that cancellation is
exact rather than a subtraction of two nearly equal floats.
Costs T^2 string products over T terms, so it suits the tensor
products and small Hermitian matrices an observable request names
rather than a molecular Hamiltonian.
Trait Implementations§
Source§impl Add for PauliObservable
impl Add for PauliObservable
Source§type Output = PauliObservable
type Output = PauliObservable
+ operator.Source§fn add(self, rhs: PauliObservable) -> PauliObservable
fn add(self, rhs: PauliObservable) -> PauliObservable
+ operation. Read moreSource§impl Clone for PauliObservable
impl Clone for PauliObservable
Source§fn clone(&self) -> PauliObservable
fn clone(&self) -> PauliObservable
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for PauliObservable
impl Debug for PauliObservable
Source§impl Default for PauliObservable
impl Default for PauliObservable
Source§fn default() -> PauliObservable
fn default() -> PauliObservable
Source§impl Mul<f64> for PauliObservable
impl Mul<f64> for PauliObservable
Source§type Output = PauliObservable
type Output = PauliObservable
* operator.Source§impl Neg for PauliObservable
impl Neg for PauliObservable
Source§type Output = PauliObservable
type Output = PauliObservable
- operator.Source§fn neg(self) -> PauliObservable
fn neg(self) -> PauliObservable
- operation. Read moreSource§impl Sub for PauliObservable
impl Sub for PauliObservable
Source§type Output = PauliObservable
type Output = PauliObservable
- operator.Source§fn sub(self, rhs: PauliObservable) -> PauliObservable
fn sub(self, rhs: PauliObservable) -> PauliObservable
- operation. Read moreAuto Trait Implementations§
impl !Freeze for PauliObservable
impl RefUnwindSafe for PauliObservable
impl Send for PauliObservable
impl Sync for PauliObservable
impl Unpin for PauliObservable
impl UnsafeUnpin for PauliObservable
impl UnwindSafe for PauliObservable
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T, U> Imply<T> for U
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