pub struct PauliHamiltonianWrapper {
pub internal: PauliHamiltonian,
}
Expand description
These are representations of systems of spins.
PauliHamiltonians are characterized by a PauliOperator to represent the hamiltonian of the spin system and an optional number of spins.
Returns: self: The new PauliHamiltonian.
§Examples
.. code-block:: python
import numpy.testing as npt
import scipy.sparse as sp
from qoqo_calculator_pyo3 import CalculatorComplex
from struqture_py.spins import PauliHamiltonian, PauliProduct
system = PauliHamiltonian()
pp = PauliProduct().z(0)
system.add_operator_product(pp, 5.0)
npt.assert_equal(system.current_number_spins(), 1)
npt.assert_equal(system.get(pp), CalculatorComplex(5))
npt.assert_equal(system.keys(), [pp])
dimension = 4**system.current_number_spins()
matrix = sp.coo_matrix(system.sparse_matrix_superoperator_coo(system.current_number_spins()), shape=(dimension, dimension))
Fields§
§internal: PauliHamiltonian
Internal storage of struqture::spins::PauliHamiltonian
Implementations§
Source§impl PauliHamiltonianWrapper
impl PauliHamiltonianWrapper
Sourcepub fn from_pyany(input: &Bound<'_, PyAny>) -> PyResult<PauliHamiltonian>
pub fn from_pyany(input: &Bound<'_, PyAny>) -> PyResult<PauliHamiltonian>
Fallible conversion of generic python object.
Source§impl PauliHamiltonianWrapper
impl PauliHamiltonianWrapper
Sourcepub fn new() -> Self
pub fn new() -> Self
Create an empty PauliHamiltonian.
Returns: self: The new PauliHamiltonian.
Sourcepub fn __mul__(
&self,
value: &Bound<'_, PyAny>,
) -> PyResult<PauliOperatorWrapper>
pub fn __mul__( &self, value: &Bound<'_, PyAny>, ) -> PyResult<PauliOperatorWrapper>
Implement *
for PauliHamiltonian and PauliHamiltonian/CalculatorComplex/CalculatorFloat.
Args: value (Union[PauliHamiltonian, CalculatorComplex, CalculatorFloat]): value by which to multiply the self PauliHamiltonian
Returns: PauliOperator: The PauliHamiltonian multiplied by the value.
Raises: ValueError: The rhs of the multiplication is neither CalculatorFloat, CalculatorComplex, nor PauliHamiltonian.
Sourcepub fn keys(&self) -> Vec<PauliProductWrapper>
pub fn keys(&self) -> Vec<PauliProductWrapper>
Return a list of the unsorted keys in self.
Returns: List[OperatorProduct]: The sequence of keys of the self.
Sourcepub fn __len__(&self) -> usize
pub fn __len__(&self) -> usize
Return number of entries in self.
Returns: int: The length of the content of self.
Sourcepub fn empty_clone(&self, capacity: Option<usize>) -> PauliHamiltonianWrapper
pub fn empty_clone(&self, capacity: Option<usize>) -> PauliHamiltonianWrapper
Return an instance of self that has no entries but clones all other properties, with the given capacity.
Args: capacity (Optional[int]): The capacity of the new instance to create.
Returns: self: An empty clone with the same properties as self, with the given capacity.
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Return true if self contains no values.
Returns: bool: Whether self is empty or not.
Sourcepub fn truncate(&self, threshold: f64) -> PauliHamiltonianWrapper
pub fn truncate(&self, threshold: f64) -> PauliHamiltonianWrapper
Truncate self by returning a copy without entries under a threshold.
Args: threshold (float): The threshold for inclusion.
Returns: self: The truncated version of self.
Sourcepub fn get(&self, key: &Bound<'_, PyAny>) -> PyResult<CalculatorFloatWrapper>
pub fn get(&self, key: &Bound<'_, PyAny>) -> PyResult<CalculatorFloatWrapper>
Get the coefficient corresponding to the key.
Args: key: Product to get the value of.
Returns: CalculatorComplex: Value at key (or 0.0).
Raises: ValueError: Product could not be constructed from key.
Sourcepub fn remove(
&mut self,
key: &Bound<'_, PyAny>,
) -> PyResult<Option<CalculatorFloatWrapper>>
pub fn remove( &mut self, key: &Bound<'_, PyAny>, ) -> PyResult<Option<CalculatorFloatWrapper>>
Remove the value of the input key.
Args: key (Product type): The key of the value to remove.
Returns: Optional[Union[CalculatorComplex, CalculatorFloat]]: Key existed if this is not None, and this is the value it had before it was removed.
Raises: ValueError: Product could not be constructed.
Sourcepub fn set(
&mut self,
key: &Bound<'_, PyAny>,
value: &Bound<'_, PyAny>,
) -> PyResult<Option<CalculatorFloatWrapper>>
pub fn set( &mut self, key: &Bound<'_, PyAny>, value: &Bound<'_, PyAny>, ) -> PyResult<Option<CalculatorFloatWrapper>>
Overwrite an existing entry or set a new entry in self.
Args: key (Product type): The key to set. value (Union[CalculatorComplex, CalculatorFloat]): The value to set.
Returns: Optional[Union[CalculatorComplex, CalculatorFloat]]: Key existed if this is not None, and this is the value it had before it was overwritten.
Raises: ValueError: Product could not be constructed.
Sourcepub fn add_operator_product(
&mut self,
key: &Bound<'_, PyAny>,
value: &Bound<'_, PyAny>,
) -> PyResult<()>
pub fn add_operator_product( &mut self, key: &Bound<'_, PyAny>, value: &Bound<'_, PyAny>, ) -> PyResult<()>
Add a new (key object, value Union[CalculatorComplex, CalculatorFloat]) pair to existing entries.
Args: key (Product type): The key object value (Union[CalculatorComplex, CalculatorFloat]): The value to add.
Raises: TypeError: Value is not CalculatorComplex or CalculatorFloat. ValueError: Product could not be constructed. ValueError: Error in add_operator_product function of self.
Sourcepub fn values(&self) -> Vec<CalculatorFloatWrapper>
pub fn values(&self) -> Vec<CalculatorFloatWrapper>
Return unsorted values in self.
Returns: List[Union[CalculatorComplex, CalculatorFloat]]: The sequence of values of self.
Sourcepub fn hermitian_conjugate(&self) -> PauliHamiltonianWrapper
pub fn hermitian_conjugate(&self) -> PauliHamiltonianWrapper
Return the hermitian conjugate of self.
Returns: self: The hermitian conjugate of self.
Sourcepub fn current_number_spins(&self) -> usize
pub fn current_number_spins(&self) -> usize
Return the current_number_spins input of self.
Returns: int: The number of spins in self.
Sourcepub fn number_spins(&self) -> usize
pub fn number_spins(&self) -> usize
Return maximum index in self.
Returns: int: Maximum index.
Sourcepub fn sparse_matrix_coo(&self, number_spins: usize) -> PyResult<PyCooMatrix>
pub fn sparse_matrix_coo(&self, number_spins: usize) -> PyResult<PyCooMatrix>
Constructs the sparse matrix representation of self as a scipy COO matrix with a given number of spins.
Args: number_spins (int): The number of spins in self.
Returns: Tuple[np.ndarray, Tuple[np.ndarray, np.ndarray]]: The little endian matrix representation of self.
Raises: ValueError: CalculatorError. RuntimeError: Could not convert to complex superoperator matrix.
Sourcepub fn sparse_matrix_superoperator_coo(
&self,
number_spins: usize,
) -> PyResult<PyCooMatrix>
pub fn sparse_matrix_superoperator_coo( &self, number_spins: usize, ) -> PyResult<PyCooMatrix>
Construct the sparse matrix representation of the superoperator in COO representation.
The superoperator for the operator O is defined as the Matrix S so that
flatten(-i [O, p]) = S flatten(p)
wher [,]
is the commutator, p
is a matrix
and flatten
flattens a matrix into a vector in row-major form.
Args: number_spins (int): The number of spins to construct the matrix for.
Returns: Tuple[np.ndarray, Tuple[np.ndarray, np.ndarray]]: The little endian matrix representation of self.
Raises: ValueError: CalculatorError. RuntimeError: Could not convert to complex superoperator matrix.
Sourcepub fn __neg__(&self) -> PauliHamiltonianWrapper
pub fn __neg__(&self) -> PauliHamiltonianWrapper
Implement -1
for self.
Returns: self: The object * -1.
Sourcepub fn __add__(
&self,
other: PauliHamiltonianWrapper,
) -> PyResult<PauliHamiltonianWrapper>
pub fn __add__( &self, other: PauliHamiltonianWrapper, ) -> PyResult<PauliHamiltonianWrapper>
Implement +
for self with self-type.
Args: other (self): value by which to add to self.
Returns: self: The two objects added.
Raises: ValueError: Objects could not be added.
Sourcepub fn __sub__(
&self,
other: PauliHamiltonianWrapper,
) -> PyResult<PauliHamiltonianWrapper>
pub fn __sub__( &self, other: PauliHamiltonianWrapper, ) -> PyResult<PauliHamiltonianWrapper>
Implement -
for self with self-type.
Args: other (self): value by which to subtract from self.
Returns: self: The two objects subtracted.
Raises: ValueError: Objects could not be subtracted.
Sourcepub fn __copy__(&self) -> PauliHamiltonianWrapper
pub fn __copy__(&self) -> PauliHamiltonianWrapper
Return a copy of self (copy here produces a deepcopy).
Returns: self: A deep copy of self.
Sourcepub fn __deepcopy__(
&self,
_memodict: &Bound<'_, PyAny>,
) -> PauliHamiltonianWrapper
pub fn __deepcopy__( &self, _memodict: &Bound<'_, PyAny>, ) -> PauliHamiltonianWrapper
Return a deep copy of self.
Returns: self: A deep copy of self.
Sourcepub fn from_bincode(
input: &Bound<'_, PyAny>,
) -> PyResult<PauliHamiltonianWrapper>
pub fn from_bincode( input: &Bound<'_, PyAny>, ) -> PyResult<PauliHamiltonianWrapper>
Sourcepub fn to_bincode(&self) -> PyResult<Py<PyByteArray>>
pub fn to_bincode(&self) -> PyResult<Py<PyByteArray>>
Sourcepub fn to_json(&self) -> PyResult<String>
pub fn to_json(&self) -> PyResult<String>
Return the json representation of self.
Returns: str: The serialized form of self.
Raises: ValueError: Cannot serialize object to json.
Sourcepub fn from_json(input: String) -> PyResult<PauliHamiltonianWrapper>
pub fn from_json(input: String) -> PyResult<PauliHamiltonianWrapper>
Convert the json representation of self to an instance.
Args: input (str): The serialized object in json form.
Returns: The deserialized object.
Raises: ValueError: Input cannot be deserialized.
Sourcepub fn __str__(&self) -> String
pub fn __str__(&self) -> String
Return a string containing a printable representation of self.
Returns: str: The printable string representation of self.
Sourcepub fn __repr__(&self) -> String
pub fn __repr__(&self) -> String
Return a string containing a printable representation of self.
Returns: str: The printable string representation of self.
Sourcepub fn __richcmp__(
&self,
other: &Bound<'_, PyAny>,
op: CompareOp,
) -> PyResult<bool>
pub fn __richcmp__( &self, other: &Bound<'_, PyAny>, op: CompareOp, ) -> PyResult<bool>
Return the richcmp magic method to perform rich comparison operations on object.
Args: other: The object to compare self to. op: Whether they should be equal or not.
Returns: Whether the two operations compared evaluated to True or False
Raises: NotImplementedError: Other comparison not implemented.
Source§impl PauliHamiltonianWrapper
impl PauliHamiltonianWrapper
Sourcepub fn jordan_wigner(&self) -> FermionHamiltonianWrapper
pub fn jordan_wigner(&self) -> FermionHamiltonianWrapper
Transform the given spin object into a fermionic object using the Jordan Wigner mapping.
Trait Implementations§
Source§impl Clone for PauliHamiltonianWrapper
impl Clone for PauliHamiltonianWrapper
Source§fn clone(&self) -> PauliHamiltonianWrapper
fn clone(&self) -> PauliHamiltonianWrapper
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for PauliHamiltonianWrapper
impl Debug for PauliHamiltonianWrapper
Source§impl Default for PauliHamiltonianWrapper
impl Default for PauliHamiltonianWrapper
Source§impl<'py> IntoPyObject<'py> for PauliHamiltonianWrapper
impl<'py> IntoPyObject<'py> for PauliHamiltonianWrapper
Source§type Target = PauliHamiltonianWrapper
type Target = PauliHamiltonianWrapper
Source§type Output = Bound<'py, <PauliHamiltonianWrapper as IntoPyObject<'py>>::Target>
type Output = Bound<'py, <PauliHamiltonianWrapper as IntoPyObject<'py>>::Target>
Source§fn into_pyobject(
self,
py: Python<'py>,
) -> Result<<Self as IntoPyObject<'_>>::Output, <Self as IntoPyObject<'_>>::Error>
fn into_pyobject( self, py: Python<'py>, ) -> Result<<Self as IntoPyObject<'_>>::Output, <Self as IntoPyObject<'_>>::Error>
Source§impl PartialEq for PauliHamiltonianWrapper
impl PartialEq for PauliHamiltonianWrapper
Source§impl PyClass for PauliHamiltonianWrapper
impl PyClass for PauliHamiltonianWrapper
Source§impl PyClassImpl for PauliHamiltonianWrapper
impl PyClassImpl for PauliHamiltonianWrapper
Source§const IS_BASETYPE: bool = false
const IS_BASETYPE: bool = false
Source§const IS_SUBCLASS: bool = false
const IS_SUBCLASS: bool = false
Source§const IS_MAPPING: bool = false
const IS_MAPPING: bool = false
Source§const IS_SEQUENCE: bool = false
const IS_SEQUENCE: bool = false
Source§const IS_IMMUTABLE_TYPE: bool = false
const IS_IMMUTABLE_TYPE: bool = false
Source§type ThreadChecker = SendablePyClass<PauliHamiltonianWrapper>
type ThreadChecker = SendablePyClass<PauliHamiltonianWrapper>
type Inventory = Pyo3MethodsInventoryForPauliHamiltonianWrapper
Source§type PyClassMutability = <<PyAny as PyClassBaseType>::PyClassMutability as PyClassMutability>::MutableChild
type PyClassMutability = <<PyAny as PyClassBaseType>::PyClassMutability as PyClassMutability>::MutableChild
Source§type BaseNativeType = PyAny
type BaseNativeType = PyAny
PyAny
by default, and when you declare
#[pyclass(extends=PyDict)]
, it’s PyDict
.fn items_iter() -> PyClassItemsIter
fn lazy_type_object() -> &'static LazyTypeObject<Self>
fn dict_offset() -> Option<isize>
fn weaklist_offset() -> Option<isize>
Source§impl PyClassNewTextSignature<PauliHamiltonianWrapper> for PyClassImplCollector<PauliHamiltonianWrapper>
impl PyClassNewTextSignature<PauliHamiltonianWrapper> for PyClassImplCollector<PauliHamiltonianWrapper>
fn new_text_signature(self) -> Option<&'static str>
Source§impl PyClass__add__SlotFragment<PauliHamiltonianWrapper> for PyClassImplCollector<PauliHamiltonianWrapper>
impl PyClass__add__SlotFragment<PauliHamiltonianWrapper> for PyClassImplCollector<PauliHamiltonianWrapper>
Source§impl PyClass__mul__SlotFragment<PauliHamiltonianWrapper> for PyClassImplCollector<PauliHamiltonianWrapper>
impl PyClass__mul__SlotFragment<PauliHamiltonianWrapper> for PyClassImplCollector<PauliHamiltonianWrapper>
Source§impl PyClass__sub__SlotFragment<PauliHamiltonianWrapper> for PyClassImplCollector<PauliHamiltonianWrapper>
impl PyClass__sub__SlotFragment<PauliHamiltonianWrapper> for PyClassImplCollector<PauliHamiltonianWrapper>
Source§impl<'a, 'py> PyFunctionArgument<'a, 'py, false> for &'a PauliHamiltonianWrapper
impl<'a, 'py> PyFunctionArgument<'a, 'py, false> for &'a PauliHamiltonianWrapper
Source§impl<'a, 'py> PyFunctionArgument<'a, 'py, false> for &'a mut PauliHamiltonianWrapper
impl<'a, 'py> PyFunctionArgument<'a, 'py, false> for &'a mut PauliHamiltonianWrapper
Source§impl PyTypeInfo for PauliHamiltonianWrapper
impl PyTypeInfo for PauliHamiltonianWrapper
Source§fn type_object_raw(py: Python<'_>) -> *mut PyTypeObject
fn type_object_raw(py: Python<'_>) -> *mut PyTypeObject
Source§fn type_object(py: Python<'_>) -> Bound<'_, PyType>
fn type_object(py: Python<'_>) -> Bound<'_, PyType>
impl DerefToPyAny for PauliHamiltonianWrapper
impl StructuralPartialEq for PauliHamiltonianWrapper
Auto Trait Implementations§
impl Freeze for PauliHamiltonianWrapper
impl RefUnwindSafe for PauliHamiltonianWrapper
impl Send for PauliHamiltonianWrapper
impl Sync for PauliHamiltonianWrapper
impl Unpin for PauliHamiltonianWrapper
impl UnwindSafe for PauliHamiltonianWrapper
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> FromPyObject<'_> for T
impl<T> FromPyObject<'_> for T
Source§impl<'py, T> FromPyObjectBound<'_, 'py> for Twhere
T: FromPyObject<'py>,
impl<'py, T> FromPyObjectBound<'_, 'py> for Twhere
T: FromPyObject<'py>,
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 moreSource§impl<'py, T> IntoPyObjectExt<'py> for Twhere
T: IntoPyObject<'py>,
impl<'py, T> IntoPyObjectExt<'py> for Twhere
T: IntoPyObject<'py>,
Source§fn into_bound_py_any(self, py: Python<'py>) -> Result<Bound<'py, PyAny>, PyErr>
fn into_bound_py_any(self, py: Python<'py>) -> Result<Bound<'py, PyAny>, PyErr>
self
into an owned Python object, dropping type information.