PauliString

Struct PauliString 

Source
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

Source

pub fn new(coefficient: Complex<f64>) -> Self

Creates a new Pauli string with the given coefficient and an empty set of operators.

§Arguments
  • coefficient - The coefficient of the Pauli string, represented as a complex number.
§Returns

A new PauliString instance with the specified coefficient and no operators.

Source

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

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.

Source

pub fn add_op(&mut self, qubit: usize, op: Pauli)

Adds a Pauli operator to the Pauli string at the specified qubit index.

§Arguments
  • qubit - The index of the qubit to which the operator is applied.
  • op - The Pauli operator to be added (X, Y, or Z).
§Panics

This function will panic if an operator for the same qubit index is added more than once.

Source

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 new PauliString instance with the added operator.
§Panics

This function will panic if an operator for the same qubit index is added more than once.

Source

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

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

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

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

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

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

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

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

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

pub fn hermitian_conjugate(&self) -> Self

Returns the Hermitian conjugate of the Pauli string.

§Returns
  • Self - A new PauliString instance representing the Hermitian conjugate of the original Pauli string.

Trait Implementations§

Source§

impl Add<PauliString> for SumOp

Source§

type Output = SumOp

The resulting type after applying the + operator.
Source§

fn add(self, other: PauliString) -> Self::Output

Performs the + operation. Read more
Source§

impl Add for PauliString

Source§

type Output = SumOp

The resulting type after applying the + operator.
Source§

fn add(self, other: Self) -> Self::Output

Performs the + operation. Read more
Source§

impl Clone for PauliString

Source§

fn clone(&self) -> PauliString

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 Debug for PauliString

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Display for PauliString

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Mul<Complex<f64>> for PauliString

Source§

type Output = PauliString

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Complex<f64>) -> Self::Output

Performs the * operation. Read more
Source§

impl Mul<PauliString> for f64

Source§

type Output = PauliString

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: PauliString) -> Self::Output

Performs the * operation. Read more
Source§

impl Mul<f64> for PauliString

Source§

type Output = PauliString

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: f64) -> Self::Output

Performs the * operation. Read more
Source§

impl PartialEq for PauliString

Source§

fn eq(&self, other: &PauliString) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for PauliString

Auto Trait Implementations§

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> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

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

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

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

Initializes a with the given initializer. Read more
Source§

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

Dereferences the given pointer. Read more
Source§

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

Mutably dereferences the given pointer. Read more
Source§

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V