Struct pauli::PauliOperator[][src]

pub struct PauliOperator { /* fields omitted */ }
Expand description

A Pauli operator optimized for sparse operations.

A Pauli operator is a string of Paulis such as IXIX or XIYIZ. However, we usually only care about the non-identity positions and we refer to the previous as operators as X_1 X_3 and X_0 Y_2 Z_4.

Implementations

impl PauliOperator[src]

pub fn new(length: usize, positions: Vec<usize>, paulis: Vec<Pauli>) -> Self[src]

Builds a new Pauli Operator.

To build an operator, we specify the length, the position of non-identity elements and their values.

Exemple

This creates the XIYIZ operator.

let operator = PauliOperator::new(5, vec![0, 2, 4], vec![X, Y, Z]);

Panic

Panics if a position is greater or equal to the length or if the number of positions and Paulis are different.

pub fn try_new(
    length: usize,
    positions: Vec<usize>,
    paulis: Vec<Pauli>
) -> Result<Self, PauliError>
[src]

Builds a new Pauli Operator or returns an error if either a position is greater or equal to the length or if the numbers of positions and Paulis are different.

Exemple

This creates the XIYIZ operator.

let operator = PauliOperator::try_new(5, vec![0, 2, 4], vec![X, Y, Z]);
assert!(operator.is_ok());

pub fn empty() -> Self[src]

Creates a Pauli operator of zero length.

pub fn commutes_with(&self, other: &Self) -> bool[src]

Checks if two operators commute.

If an operator is smaller than the other, it is padded with identities.

Example

let op1 = PauliOperator::new(5, vec![1, 2, 3], vec![X, Y, Z]);
let op2 = PauliOperator::new(5, vec![2, 3, 4], vec![X, X, X]);
let op3 = PauliOperator::new(5, vec![0, 1], vec![Z, Z]);

assert!(op1.commutes_with(&op2));
assert!(!op1.commutes_with(&op3));

pub fn anticommutes_with(&self, other: &Self) -> bool[src]

Checks if two operators anticommute.

If an operator is smaller than the other, it is padded with identities.

Example

let op1 = PauliOperator::new(5, vec![1, 2, 3], vec![X, Y, Z]);
let op2 = PauliOperator::new(5, vec![2, 3, 4], vec![X, X, X]);
let op3 = PauliOperator::new(5, vec![0, 1], vec![Z, Z]);

assert!(!op1.anticommutes_with(&op2));
assert!(op1.anticommutes_with(&op3));

pub fn iter(&self) -> VectorIterator<'_, Pauli, usize>[src]

Returns an iterator over pairs of positions and Paulis.

Example

let operator = PauliOperator::new(5, vec![0, 2, 4], vec![X, Y, Z]);
let mut iter = operator.iter();

assert_eq!(iter.next(), Some((0, &X)));
assert_eq!(iter.next(), Some((2, &Y)));
assert_eq!(iter.next(), Some((4, &Z)));
assert_eq!(iter.next(), None);

pub fn get(&self, position: usize) -> Option<Pauli>[src]

Returns the Pauli at the given position or None if the position is out of bound.

Example

let operator = PauliOperator::new(5, vec![0, 2, 4], vec![X, Y, Z]);

assert_eq!(operator.get(0), Some(X));
assert_eq!(operator.get(1), Some(I));
assert_eq!(operator.get(2), Some(Y));
assert_eq!(operator.get(10), None);

pub fn len(&self) -> usize[src]

Returns the length of the operator.

pub fn weight(&self) -> usize[src]

Returns the number of non identity elements.

pub fn non_trivial_positions(&self) -> &[usize][src]

Returns a slice of the positions where the element is not identity.

Example

let operator = PauliOperator::new(5, vec![0, 2, 4], vec![X, Y, Z]);

assert_eq!(operator.non_trivial_positions(), &[0, 2, 4]);

pub fn partition_x_and_z(&self) -> (Self, Self)[src]

Returns two operators such that there product is the original operator and the first contains only Xs and the second only Zs.

Example

let operator = PauliOperator::new(5, vec![0, 2, 4], vec![X, Y, Z]);
let (x_operator, z_operator) = operator.partition_x_and_z();

assert_eq!(x_operator, PauliOperator::new(5, vec![0, 2], vec![X, X]));
assert_eq!(z_operator, PauliOperator::new(5, vec![2, 4], vec![Z, Z]));

pub fn x_part(&self) -> Self[src]

Returns the X part of the operator.

Example

let operator = PauliOperator::new(5, vec![0, 2, 4], vec![X, Y, Z]);
let x_operator = operator.x_part();

