OperateOnDensityMatrix

Trait OperateOnDensityMatrix 

Source
pub trait OperateOnDensityMatrix<'a>:
    IntoIterator<Item = (Self::Index, Self::Value)>
    + FromIterator<(Self::Index, Self::Value)>
    + Extend<(Self::Index, Self::Value)>
    + PartialEq
    + Clone
    + Mul<CalculatorFloat>
    + Mul<CalculatorComplex>
    + Add
    + Sub
    + Display
    + Serialize
    + Deserialize<'a>
where Self: 'a, &'a Self: IntoIterator, Self::Index: Clone, Self::Value: Mul<f64, Output = Self::Value> + Add<Self::Value, Output = Self::Value> + Clone + TruncateTrait,
{ type Index; type Value; // Required methods fn get(&self, key: &Self::Index) -> &Self::Value; fn iter( &'a self, ) -> impl ExactSizeIterator<Item = (&'a Self::Index, &'a Self::Value)>; fn keys(&'a self) -> impl ExactSizeIterator<Item = &'a Self::Index>; fn values(&'a self) -> impl ExactSizeIterator<Item = &'a Self::Value>; fn remove(&mut self, key: &Self::Index) -> Option<Self::Value>; fn empty_clone(&self, capacity: Option<usize>) -> Self; fn set( &mut self, key: Self::Index, value: Self::Value, ) -> Result<Option<Self::Value>, StruqtureError>; // Provided methods fn len(&'a self) -> usize { ... } fn is_empty(&'a self) -> bool { ... } fn add_operator_product( &mut self, key: Self::Index, value: Self::Value, ) -> Result<(), StruqtureError> { ... } fn truncate(&'a self, threshold: f64) -> Self { ... } }
Expand description

Trait for all objects that can act on a quantum density matrix like a superoperator.

§Example

use qoqo_calculator::CalculatorComplex;
use std::collections::HashMap;
use struqture::prelude::*;
use struqture::spins::{OperateOnSpins, PauliProduct, PauliOperator};

let mut so = PauliOperator::new();
let pp_0z = PauliProduct::new().z(0);
so.add_operator_product(pp_0z.clone(), CalculatorComplex::from(0.2)).unwrap();
let mut mapping: HashMap<PauliProduct, CalculatorComplex> = HashMap::new();
mapping.insert(pp_0z.clone(), CalculatorComplex::from(0.2));

// Functions provided in this :
assert_eq!(so.get(&pp_0z), &CalculatorComplex::from(0.2));
for (item_so, item_map) in so.iter().zip(mapping.iter()) {
    assert_eq!(item_so, item_map);
}
for (key_so, key_map) in so.keys().zip(mapping.keys()) {
    assert_eq!(key_so, key_map);
}
for (val_so, val_map) in so.values().zip(mapping.values()) {
    assert_eq!(val_so, val_map);
}
assert_eq!(so.len(), 1_usize);
assert_eq!(so.is_empty(), false);

Required Associated Types§

Required Methods§

Source

fn get(&self, key: &Self::Index) -> &Self::Value

Gets the Self::Value typed coefficient corresponding to the key.

§Arguments
  • key - The Self::Index key for which to retrieve the value.
§Returns
  • Value at key (or 0.0).
Source

fn iter( &'a self, ) -> impl ExactSizeIterator<Item = (&'a Self::Index, &'a Self::Value)>

Returns the iterator form of Self.

§Returns
  • Iter<'_, Self::Index, Self::Value> - Self in iterator form.
Source

fn keys(&'a self) -> impl ExactSizeIterator<Item = &'a Self::Index>

Returns the unsorted keys in Self.

§Returns
  • Keys<'_, Self::Index, Self::Value> - The sequence of keys of Self.
Source

fn values(&'a self) -> impl ExactSizeIterator<Item = &'a Self::Value>

Returns the unsorted values in Self.

§Returns
  • Values<'_, Self::Index, Self::Value> - The sequence of values of Self.
Source

fn remove(&mut self, key: &Self::Index) -> Option<Self::Value>

Removes the value of the Self::Index object key.

§Arguments
  • key - The Self::Index object to remove from Self.
§Returns
  • Some(Self::Value) - Key existed, this is the value it had before it was removed.
  • None - Key did not exist.
Source

fn empty_clone(&self, capacity: Option<usize>) -> Self

Returns an instance of Self that has no entries but clones all other properties, with the given capacity.

§Arguments
  • capacity - The capacity of the object to create.
§Returns
  • Self - An empty clone with the same properties as Self, with the given capacity.
Source

fn set( &mut self, key: Self::Index, value: Self::Value, ) -> Result<Option<Self::Value>, StruqtureError>

Provided Methods§

Source

fn len(&'a self) -> usize

Returns number of entries in object.

§Returns
  • usize - The length of the object’s internal_map.
Source

fn is_empty(&'a self) -> bool

Returns true if object contains no values.

§Returns
  • bool - Whether the object is empty or not.
Source

fn add_operator_product( &mut self, key: Self::Index, value: Self::Value, ) -> Result<(), StruqtureError>

Source

fn truncate(&'a self, threshold: f64) -> Self

Truncates Self by returning a copy without entries under a threshold.

Entries with an absolute value under the threshold are removed from the copy of the object that is returned. For entries with complex coefficients the threshold is applied to real and imaginary part separately. All symbolic values are considered to be above the threshold.

§Arguments
  • threshold - The threshold for inclusion.
§Returns
  • Self - The truncated version of Self.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<'a> OperateOnDensityMatrix<'a> for BosonHamiltonian

Source§

impl<'a> OperateOnDensityMatrix<'a> for BosonLindbladNoiseOperator

Source§

impl<'a> OperateOnDensityMatrix<'a> for BosonOperator

Source§

impl<'a> OperateOnDensityMatrix<'a> for FermionHamiltonian

Source§

impl<'a> OperateOnDensityMatrix<'a> for FermionLindbladNoiseOperator

Source§

impl<'a> OperateOnDensityMatrix<'a> for FermionOperator

Source§

impl<'a> OperateOnDensityMatrix<'a> for MixedHamiltonian

Source§

impl<'a> OperateOnDensityMatrix<'a> for MixedLindbladNoiseOperator

Source§

impl<'a> OperateOnDensityMatrix<'a> for MixedOperator

Source§

impl<'a> OperateOnDensityMatrix<'a> for MixedPlusMinusOperator

Source§

impl<'a> OperateOnDensityMatrix<'a> for DecoherenceOperator

Source§

impl<'a> OperateOnDensityMatrix<'a> for PauliHamiltonian

Source§

impl<'a> OperateOnDensityMatrix<'a> for PauliLindbladNoiseOperator

Source§

impl<'a> OperateOnDensityMatrix<'a> for PauliOperator

Source§

impl<'a> OperateOnDensityMatrix<'a> for PlusMinusLindbladNoiseOperator

Source§

impl<'a> OperateOnDensityMatrix<'a> for PlusMinusOperator