pub struct SumOp {
pub terms: Vec<PauliString>,
}Expand description
A vector of Pauli strings that are summed together. Useful for representing Hamiltonians or observables.
§Fields
terms- A vector ofPauliStringinstances that are summed together.
Fields§
§terms: Vec<PauliString>A vector of Pauli strings that are summed together.
Implementations§
Source§impl SumOp
impl SumOp
Sourcepub fn new(terms: Vec<PauliString>) -> Self
pub fn new(terms: Vec<PauliString>) -> Self
Sourcepub fn add_term(&mut self, term: PauliString)
pub fn add_term(&mut self, term: PauliString)
Sourcepub fn with_term(self, term: PauliString) -> Self
pub fn with_term(self, term: PauliString) -> Self
Sourcepub fn apply(&self, state: &State) -> Result<State, Error>
pub fn apply(&self, state: &State) -> Result<State, Error>
Applies the sum of Pauli strings to a given state.
§Arguments
state- The state to which the sum of Pauli strings is applied.
§Returns
Result<State, Error>- The resulting state after applying the sum of Pauli strings, or an error if the operation fails.
§Errors
- Returns an error if the operations in the Pauli strings refer to qubits outside the range of the state.
Sourcepub fn expectation_value(&self, state: &State) -> Result<Complex<f64>, Error>
pub fn expectation_value(&self, state: &State) -> Result<Complex<f64>, Error>
Calculates the expectation value <psi|H|psi> = Sum_i <psi|P_i|psi>.
The expectation value is generally real for Hermitian operators and normalised states.
However, this function returns a Complex<f64> as intermediate PauliStrings
might have complex coefficients or the operator/state might not be strictly physical.
§Arguments
state- The state |psi> for which to calculate the expectation value. For a physically meaningful expectation value, this state should be normalised.
§Returns
Result<Complex<f64>, Error>- The expectation value, or an error if the operation fails.
§Errors
- Returns an error if any underlying
PauliString::applyfails (eg., invalid qubit index). - Returns an error if
state.inner_productfails (eg., mismatched number of qubits, thoughPauliString::applyshould also catch qubit count issues).
Trait Implementations§
Source§impl Add<PauliString> for SumOp
impl Add<PauliString> for SumOp
impl StructuralPartialEq for SumOp
Auto Trait Implementations§
impl Freeze for SumOp
impl RefUnwindSafe for SumOp
impl Send for SumOp
impl Sync for SumOp
impl Unpin for SumOp
impl UnwindSafe for SumOp
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