assert_eq!(x_operator, PauliOperator::new(5, vec![0, 2], vec![X, X]));

pub fn z_part(&self) -> Self[src]

Returns the Z part of the operator.

Example

let operator = PauliOperator::new(5, vec![0, 2, 4], vec![X, Y, Z]);
let z_operator = operator.z_part();

assert_eq!(z_operator, PauliOperator::new(5, vec![2, 4], vec![Z, Z]));

pub fn multiply_with(&self, other: &Self) -> Result<Self, PauliError>[src]

Returns the element-wise product of two operators or an Error if they have different lengths.

For a panicking version, use the * operator.

Example

let op1 = PauliOperator::new(5, vec![1, 2, 3], vec![X, Y, Z]);
let op2 = PauliOperator::new(5, vec![2, 3, 4], vec![Y, X, Z]);

let product = PauliOperator::new(5, vec![1, 3, 4], vec![X, Y, Z]);

assert_eq!(op1.multiply_with(&op2), Ok(product))

pub fn into_raw_positions(self) -> Vec<usize>[src]

Converts a PauliOperator to a Vec of its non trivial positions consumming the operator.

Example

let operator = PauliOperator::new(5, vec![1, 2, 3], vec![X, Y, Z]);
let positions = operator.into_raw_positions();
assert_eq!(positions, vec![1, 2, 3]);

pub fn into_raw_paulis(self) -> Vec<Pauli>[src]

Converts a PauliOperator to a Vec of the Paulis consumming the operator.

Example

let operator = PauliOperator::new(5, vec![1, 2, 3], vec![X, Y, Z]);
let paulis = operator.into_raw_paulis();
assert_eq!(paulis, vec![X, Y, Z]);

pub fn into_raw(self) -> (Vec<usize>, Vec<Pauli>)[src]

Converts a PauliOperator to a Vec of the positions and a Vec of Paulis consumming the operator.

Example

let operator = PauliOperator::new(5, vec![1, 2, 3], vec![X, Y, Z]);
let (positions, paulis) = operator.into_raw();
assert_eq!(positions, vec![1, 2, 3]);
assert_eq!(paulis, vec![X, Y, Z]);

Trait Implementations

impl Clone for PauliOperator[src]

fn clone(&self) -> PauliOperator[src]

Returns a copy of the value. Read more

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl Debug for PauliOperator[src]

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

Formats the value using the given formatter. Read more

impl<'de> Deserialize<'de> for PauliOperator[src]

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
    __D: Deserializer<'de>, 
[src]

Deserialize this value from the given Serde deserializer. Read more

impl Display for PauliOperator[src]

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

Formats the value using the given formatter. Read more

impl Hash for PauliOperator[src]

fn hash<__H: Hasher>(&self, state: &mut __H)[src]

Feeds this value into the given Hasher. Read more

fn hash_slice<H>(data: &[Self], state: &mut H) where
    H: Hasher
1.3.0[src]

Feeds a slice of this type into the given Hasher. Read more

impl<'a> Mul<&'a PauliOperator> for &'a PauliOperator[src]

type Output = PauliOperator

The resulting type after applying the * operator.

fn mul(self, other: Self) -> Self::Output[src]

Performs the * operation. Read more

impl PartialEq<PauliOperator> for PauliOperator[src]

fn eq(&self, other: &PauliOperator) -> bool[src]

This method tests for self and other values to be equal, and is used by ==. Read more

fn ne(&self, other: &PauliOperator) -> bool[src]

This method tests for !=.

impl Serialize for PauliOperator[src]

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error> where
    __S: Serializer
[src]

Serialize this value into the given Serde serializer. Read more

impl Eq for PauliOperator[src]

impl StructuralEq for PauliOperator[src]

impl StructuralPartialEq for PauliOperator[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

impl<T> Pointable for T

pub const ALIGN: usize

The alignment of pointer.

type Init = T

The type for initializers.

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

Initializes a with the given initializer. Read more

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

Dereferences the given pointer. Read more

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

Mutably dereferences the given pointer. Read more

pub unsafe fn drop(ptr: usize)

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

impl<SS, SP> SupersetOf<SS> for SP where
    SS: SubsetOf<SP>, 

pub fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more

pub fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).

pub unsafe fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.

pub fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

pub fn to_owned(&self) -> T[src]

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

pub fn clone_into(&self, target: &mut T)[src]

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

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

impl<T> ToString for T where
    T: Display + ?Sized
[src]

pub default fn to_string(&self) -> String[src]

Converts the given value to a String. Read more

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

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

Performs the conversion.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

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

Performs the conversion.

impl<T> DeserializeOwned for T where
    T: for<'de> Deserialize<'de>, 
[src]