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§
Sourcefn iter(
&'a self,
) -> impl ExactSizeIterator<Item = (&'a Self::Index, &'a Self::Value)>
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.
Sourcefn keys(&'a self) -> impl ExactSizeIterator<Item = &'a Self::Index>
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.
Sourcefn values(&'a self) -> impl ExactSizeIterator<Item = &'a Self::Value>
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.
Sourcefn empty_clone(&self, capacity: Option<usize>) -> Self
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 add_operator_product( &mut self, key: Self::Index, value: Self::Value, ) -> Result<(), StruqtureError>
Sourcefn truncate(&'a self, threshold: f64) -> Self
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.