pub struct PauliString { /* private fields */ }Expand description
Represents a Pauli string, which is a product of Pauli operators (X, Y, Z) acting on qubits. Used to represent a term in a Hamiltonian or a quantum operator.
Implementations§
Source§impl PauliString
impl PauliString
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the length of the Pauli string, defined as the number of operators it contains.
§Returns
usize- The number of operators in the Pauli string.
Sourcepub fn with_ops(coefficient: Complex<f64>, ops: HashMap<usize, Pauli>) -> Self
pub fn with_ops(coefficient: Complex<f64>, ops: HashMap<usize, Pauli>) -> Self
Creates a new Pauli string with the given coefficient and a set of operators.
§Arguments
coefficient- The coefficient of the Pauli string, represented as a complex number.ops- A mapping from qubit indices to Pauli operators.
§Returns
A new PauliString instance with the specified coefficient and operators.
Note that the Hashmap ensures uniqueness of operators for each qubit.
Sourcepub fn with_op(self, qubit: usize, op: Pauli) -> Self
pub fn with_op(self, qubit: usize, op: Pauli) -> Self
Adds a Pauli operator to the Pauli string at the specified qubit index and returns the new PauliString instance.
§Arguments
qubit- The index of the qubit to which the operator is applied.op- The Pauli operator to be added (X, Y, or Z).
§Returns
Self- A newPauliStringinstance with the added operator.
§Panics
This function will panic if an operator for the same qubit index is added more than once.
Sourcepub fn coefficient(&self) -> Complex<f64>
pub fn coefficient(&self) -> Complex<f64>
Returns the coefficient of the Pauli string.
§Returns
Complex<f64>- The coefficient of the Pauli string, represented as a complex number.
Sourcepub fn ops(&self) -> &HashMap<usize, Pauli>
pub fn ops(&self) -> &HashMap<usize, Pauli>
Returns a reference to the operators in the Pauli string.
§Returns
&HashMap<usize, Pauli>- A reference to the mapping of qubit indices to Pauli operators.
Sourcepub fn get_targets(&self) -> Vec<usize>
pub fn get_targets(&self) -> Vec<usize>
Returns the list of targets of the Pauli string
§Returns
Vec<usize>- A vector of qubit indices that the Pauli string acts upon.
Sourcepub fn to_gates(&self) -> Vec<Gate>
pub fn to_gates(&self) -> Vec<Gate>
Converts the Pauli string to a vector of operator gates.
§Returns
Vec<Gate>- A vector of Gate structs representing the individual Pauli operators.
Sourcepub fn apply(&self, state: &State) -> Result<State, Error>
pub fn apply(&self, state: &State) -> Result<State, Error>
Applies the Pauli string to a given state.
§Arguments
state- The state to which the Pauli string is applied.
§Returns
Result<State, Error>- The resulting state after applying the Pauli string, or an error if the operation fails.
§Errors
- Returns an error if the operations in the Pauli string refer to qubits outside the range of the state.
Sourcepub fn apply_normalised(&self, state: &State) -> Result<State, Error>
pub fn apply_normalised(&self, state: &State) -> Result<State, Error>
Applies the Pauli string to a given state and normalises the new state.
§Arguments
state- The state to which the Pauli string is applied.
§Returns
Result<State, Error>- The resulting state after applying the Pauli string, or an error if the operation fails.
§Errors
- Returns an error if the operations in the Pauli string refer to qubits outside the range of the state.
- Returns an error if the resulting state cannot be normalised (eg., has zero norm).
Sourcepub fn apply_exp(&self, state: &State) -> Result<State, Error>
pub fn apply_exp(&self, state: &State) -> Result<State, Error>
Applies the exponential of the Pauli string to a given state.
§Arguments
state- The state to which the exponential of the Pauli string is applied.
§Returns
Result<State, Error>- The resulting state after applying the exponential of the Pauli string, or an error if the operation fails.
§Errors
- Returns an error if the operations in the Pauli string refer to qubits outside the range of the state.
Sourcepub fn apply_exp_factor(
&self,
state: &State,
factor: Complex<f64>,
) -> Result<State, Error>
pub fn apply_exp_factor( &self, state: &State, factor: Complex<f64>, ) -> Result<State, Error>
Applies the exponential of the Pauli string to a given state with a specified factor.
§Arguments
state- The state to which the exponential of the Pauli string is applied.factor- A complex factor to be multiplied with the coefficient of the Pauli string.
§Returns
Result<State, Error>- The resulting state after applying the exponential of the Pauli string with the factor, or an error if the operation fails.
§Errors
- Returns an error if the operations in the Pauli string refer to qubits outside the range of the state.
Sourcepub fn apply_exp_neg_i_dt(&self, state: &State, dt: f64) -> Result<State, Error>
pub fn apply_exp_neg_i_dt(&self, state: &State, dt: f64) -> Result<State, Error>
Applies the exponential of the Pauli string to the given state with a negative imaginary factor. Represents a time evolution step of the form exp(-i * coefficient * P_ops * dt). Guaranteed to return a normalised state if the input state is normalised.
§Arguments
state- The state to which the exponential of the Pauli string is applied.dt- The time step for the evolution.
§Returns
Result<State, Error>- The resulting state after applying the exponential of the Pauli string with the negative imaginary factor, or an error if the operation fails.
§Errors
- Returns an error if the operations in the Pauli string refer to qubits outside the range of the state.
- Returns an error if the coefficient for the Pauli string has an imaginary component.
Sourcepub fn hermitian_conjugate(&self) -> Self
pub fn hermitian_conjugate(&self) -> Self
Returns the Hermitian conjugate of the Pauli string.
§Returns
Self- A newPauliStringinstance representing the Hermitian conjugate of the original Pauli string.
Trait Implementations§
Source§impl Add<PauliString> for SumOp
impl Add<PauliString> for SumOp
Source§impl Add for PauliString
impl Add for PauliString
Source§impl Clone for PauliString
impl Clone for PauliString
Source§fn clone(&self) -> PauliString
fn clone(&self) -> PauliString
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for PauliString
impl Debug for PauliString
Source§impl Display for PauliString
impl Display for PauliString
Source§impl Mul<PauliString> for f64
impl Mul<PauliString> for f64
Source§type Output = PauliString
type Output = PauliString
* operator.Source§impl Mul<f64> for PauliString
impl Mul<f64> for PauliString
Source§impl PartialEq for PauliString
impl PartialEq for PauliString
impl StructuralPartialEq for PauliString
Auto Trait Implementations§
impl Freeze for PauliString
impl RefUnwindSafe for PauliString
impl Send for PauliString
impl Sync for PauliString
impl Unpin for PauliString
impl UnwindSafe for PauliString
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