pub struct PauliProductWrapper {
pub internal: PauliProduct,
}
Expand description
PauliProducts are combinations of SinglePauliOperators on specific qubits.
PauliProducts can be used in either noise-free or a noisy system.
They are representations of products of pauli matrices acting on qubits,
in order to build the terms of a hamiltonian.
For instance, to represent the term :math:\sigma_0^{x}
:math:\sigma_2^{x}
:
PauliProduct().x(0).x(2)
.
Note that these methods are setters that set the Pauli operator acting on the corresponding spin, and do not represent matrix multiplication. For example
PauliProduct().z(0).z(0)
will set the Pauli operator on spin 0 to Z and not to the identity.
PauliProduct is supposed to be used as input for the function set_pauli_product
,
for instance in the spin system classes PauliLindbladOpenSystem, PauliHamiltonian or PauliOperator,
or in the mixed systems as part of MixedProduct <mixed_systems.MixedProduct>
or as part of HermitianMixedProduct <mixed_systems.HermitianMixedProduct>
.
Returns:
self: The new, empty PauliProduct.
§Examples
.. code-block:: python
import numpy.testing as npt
from struqture_py.spins import PauliProduct
pp = PauliProduct().x(0).y(1).z(2)
pp = pp.set_pauli(3, "X")
npt.assert_equal(pp.get(0), "X")
npt.assert_equal(pp.keys(), [0, 1, 2, 3])
Fields§
§internal: PauliProduct
Internal storage of struqture::spins::PauliProduct
Implementations§
Source§impl PauliProductWrapper
impl PauliProductWrapper
Sourcepub fn from_pyany(input: &Bound<'_, PyAny>) -> PyResult<PauliProduct>
pub fn from_pyany(input: &Bound<'_, PyAny>) -> PyResult<PauliProduct>
Fallible conversion of generic python object..
Source§impl PauliProductWrapper
impl PauliProductWrapper
Sourcepub fn x(&self, index: usize) -> PauliProductWrapper
pub fn x(&self, index: usize) -> PauliProductWrapper
Set a new entry for SinglePauliOperator X in the internal dictionary.
Args: index (int): Index of set object.
Returns: PauliProduct: The PauliProduct with the new entry.
Sourcepub fn y(&self, index: usize) -> PauliProductWrapper
pub fn y(&self, index: usize) -> PauliProductWrapper
Set a new entry for SinglePauliOperator Y in the internal dictionary.
Args: index (int): Index of set object.
Returns: PauliProduct: The PauliProduct with the new entry.
Sourcepub fn z(&self, index: usize) -> PauliProductWrapper
pub fn z(&self, index: usize) -> PauliProductWrapper
Set a new entry for SinglePauliOperator Z in the internal dictionary.
Args: index (int): Index of set object.
Returns: PauliProduct: The PauliProduct with the new entry.
Sourcepub fn set_pauli(&self, index: usize, pauli: String) -> PyResult<Self>
pub fn set_pauli(&self, index: usize, pauli: String) -> PyResult<Self>
Set a new entry in the internal_map. This function consumes self.
Args: index (int): Index of set object. pauli (str): Value of set object.
Returns: self: The entry was correctly set and the PauliProduct is returned.
Sourcepub fn hermitian_conjugate(&self) -> (PauliProductWrapper, f64)
pub fn hermitian_conjugate(&self) -> (PauliProductWrapper, f64)
Return the hermitian conjugate of self and its prefactor.
Returns: (self, float): The hermitian conjugate of self and the potential sign it has picked up.
Sourcepub fn is_natural_hermitian(&self) -> bool
pub fn is_natural_hermitian(&self) -> bool
Return whether self is naturally hermitian.
For spin objects, this is true when applying the hermitian conjugation does not change the sign.
For bosonic and fermionic objects, this is true when creators == annihilators.
For mixed objects, this is true when all of the spin, bosonic and fermionic parts’ is_naturally_hermitian
functions evaluate to true.
Returns: bool: Whether self is naturally hermitian or not.
Sourcepub fn get(&self, index: usize) -> Option<String>
pub fn get(&self, index: usize) -> Option<String>
Get the pauli matrix corresponding to the index.
Args: index (int): Index of get object.
Returns: Optionalstr: The key’s corresponding value (if it exists).
Sourcepub fn keys(&self) -> Vec<usize>
pub fn keys(&self) -> Vec<usize>
Return a list of the unsorted keys in self.
Returns: List[int]: The sequence of qubit index keys of self.
Sourcepub fn current_number_spins(&self) -> usize
pub fn current_number_spins(&self) -> usize
Return maximum index in self.
Returns: int: Maximum index.
Sourcepub fn __len__(&self) -> usize
pub fn __len__(&self) -> usize
Return number of entries in object.
Returns: int: The length of the content of the object.
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Return whether self is empty or not.
Returns: bool: Whether self is empty or not.
Sourcepub fn remap_qubits(
&self,
mapping: HashMap<usize, usize>,
) -> PauliProductWrapper
pub fn remap_qubits( &self, mapping: HashMap<usize, usize>, ) -> PauliProductWrapper
Remap the qubits in a new instance of self (returned).
Args: mapping (Dict[int, int]): The map containing the {qubit: qubit} mapping to use.
Returns: self: The new instance of self with the qubits remapped.
Sourcepub fn concatenate(
&self,
other: PauliProductWrapper,
) -> PyResult<PauliProductWrapper>
pub fn concatenate( &self, other: PauliProductWrapper, ) -> PyResult<PauliProductWrapper>
Return the concatenation of two objects of type self
with no overlapping qubits.
Args: other (self): The object to concatenate self with.
Returns: List[int]: A list of the corresponding creator indices.
Raises: ValueError: The two objects could not be concatenated.
Sourcepub fn multiply(
left: PauliProductWrapper,
right: PauliProductWrapper,
) -> (PauliProductWrapper, Complex64)
pub fn multiply( left: PauliProductWrapper, right: PauliProductWrapper, ) -> (PauliProductWrapper, Complex64)
Multiplication function for a self-typed object by a self-typed object.
Args: left (self): Left-hand self typed object to be multiplied. right (self): Right-hand self typed object to be multiplied.
Returns: (self, complex): The multiplied objects and the resulting prefactor.
Sourcepub fn __copy__(&self) -> PauliProductWrapper
pub fn __copy__(&self) -> PauliProductWrapper
Return a copy of self (copy here produces a deepcopy).
Returns: self: A deep copy of Self.
Sourcepub fn __deepcopy__(&self, _memodict: &Bound<'_, PyAny>) -> PauliProductWrapper
pub fn __deepcopy__(&self, _memodict: &Bound<'_, PyAny>) -> PauliProductWrapper
Return a deep copy of self.
Returns: self: A deep copy of Self.
Sourcepub fn from_bincode(input: &Bound<'_, PyAny>) -> PyResult<PauliProductWrapper>
pub fn from_bincode(input: &Bound<'_, PyAny>) -> PyResult<PauliProductWrapper>
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 the object.
Returns: str: The serialized form of the object.
Raises: ValueError: Cannot serialize object to json.
Sourcepub fn from_json(input: String) -> PyResult<PauliProductWrapper>
pub fn from_json(input: String) -> PyResult<PauliProductWrapper>
Convert the json representation of the object to an instance.
Args: input (str): The serialized object in json form.
Returns: The deserialized object.
Raises: ValueError: Input cannot be deserialized.
Sourcepub fn from_string(input: String) -> PyResult<PauliProductWrapper>
pub fn from_string(input: String) -> PyResult<PauliProductWrapper>
Convert a string representation of the object to an instance.
Args: input (str): The serialized index in str representation.
Returns: self: The converted object.
Raises: ValueError: Input cannot be converted from str.
Sourcepub fn __str__(&self) -> String
pub fn __str__(&self) -> String
Return a string containing a printable representation of the index.
Returns: str: The printable string representation of the index.
Sourcepub fn __repr__(&self) -> String
pub fn __repr__(&self) -> String
Return a string containing a printable representation of the index.
Returns: str: The printable string representation of the index.
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 mixed index.
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 PauliProductWrapper
impl PauliProductWrapper
Sourcepub fn jordan_wigner(&self) -> FermionOperatorWrapper
pub fn jordan_wigner(&self) -> FermionOperatorWrapper
Transform the given spin object into a fermionic object using the Jordan Wigner mapping.
Trait Implementations§
Source§impl Clone for PauliProductWrapper
impl Clone for PauliProductWrapper
Source§fn clone(&self) -> PauliProductWrapper
fn clone(&self) -> PauliProductWrapper
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for PauliProductWrapper
impl Debug for PauliProductWrapper
Source§impl Default for PauliProductWrapper
impl Default for PauliProductWrapper
Source§fn default() -> PauliProductWrapper
fn default() -> PauliProductWrapper
Source§impl Hash for PauliProductWrapper
impl Hash for PauliProductWrapper
Source§impl<'py> IntoPyObject<'py> for PauliProductWrapper
impl<'py> IntoPyObject<'py> for PauliProductWrapper
Source§type Target = PauliProductWrapper
type Target = PauliProductWrapper
Source§type Output = Bound<'py, <PauliProductWrapper as IntoPyObject<'py>>::Target>
type Output = Bound<'py, <PauliProductWrapper 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 Ord for PauliProductWrapper
impl Ord for PauliProductWrapper
Source§fn cmp(&self, other: &PauliProductWrapper) -> Ordering
fn cmp(&self, other: &PauliProductWrapper) -> Ordering
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialEq for PauliProductWrapper
impl PartialEq for PauliProductWrapper
Source§impl PartialOrd for PauliProductWrapper
impl PartialOrd for PauliProductWrapper
Source§impl PyClass for PauliProductWrapper
impl PyClass for PauliProductWrapper
Source§impl PyClassImpl for PauliProductWrapper
impl PyClassImpl for PauliProductWrapper
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<PauliProductWrapper>
type ThreadChecker = SendablePyClass<PauliProductWrapper>
type Inventory = Pyo3MethodsInventoryForPauliProductWrapper
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<PauliProductWrapper> for PyClassImplCollector<PauliProductWrapper>
impl PyClassNewTextSignature<PauliProductWrapper> for PyClassImplCollector<PauliProductWrapper>
fn new_text_signature(self) -> Option<&'static str>
Source§impl<'a, 'py> PyFunctionArgument<'a, 'py, false> for &'a PauliProductWrapper
impl<'a, 'py> PyFunctionArgument<'a, 'py, false> for &'a PauliProductWrapper
Source§impl<'a, 'py> PyFunctionArgument<'a, 'py, false> for &'a mut PauliProductWrapper
impl<'a, 'py> PyFunctionArgument<'a, 'py, false> for &'a mut PauliProductWrapper
Source§impl PyTypeInfo for PauliProductWrapper
impl PyTypeInfo for PauliProductWrapper
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 PauliProductWrapper
impl Eq for PauliProductWrapper
impl StructuralPartialEq for PauliProductWrapper
Auto Trait Implementations§
impl Freeze for PauliProductWrapper
impl RefUnwindSafe for PauliProductWrapper
impl Send for PauliProductWrapper
impl Sync for PauliProductWrapper
impl Unpin for PauliProductWrapper
impl UnwindSafe for PauliProductWrapper
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<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.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.