struqture_py
Struqture python interface
HQS Quantum Simulations package for representing physical operators.
Copyright © 2021-2023 HQS Quantum Simulations GmbH. All Rights Reserved.
Spin module of struqture Python interface |
|
Bosons module of struqture Python interface |
|
Fermions module of struqture Python interface |
|
Module for representing mixed physical systems. |
Classes
|
These are representations of systems of bosons. |
|
These are representations of noisy systems of bosons. |
|
These are representations of noisy systems of bosons. |
|
A product of bosonic creation and annihilation operators. |
|
These are representations of systems of bosons. |
These are combinations of SingleDecoherenceOperators on specific qubits. |
|
|
These are representations of systems of fermions. |
|
These are representations of noisy systems of fermions. |
|
These are representations of noisy systems of fermions. |
|
A product of fermionic creation and annihilation operators. |
|
These are representations of systems of fermions. |
|
A product of bosonic creation and annihilation operators. |
|
A product of fermionic creation and annihilation operators. |
|
A mixed product of pauli products and boson products. |
|
A mixed product of pauli products and boson products. |
|
These are representations of systems of mixed_systems. |
|
These are representations of noisy systems of mixed_systems. |
|
These are representations of noisy systems of mixed_systems. |
|
These are representations of systems of mixed_systems. |
|
A mixed product of pauli products and boson products. |
|
A mixed product of pauli products and boson products. |
|
These are representations of systems of mixed_systems. |
PauliProducts are combinations of SingleSpinOperators on specific qubits. |
|
These are representations of noisy systems of spins. |
|
These are representations of systems of spins. |
|
PlusMinusProducts are combinations of SinglePlusMinusOperators on specific qubits. |
|
|
These are representations of systems of spins. |
|
These are representations of noisy systems of spins. |
|
These are representations of noisy systems of spins. |
|
These are representations of systems of spins. |
- class struqture_py.BosonHamiltonianSystem(number_bosons=None)
These are representations of systems of bosons.
BosonHamiltonianSystems are characterized by a BosonOperator to represent the hamiltonian of the spin system and an optional number of bosons.
- Returns:
The new BosonHamiltonianSystem with the input number of bosons.
- Return type:
self
Examples
import numpy.testing as npt import scipy.sparse as sp from qoqo_calculator_pyo3 import CalculatorComplex from struqture_py.bosons import BosonHamiltonianSystem, HermitianBosonProduct ssystem = BosonHamiltonianSystem(2) pp = HermitianBosonProduct([0], [0]) ssystem.add_operator_product(pp, 5.0) npt.assert_equal(ssystem.number_modes(), 2) npt.assert_equal(ssystem.get(pp), CalculatorComplex(5)) npt.assert_equal(ssystem.keys(), [pp])
- add_operator_product(key, value)
Add a new (key object, value Union[CalculatorComplex, CalculatorFloat]) pair to existing entries.
- Parameters:
key (Product type) -- The key object
- Raises:
TypeError -- Value is not CalculatorComplex or CalculatorFloat.
ValueError -- Product could not be constructed.
ValueError -- Error in add_operator_product function of self.
- current_number_modes()
Return maximum index in self.
- Returns:
Maximum index.
- Return type:
int
- static current_version()
Returns the current version of the struqture library .
- Returns:
The current version of the library.
- Return type:
str
- empty_clone(capacity=None)
Return an instance of self that has no entries but clones all other properties, with the given capacity.
- Parameters:
capacity (Optional[int]) -- The capacity of the new instance to create.
- Returns:
An empty clone with the same properties as self, with the given capacity.
- Return type:
self
- static from_bincode(input)
Convert the bincode representation of self to an instance using the [bincode] crate.
- Parameters:
input (bytearray) -- The serialized object (in [bincode] form).
- Returns:
The deserialized object.
- Raises:
TypeError -- Input cannot be converted to byte array.
ValueError -- Input cannot be deserialized.
- static from_json(input)
Convert the json representation of self to an instance.
- Parameters:
input (str) -- The serialized object in json form.
- Returns:
The deserialized object.
- Raises:
ValueError -- Input cannot be deserialized.
- get(key)
Get the coefficient corresponding to the key.
- Parameters:
key -- Product to get the value of.
- Returns:
Value at key (or 0.0).
- Return type:
CalculatorComplex
- Raises:
ValueError -- Product could not be constructed from key.
- hermitian_conjugate()
Return the hermitian conjugate of self.
- Returns:
The hermitian conjugate of self.
- Return type:
self
- is_empty()
Return true if self contains no values.
- Returns:
Whether self is empty or not.
- Return type:
bool
- static json_schema()
Return the JsonSchema for the json serialisation of the class.
- Returns:
The json schema serialized to json
- Return type:
str
- keys()
Return a list of the unsorted keys in self.
- Returns:
The sequence of keys of the self.
- Return type:
List[OperatorProduct]
- min_supported_version()
Return the minimum version of struqture that supports this object.
- Returns:
The minimum version of the struqture library to deserialize this object.
- Return type:
str
- number_modes()
Return the number_modes input of self.
- Returns:
The number of modes in self.
- Return type:
int
- remove(key)
Remove the value of the input key.
- Parameters:
key -- The key of the value to remove.
- Raises:
ValueError -- Product could not be constructed.
- separate_into_n_terms(number_creators_annihilators)
Separate self into an operator with the terms of given number of creation and annihilation operators and an operator with the remaining operations.
- Parameters:
number_creators_annihilators (Tuple[int, int]) -- Number of modes to filter for in the keys.
- Returns:
Operator with the noise terms where the number of creation and annihilation operators matches the number of spins the operator product acts on and Operator with all other contributions.
- Return type:
Tuple[Self, Self]
- Raises:
ValueError -- Error in adding terms to return values.
- set(key, value)
Overwrite an existing entry or set a new entry in self.
- Parameters:
key (Product type) -- The key to set.
value (Union[CalculatorComplex, CalculatorFloat]) -- The value to set.
- Returns:
Key existed if this is not None, and this is the value it had before it was overwritten.
- Return type:
Optional[Union[CalculatorComplex, CalculatorFloat]]
- Raises:
ValueError -- Product could not be constructed.
- to_bincode()
Return the bincode representation of self using the [bincode] crate.
- Returns:
The serialized object (in [bincode] form).
- Return type:
bytearray
- Raises:
ValueError -- Cannot serialize object to bytes.
- to_json()
Return the json representation of self.
- Returns:
The serialized form of self.
- Return type:
str
- Raises:
ValueError -- Cannot serialize object to json.
- truncate(threshold)
Truncate self by returning a copy without entries under a threshold.
- Parameters:
threshold (float) -- The threshold for inclusion.
- Returns:
The truncated version of self.
- Return type:
self
- values()
Return unsorted values in self.
- Returns:
The sequence of values of self.
- Return type:
List[Union[CalculatorComplex, CalculatorFloat]]
- class struqture_py.BosonLindbladNoiseSystem(number_bosons=None)
These are representations of noisy systems of bosons.
In a BosonLindbladNoiseSystem is characterized by a BosonLindbladNoiseOperator to represent the hamiltonian of the system, and an optional number of bosons.
- Parameters:
number_bosons (Optional[int]) -- The number of bosons in the BosonLindbladNoiseSystem.
- Returns:
The new BosonLindbladNoiseSystem with the input number of bosons.
- Return type:
self
Examples
import numpy.testing as npt import scipy.sparse as sp from qoqo_calculator_pyo3 import CalculatorComplex from struqture_py.bosons import BosonLindbladNoiseSystem, BosonProduct slns = BosonLindbladNoiseSystem() dp = BosonProduct([0], [1]) slns.add_operator_product((dp, dp), 2.0) npt.assert_equal(slns.current_number_modes(), 2) npt.assert_equal(slns.get((dp, dp)), CalculatorComplex(2))
- add_operator_product(key, value)
Adds a new (key object, CalculatorComplex) pair to existing entries.
- Parameters:
key (Tuple[Product type, Product type]) -- The key of the value to add.
value (CalculatorComplex) -- The value to add.
- Raises:
TypeError -- Value is not CalculatorComplex or CalculatorFloat.
ValueError -- Left-hand product could not be constructed.
ValueError -- Right-hand product could not be constructed.
ValueError -- Error in add_operator_product function of self.
- current_number_modes()
Return maximum index in object.
- Returns:
Maximum index.
- Return type:
int
- static current_version()
Returns the current version of the struqture library .
- Returns:
The current version of the library.
- Return type:
str
- empty_clone(capacity=None)
Return an instance of self that has no entries but clones all other properties, with the given capacity.
- Parameters:
capacity -- The capacity of the object to create.
- Returns:
An empty clone with the same properties as self, with the given capacity.
- Return type:
self
- static from_bincode(input)
Convert the bincode representation of the object to an instance using the [bincode] crate.
- Parameters:
input (bytearray) -- The serialized object (in [bincode] form).
- Returns:
The deserialized object.
- Raises:
TypeError -- Input cannot be converted to byte array.
ValueError -- Input cannot be deserialized.
- static from_json(input)
Convert the json representation of the object to an instance.
- Parameters:
input (str) -- The serialized object in json form.
- Returns:
The deserialized object.
- Raises:
ValueError -- Input cannot be deserialized.
- get(key)
Get the coefficient corresponding to the key.
- Parameters:
key (Tuple[Product type, Product type]) -- Product to get the value of.
- Returns:
Value at key (or 0.0).
- Return type:
CalculatorComplex
- Raises:
ValueError -- Left-hand product could not be constructed from key.
ValueError -- Right-hand product could not be constructed from key.
- is_empty()
Return true if object contains no values.
- Returns:
Whether self is empty or not.
- Return type:
bool
- static json_schema()
Return the JsonSchema for the json serialisation of the class.
- Returns:
The json schema serialized to json
- Return type:
str
- keys()
Return unsorted keys in self.
- Returns:
The sequence of keys of self.
- Return type:
List[(OperatorProduct, OperatorProduct)]
- min_supported_version()
Return the minimum version of struqture that supports this object.
- Returns:
The minimum version of the struqture library to deserialize this object.
- Return type:
str
- number_modes()
Return the number_modes input of self.
- Returns:
The number of modes in self.
- Return type:
int
- remove(key)
Remove the value of the input object key.
- Parameters:
key (Tuple[Product type, Product type]) -- The key of the value to remove.
- Returns:
Key existed if this is not None, and this is the value it had before it was removed.
- Return type:
Optional[CalculatorComplex]
- Raises:
ValueError -- Left-hand Product could not be constructed.
ValueError -- Right-hand Product could not be constructed.
- separate_into_n_terms(number_creators_annihilators_left, number_creators_annihilators_right)
Separate self into an operator with the terms of given number of creation and annihilation operators and an operator with the remaining operations.
- Parameters:
number_creators_annihilators_left (Tuple[int, int]) -- Number of creators and number of annihilators to filter for in the left term of the keys.
number_creators_annihilators_right (Tuple[int, int]) -- Number of creators and number of annihilators to filter for in the right term of the keys.
- Returns:
Operator with the noise terms where the number of creation and annihilation operators matches the number of spins the operator product acts on and Operator with all other contributions.
- Return type:
- Raises:
ValueError -- Error in adding terms to return values.
- set(key, value)
Overwrite an existing entry or set a new entry in self.
- Parameters:
key (Tuple[Product type, Product type]) -- The key of the value to set.
value (CalculatorComplex) -- The value to set.
- Returns:
Key existed if this is not None, and this is the value it had before it was overwritten.
- Return type:
Optional[CalculatorComplex]
- Raises:
ValueError -- Left-hand Product could not be constructed.
ValueError -- Right-hand Product could not be constructed.
- to_bincode()
Return the bincode representation of the object using the [bincode] crate.
- Returns:
The serialized object (in [bincode] form).
- Return type:
bytearray
- Raises:
ValueError -- Cannot serialize object to bytes.
- to_json()
Return the json representation of the object.
- Returns:
The serialized form of the object.
- Return type:
str
- Raises:
ValueError -- Cannot serialize object to json.
- truncate(threshold)
Truncate self by returning a copy without entries under a threshold.
- Parameters:
threshold -- The threshold for inclusion.
- Returns:
The truncated version of self.
- Return type:
self
- values()
Return unsorted values in self.
- Returns:
The sequence of values of self.
- Return type:
List[CalculatorComplex]
- class struqture_py.BosonLindbladOpenSystem(number_bosons=None)
These are representations of noisy systems of bosons.
In a BosonLindbladOpenSystem is characterized by a BosonLindbladOpenOperator to represent the hamiltonian of the system, and an optional number of bosons.
- Parameters:
number_bosons (Optional[int]) -- The number of bosons in the BosonLindbladOpenSystem.
- Returns:
The new BosonLindbladOpenSystem with the input number of bosons.
- Return type:
self
Examples
import numpy.testing as npt import scipy.sparse as sp from qoqo_calculator_pyo3 import CalculatorComplex, CalculatorFloat from struqture_py.bosons import BosonLindbladOpenSystem, BosonProduct slns = BosonLindbladOpenSystem() dp = BosonProduct([0], [1]) slns.system_add_operator_product(dp, 2.0) npt.assert_equal(slns.current_number_modes(), 2) npt.assert_equal(slns.system().get(dp), CalculatorFloat(2))
- current_number_modes()
Return maximum index in object.
- Returns:
Maximum index.
- Return type:
int
- static current_version()
Returns the current version of the struqture library .
- Returns:
The current version of the library.
- Return type:
str
- empty_clone()
Return an instance of self that has no entries but clones all other properties, with the given capacity.
- Returns:
An empty clone with the same properties as self, with the given capacity.
- Return type:
self
- static from_bincode(input)
Convert the bincode representation of the object to an instance using the [bincode] crate.
- Parameters:
input (bytearray) -- The serialized object (in [bincode] form).
- Returns:
The deserialized object.
- Raises:
TypeError -- Input cannot be converted to byte array.
ValueError -- Input cannot be deserialized.
- static from_json(input)
Convert the json representation of the object to an instance.
- Parameters:
input (str) -- The serialized object in json form.
- Returns:
The deserialized object.
- Raises:
ValueError -- Input cannot be deserialized.
- static group(system, noise)
Take a tuple of a system term and a noise term and combines them to be a OpenSystem.
- Parameters:
system -- The system to have in the new instance.
noise -- The noise to have in the new instance.
- Returns:
The OpenSystem with input system and noise terms.
- Return type:
self
- Raises:
ValueError -- System could not be constructed.
ValueError -- Noise could not be constructed.
ValueError -- Grouping could not be constructed.
- static json_schema()
Return the JsonSchema for the json serialisation of the class.
- Returns:
The json schema serialized to json
- Return type:
str
- min_supported_version()
Return the minimum version of struqture that supports this object.
- Returns:
The minimum version of the struqture library to deserialize this object.
- Return type:
str
- noise()
Return the noise part of self.
- Returns:
The noise of self.
- Return type:
Noise type
- noise_add_operator_product(key, value)
Add a new entry to the system of the open system.
- Parameters:
key (Tuple[Product type, Product type]) -- Tuple of Products of set object.
value (CalculatorComplex) -- Value of set object.
- Returns:
The OpenSystem with the new entry.
- Return type:
OpenSystem
- Raises:
ValueError -- Left key element cannot be converted to product.
ValueError -- Right key element cannot be converted to product.
TypeError -- Value cannot be converted to CalculatorComplex.
- noise_get(key)
Get the CalculatorComplex coefficient corresponding to the key.
- Parameters:
key (Tuple[Product type, Product type]) -- Tuple of Products of set object.
- Returns:
Value at key (or 0.0).
- Return type:
CalculatorComplex
- Raises:
ValueError -- Left key element cannot be converted to product.
ValueError -- Right key element cannot be converted to product.
- noise_set(key, value)
Set a new entry in the noise of the open system.
- Parameters:
key (Tuple[Product type, Product type]) -- Tuple of Products of set object.
value (CalculatorComplex) -- CalculatorComplex value of set object.
- Returns:
The OpenSystem with the new entry.
- Return type:
OpenSystem
- Raises:
ValueError -- Left key element cannot be converted to product.
ValueError -- Right key element cannot be converted to product.
TypeError -- Value cannot be converted to Union[CalculatorComplex, CalculatorFloat].
- number_modes()
Return the number_modes input of self.
- Returns:
The number of modes in self.
- Return type:
int
- system()
Return the system part of self.
- Returns:
The system of self.
- Return type:
System type
- system_add_operator_product(key, value)
Add a new entry to the system of the open system.
- Parameters:
key (Product type) -- Product key of set object.
value (Union[CalculatorComplex, CalculatorFloat]) -- Value of set object.
- Returns:
The OpenSystem with the new entry.
- Return type:
OpenSystem
- Raises:
ValueError -- key element cannot be converted to product.
TypeError -- Value cannot be converted to Union[CalculatorComplex, CalculatorFloat].
- system_get(key)
Get the CalculatorComplex or CalculatorFloat coefficient corresponding to the key.
- Parameters:
key (Product type) -- Product key of set object.
- Returns:
Value at key (or 0.0).
- Return type:
CalculatorComplex or CalculatorFloat
- Raises:
ValueError -- key element cannot be converted to product.
- system_set(key, value)
Set a new entry in the system of the open system.
- Parameters:
key (Product type) -- Product key of set object.
value (Union[CalculatorComplex, CalculatorFloat]) -- Value of set object.
- Returns:
The OpenSystem with the new entry.
- Return type:
OpenSystem
- Raises:
ValueError -- key element cannot be converted to product.
TypeError -- Value cannot be converted to Union[CalculatorComplex, CalculatorFloat].
- to_bincode()
Return the bincode representation of the object using the [bincode] crate.
- Returns:
The serialized object (in [bincode] form).
- Return type:
bytearray
- Raises:
ValueError -- Cannot serialize object to bytes.
- to_json()
Return the json representation of the object.
- Returns:
The serialized form of the object.
- Return type:
str
- Raises:
ValueError -- Cannot serialize object to json.
- truncate(threshold)
Truncate self by returning a copy without entries under a threshold.
- Parameters:
threshold -- The threshold for inclusion.
- Returns:
The truncated version of self.
- Return type:
self
- ungroup()
Return a tuple of the system and the noise of self.
- Returns:
The system and noise of self.
- Return type:
(System, Noise)
- class struqture_py.BosonProduct(creators, annihilators)
A product of bosonic creation and annihilation operators.
The BosonProduct is used as an index for non-hermitian, normal ordered bosonic operators. A bosonic operator can be written as a sum over normal ordered products of creation and annihilation operators. The BosonProduct is used as an index when setting or adding new summands to a bosonic operator and when querrying the weight of a product of operators in the sum.
- Parameters:
creators (List[int]) -- List of creator sub-indices.
annihilators (List[int]) -- List of annihilator sub-indices.
- Returns:
The new (empty) BosonProduct.
- Return type:
self
Example:
from struqture_py.bosons import BosonProduct import numpy.testing as npt # For instance, to represent $c_0a_0$ b_product = BosonProduct([0], [0]) npt.assert_equal(b_product.creators(), [0]) npt.assert_equal(b_product.annihilators(), [0])
- annihilators()
Return list of annihilator indices.
- Returns:
A list of the corresponding annihilator indices.
- Return type:
List[int]
- create_valid_pair(annihilators, value)
Create valid pair of index and value to be set in an operator.
The first item is the valid instance of self created from the input creators and annihilators. The second term is the input CalculatorComplex transformed according to the valid order of creators and annihilators.
- Parameters:
creators (List[int]) -- The creator indices to have in the instance of self.
annihilators (List[int]) -- The annihilators indices to have in the instance of self.
value (CalculatorComplex) -- The CalculatorComplex to transform.
- Returns:
The valid instance of self and the corresponding transformed CalculatorComplex.
- Return type:
(self, CalculatorComplex)
- Raises:
TypeError -- Value is not CalculatorComplex.
ValueError -- Indices given in either creators or annihilators contain a double index specification (only applicable to fermionic objects).
- creators()
Return list of creator indices.
- Returns:
A list of the corresponding creator indices.
- Return type:
List[int]
- current_number_modes()
Returns the maximal number of modes self acts on.
Self acts on a state space of unknown dimension. There is only a lower bound of the dimension or number of modes based on the maximal mode the product of operators in the index acts on. For example an index consisting of one creator acting on mode 0 would have a current_number_modes of one. An index consisting of one annhihilator acting on 3 would have current_number_modes of four.
- Returns:
The maximal number of modes self acts on.
- Return type:
int
- static current_version()
Returns the current version of the struqture library .
- Returns:
The current version of the library.
- Return type:
str
- static from_bincode(input)
Convert the bincode representation of the object to an instance using the [bincode] crate.
- Parameters:
input (bytearray) -- The serialized object (in [bincode] form).
- Returns:
The deserialized Spin System.
- Raises:
TypeError -- Input cannot be converted to byte array.
ValueError -- Input cannot be deserialized.
- static from_json(input)
Convert the json representation of the object to an instance.
- Parameters:
input (str) -- The serialized object in json form.
- Returns:
The deserialized object.
- Raises:
ValueError -- Input cannot be deserialized.
- static from_string(input)
Convert a string representation of the object to an instance.
- Parameters:
input (str) -- The serialized index in str representation.
- Returns:
The converted object.
- Return type:
self
- Raises:
ValueError -- Input cannot be converted from str.
- hermitian_conjugate()
Return the hermitian conjugate of self and its prefactor.
- Returns:
The hermitian conjugate of self and the potential sign it has picked up.
- Return type:
(self, float)
- is_natural_hermitian()
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:
Whether self is naturally hermitian or not.
- Return type:
bool
- static json_schema()
Return the JsonSchema for the json serialisation of the class.
- Returns:
The json schema serialized to json
- Return type:
str
- min_supported_version()
Return the minimum version of struqture that supports this object.
- Returns:
The minimum version of the struqture library to deserialize this object.
- Return type:
str
- number_annihilators()
Get the number of annihilator indices of self.
- Returns:
The number of annihilator indices in self.
- Return type:
int
- number_creators()
Get the number of creator indices of self.
- Returns:
The number of creator indices in self.
- Return type:
int
- remap_modes(reordering_dictionary)
Remap modes according to an input dictionary.
- Parameters:
reordering_dictionary (dict)
- Returns:
(Self, CalculatorComplex) - The instance of Self with modes remapped, and the sign resulting from symmetry/antisymmetry.
- Raises:
ValueError -- Input reordering dictionary is not a permutation of the indices.
- to_bincode()
Return the bincode representation of the object using the [bincode] crate.
- Returns:
The serialized object (in [bincode] form).
- Return type:
bytearray
- Raises:
ValueError -- Cannot serialize object to bytes.
- to_json()
Return the json representation of the object.
- Returns:
The serialized form of the object.
- Return type:
str
- Raises:
ValueError -- Cannot serialize object to json.
- class struqture_py.BosonSystem(number_bosons=None)
These are representations of systems of bosons.
BosonSystems are characterized by a BosonOperator to represent the hamiltonian of the spin system and an optional number of bosons.
- Parameters:
number_bosons (Optional[int]) -- The number of bosons in the BosonSystem.
- Returns:
The new BosonSystem with the input number of bosons.
- Return type:
self
Examples
import numpy.testing as npt import scipy.sparse as sp from qoqo_calculator_pyo3 import CalculatorComplex from struqture_py.bosons import BosonSystem, BosonProduct ssystem = BosonSystem(2) pp = BosonProduct([0], [1]) ssystem.add_operator_product(pp, 5.0) npt.assert_equal(ssystem.number_modes(), 2) npt.assert_equal(ssystem.get(pp), CalculatorComplex(5)) npt.assert_equal(ssystem.keys(), [pp])
- add_operator_product(key, value)
Add a new (key object, value Union[CalculatorComplex, CalculatorFloat]) pair to existing entries.
- Parameters:
key (Product type) -- The key object
- Raises:
TypeError -- Value is not CalculatorComplex or CalculatorFloat.
ValueError -- Product could not be constructed.
ValueError -- Error in add_operator_product function of self.
- current_number_modes()
Return maximum index in self.
- Returns:
Maximum index.
- Return type:
int
- static current_version()
Returns the current version of the struqture library .
- Returns:
The current version of the library.
- Return type:
str
- empty_clone(capacity=None)
Return an instance of self that has no entries but clones all other properties, with the given capacity.
- Parameters:
capacity (Optional[int]) -- The capacity of the new instance to create.
- Returns:
An empty clone with the same properties as self, with the given capacity.
- Return type:
self
- static from_bincode(input)
Convert the bincode representation of self to an instance using the [bincode] crate.
- Parameters:
input (bytearray) -- The serialized object (in [bincode] form).
- Returns:
The deserialized object.
- Raises:
TypeError -- Input cannot be converted to byte array.
ValueError -- Input cannot be deserialized.
- static from_json(input)
Convert the json representation of self to an instance.
- Parameters:
input (str) -- The serialized object in json form.
- Returns:
The deserialized object.
- Raises:
ValueError -- Input cannot be deserialized.
- get(key)
Get the coefficient corresponding to the key.
- Parameters:
key -- Product to get the value of.
- Returns:
Value at key (or 0.0).
- Return type:
CalculatorComplex
- Raises:
ValueError -- Product could not be constructed from key.
- hermitian_conjugate()
Return the hermitian conjugate of self.
- Returns:
The hermitian conjugate of self.
- Return type:
self
- is_empty()
Return true if self contains no values.
- Returns:
Whether self is empty or not.
- Return type:
bool
- static json_schema()
Return the JsonSchema for the json serialisation of the class.
- Returns:
The json schema serialized to json
- Return type:
str
- keys()
Return a list of the unsorted keys in self.
- Returns:
The sequence of keys of the self.
- Return type:
List[OperatorProduct]
- min_supported_version()
Return the minimum version of struqture that supports this object.
- Returns:
The minimum version of the struqture library to deserialize this object.
- Return type:
str
- number_modes()
Return the number_modes input of self.
- Returns:
The number of modes in self.
- Return type:
int
- remove(key)
Remove the value of the input key.
- Parameters:
key -- The key of the value to remove.
- Raises:
ValueError -- Product could not be constructed.
- separate_into_n_terms(number_creators_annihilators)
Separate self into an operator with the terms of given number of creation and annihilation operators and an operator with the remaining operations.
- Parameters:
number_creators_annihilators (Tuple[int, int]) -- Number of modes to filter for in the keys.
- Returns:
Operator with the noise terms where the number of creation and annihilation operators matches the number of spins the operator product acts on and Operator with all other contributions.
- Return type:
Tuple[Self, Self]
- Raises:
ValueError -- Error in adding terms to return values.
- set(key, value)
Overwrite an existing entry or set a new entry in self.
- Parameters:
key (Product type) -- The key to set.
value (Union[CalculatorComplex, CalculatorFloat]) -- The value to set.
- Returns:
Key existed if this is not None, and this is the value it had before it was overwritten.
- Return type:
Optional[Union[CalculatorComplex, CalculatorFloat]]
- Raises:
ValueError -- Product could not be constructed.
- to_bincode()
Return the bincode representation of self using the [bincode] crate.
- Returns:
The serialized object (in [bincode] form).
- Return type:
bytearray
- Raises:
ValueError -- Cannot serialize object to bytes.
- to_json()
Return the json representation of self.
- Returns:
The serialized form of self.
- Return type:
str
- Raises:
ValueError -- Cannot serialize object to json.
- truncate(threshold)
Truncate self by returning a copy without entries under a threshold.
- Parameters:
threshold (float) -- The threshold for inclusion.
- Returns:
The truncated version of self.
- Return type:
self
- values()
Return unsorted values in self.
- Returns:
The sequence of values of self.
- Return type:
List[Union[CalculatorComplex, CalculatorFloat]]
- class struqture_py.DecoherenceProduct
These are combinations of SingleDecoherenceOperators on specific qubits.
DecoherenceProducts act in a noisy system. They are representation of products of decoherence matrices acting on qubits in order to build the terms of a hamiltonian. For instance, to represent the term \(\sigma_0^{x}\) \(\sigma_2^{z}\):
DecoherenceProduct().x(0).z(2).
DecoherenceProduct is supposed to be used as input for the function add_noise, for instance in the spin system classes SpinLindbladOpenSystem, SpinLindbladNoiseSystem or SpinLindbladNoiseOperator, or in the mixed systems as part of MixedDecoherenceProduct <mixed_systems.MixedDecoherenceProduct>.
- Returns:
The new, empty DecoherenceProduct.
- Return type:
self
Examples
import numpy.testing as npt from struqture_py.spins import DecoherenceProduct dp = DecoherenceProduct().x(0).iy(1).z(2) dp = dp.set_pauli(3, "X") npt.assert_equal(dp.get(1), "iY") npt.assert_equal(dp.keys(), [0, 1, 2, 3])
- concatenate(other)
Return the concatenation of two objects of type self with no overlapping qubits.
- Parameters:
other (self) -- The object to concatenate self with.
- Returns:
A list of the corresponding creator indices.
- Return type:
List[int]
- Raises:
ValueError -- The two objects could not be concatenated.
- current_number_spins()
Return maximum index in self.
- Returns:
Maximum index.
- Return type:
int
- static current_version()
Returns the current version of the struqture library .
- Returns:
The current version of the library.
- Return type:
str
- static from_bincode(input)
Convert the bincode representation of the object to an instance using the [bincode] crate.
- Parameters:
input (bytearray) -- The serialized object (in [bincode] form).
- Returns:
The deserialized Spin System.
- Raises:
TypeError -- Input cannot be converted to byte array.
ValueError -- Input cannot be deserialized.
- static from_json(input)
Convert the json representation of the object to an instance.
- Parameters:
input (str) -- The serialized object in json form.
- Returns:
The deserialized object.
- Raises:
ValueError -- Input cannot be deserialized.
- static from_string(input)
Convert a string representation of the object to an instance.
- Parameters:
input (str) -- The serialized index in str representation.
- Returns:
The converted object.
- Return type:
self
- Raises:
ValueError -- Input cannot be converted from str.
- get(index)
Get the pauli matrix corresponding to the index.
- Parameters:
index (int) -- Index of get object.
- Returns:
The key's corresponding value (if it exists).
- Return type:
Optional[str]
- hermitian_conjugate()
Return the hermitian conjugate of self and its prefactor.
- Returns:
The hermitian conjugate of self and the potential sign it has picked up.
- Return type:
(self, float)
- is_empty()
Return whether self is empty or not.
- Returns:
Whether self is empty or not.
- Return type:
bool
- is_natural_hermitian()
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:
Whether self is naturally hermitian or not.
- Return type:
bool
- iy(index)
Set a new entry for SingleDecoherenceOperator iY in the internal dictionary.
- Parameters:
index (int) -- Index of set object.
- Returns:
The DecoherenceProduct with the new entry.
- Return type:
- jordan_wigner()
Transform the given spin object into a fermionic object using the Jordan Wigner mapping.
- static json_schema()
Return the JsonSchema for the json serialisation of the class.
- Returns:
The json schema serialized to json
- Return type:
str
- keys()
Return a list of the unsorted keys in self.
- Returns:
The sequence of qubit index keys of self.
- Return type:
List[int]
- min_supported_version()
Return the minimum version of struqture that supports this object.
- Returns:
The minimum version of the struqture library to deserialize this object.
- Return type:
str
- static multiply(left, right)
Multiplication function for a self-typed object by a self-typed object.
- Parameters:
left (self) -- Left-hand self typed object to be multiplied.
right (self) -- Right-hand self typed object to be multiplied.
- Returns:
The multiplied objects and the resulting prefactor.
- Return type:
(self, complex)
- remap_qubits(mapping)
Remap the qubits in a new instance of self (returned).
- Parameters:
mapping (Dict[int, int]) -- The map containing the {qubit: qubit} mapping to use.
- Returns:
The new instance of self with the qubits remapped.
- Return type:
self
- set_pauli(index, pauli)
Set a new entry in the internal_map. This function consumes self.
- Parameters:
index (int) -- Index of set object.
pauli (str) -- Value of set object.
- Returns:
The entry was correctly set and the DecoherenceProduct is returned.
- Return type:
self
- to_bincode()
Return the bincode representation of the object using the [bincode] crate.
- Returns:
The serialized object (in [bincode] form).
- Return type:
bytearray
- Raises:
ValueError -- Cannot serialize object to bytes.
- to_json()
Return the json representation of the object.
- Returns:
The serialized form of the object.
- Return type:
str
- Raises:
ValueError -- Cannot serialize object to json.
- x(index)
Set a new entry for SingleDecoherenceOperator X in the internal dictionary.
- Parameters:
index (int) -- Index of set object.
- Returns:
The DecoherenceProduct with the new entry.
- Return type:
- z(index)
Set a new entry for SingleDecoherenceOperator Z in the internal dictionary.
- Parameters:
index (int) -- Index of set object.
- Returns:
The DecoherenceProduct with the new entry.
- Return type:
- class struqture_py.FermionHamiltonianSystem(number_fermions=None)
These are representations of systems of fermions.
FermionHamiltonianSystems are characterized by a FermionOperator to represent the hamiltonian of the spin system and an optional number of fermions.
- Parameters:
number_fermions (Optional[int]) -- The number of fermions in the FermionHamiltonianSystem.
- Returns:
The new FermionHamiltonianSystem with the input number of fermions.
- Return type:
self
Examples
import numpy.testing as npt import scipy.sparse as sp from qoqo_calculator_pyo3 import CalculatorComplex from struqture_py.fermions import FermionHamiltonianSystem, HermitianFermionProduct ssystem = FermionHamiltonianSystem(2) pp = HermitianFermionProduct([0], [0]) ssystem.add_operator_product(pp, 5.0) npt.assert_equal(ssystem.number_modes(), 2) npt.assert_equal(ssystem.get(pp), CalculatorComplex(5)) npt.assert_equal(ssystem.keys(), [pp])
- add_operator_product(key, value)
Add a new (key object, value Union[CalculatorComplex, CalculatorFloat]) pair to existing entries.
- Parameters:
key (Product type) -- The key object
- Raises:
TypeError -- Value is not CalculatorComplex or CalculatorFloat.
ValueError -- Product could not be constructed.
ValueError -- Error in add_operator_product function of self.
- current_number_modes()
Return maximum index in self.
- Returns:
Maximum index.
- Return type:
int
- static current_version()
Returns the current version of the struqture library .
- Returns:
The current version of the library.
- Return type:
str
- empty_clone(capacity=None)
Return an instance of self that has no entries but clones all other properties, with the given capacity.
- Parameters:
capacity (Optional[int]) -- The capacity of the new instance to create.
- Returns:
An empty clone with the same properties as self, with the given capacity.
- Return type:
self
- static from_bincode(input)
Convert the bincode representation of self to an instance using the [bincode] crate.
- Parameters:
input (bytearray) -- The serialized object (in [bincode] form).
- Returns:
The deserialized object.
- Raises:
TypeError -- Input cannot be converted to byte array.
ValueError -- Input cannot be deserialized.
- static from_json(input)
Convert the json representation of self to an instance.
- Parameters:
input (str) -- The serialized object in json form.
- Returns:
The deserialized object.
- Raises:
ValueError -- Input cannot be deserialized.
- get(key)
Get the coefficient corresponding to the key.
- Parameters:
key -- Product to get the value of.
- Returns:
Value at key (or 0.0).
- Return type:
CalculatorComplex
- Raises:
ValueError -- Product could not be constructed from key.
- hermitian_conjugate()
Return the hermitian conjugate of self.
- Returns:
The hermitian conjugate of self.
- Return type:
self
- is_empty()
Return true if self contains no values.
- Returns:
Whether self is empty or not.
- Return type:
bool
- jordan_wigner()
Transform the given fermionic object into a spin object using the Jordan Wigner mapping.
- static json_schema()
Return the JsonSchema for the json serialisation of the class.
- Returns:
The json schema serialized to json
- Return type:
str
- keys()
Return a list of the unsorted keys in self.
- Returns:
The sequence of keys of the self.
- Return type:
List[OperatorProduct]
- min_supported_version()
Return the minimum version of struqture that supports this object.
- Returns:
The minimum version of the struqture library to deserialize this object.
- Return type:
str
- number_modes()
Return the number_modes input of self.
- Returns:
The number of modes in self.
- Return type:
int
- remove(key)
Remove the value of the input key.
- Parameters:
key -- The key of the value to remove.
- Raises:
ValueError -- Product could not be constructed.
- separate_into_n_terms(number_creators_annihilators)
Separate self into an operator with the terms of given number of creation and annihilation operators and an operator with the remaining operations.
- Parameters:
number_creators_annihilators (Tuple[int, int]) -- Number of modes to filter for in the keys.
- Returns:
Operator with the noise terms where the number of creation and annihilation operators matches the number of spins the operator product acts on and Operator with all other contributions.
- Return type:
Tuple[Self, Self]
- Raises:
ValueError -- Error in adding terms to return values.
- set(key, value)
Overwrite an existing entry or set a new entry in self.
- Parameters:
key (Product type) -- The key to set.
value (Union[CalculatorComplex, CalculatorFloat]) -- The value to set.
- Returns:
Key existed if this is not None, and this is the value it had before it was overwritten.
- Return type:
Optional[Union[CalculatorComplex, CalculatorFloat]]
- Raises:
ValueError -- Product could not be constructed.
- to_bincode()
Return the bincode representation of self using the [bincode] crate.
- Returns:
The serialized object (in [bincode] form).
- Return type:
bytearray
- Raises:
ValueError -- Cannot serialize object to bytes.
- to_json()
Return the json representation of self.
- Returns:
The serialized form of self.
- Return type:
str
- Raises:
ValueError -- Cannot serialize object to json.
- truncate(threshold)
Truncate self by returning a copy without entries under a threshold.
- Parameters:
threshold (float) -- The threshold for inclusion.
- Returns:
The truncated version of self.
- Return type:
self
- values()
Return unsorted values in self.
- Returns:
The sequence of values of self.
- Return type:
List[Union[CalculatorComplex, CalculatorFloat]]
- class struqture_py.FermionLindbladNoiseSystem(number_fermions=None)
These are representations of noisy systems of fermions.
In a FermionLindbladNoiseSystem is characterized by a FermionLindbladNoiseOperator to represent the hamiltonian of the system, and an optional number of fermions.
- Parameters:
number_fermions (Optional[int]) -- The number of fermions in the FermionLindbladNoiseSystem.
- Returns:
The new FermionLindbladNoiseSystem with the input number of fermions.
- Return type:
self
Examples
import numpy.testing as npt import scipy.sparse as sp from qoqo_calculator_pyo3 import CalculatorComplex from struqture_py.fermions import FermionLindbladNoiseSystem, FermionProduct slns = FermionLindbladNoiseSystem() dp = FermionProduct([0], [1]) slns.add_operator_product((dp, dp), 2.0) npt.assert_equal(slns.current_number_modes(), 2) npt.assert_equal(slns.get((dp, dp)), CalculatorComplex(2))
- add_operator_product(key, value)
Adds a new (key object, CalculatorComplex) pair to existing entries.
- Parameters:
key (Tuple[Product type, Product type]) -- The key of the value to add.
value (CalculatorComplex) -- The value to add.
- Raises:
TypeError -- Value is not CalculatorComplex or CalculatorFloat.
ValueError -- Left-hand product could not be constructed.
ValueError -- Right-hand product could not be constructed.
ValueError -- Error in add_operator_product function of self.
- current_number_modes()
Return maximum index in object.
- Returns:
Maximum index.
- Return type:
int
- static current_version()
Returns the current version of the struqture library .
- Returns:
The current version of the library.
- Return type:
str
- empty_clone(capacity=None)
Return an instance of self that has no entries but clones all other properties, with the given capacity.
- Parameters:
capacity -- The capacity of the object to create.
- Returns:
An empty clone with the same properties as self, with the given capacity.
- Return type:
self
- static from_bincode(input)
Convert the bincode representation of the object to an instance using the [bincode] crate.
- Parameters:
input (bytearray) -- The serialized object (in [bincode] form).
- Returns:
The deserialized object.
- Raises:
TypeError -- Input cannot be converted to byte array.
ValueError -- Input cannot be deserialized.
- static from_json(input)
Convert the json representation of the object to an instance.
- Parameters:
input (str) -- The serialized object in json form.
- Returns:
The deserialized object.
- Raises:
ValueError -- Input cannot be deserialized.
- get(key)
Get the coefficient corresponding to the key.
- Parameters:
key (Tuple[Product type, Product type]) -- Product to get the value of.
- Returns:
Value at key (or 0.0).
- Return type:
CalculatorComplex
- Raises:
ValueError -- Left-hand product could not be constructed from key.
ValueError -- Right-hand product could not be constructed from key.
- is_empty()
Return true if object contains no values.
- Returns:
Whether self is empty or not.
- Return type:
bool
- jordan_wigner()
Transform the given fermionic object into a spin object using the Jordan Wigner mapping.
- static json_schema()
Return the JsonSchema for the json serialisation of the class.
- Returns:
The json schema serialized to json
- Return type:
str
- keys()
Return unsorted keys in self.
- Returns:
The sequence of keys of self.
- Return type:
List[(OperatorProduct, OperatorProduct)]
- min_supported_version()
Return the minimum version of struqture that supports this object.
- Returns:
The minimum version of the struqture library to deserialize this object.
- Return type:
str
- number_modes()
Return the number_modes input of self.
- Returns:
The number of modes in self.
- Return type:
int
- remove(key)
Remove the value of the input object key.
- Parameters:
key (Tuple[Product type, Product type]) -- The key of the value to remove.
- Returns:
Key existed if this is not None, and this is the value it had before it was removed.
- Return type:
Optional[CalculatorComplex]
- Raises:
ValueError -- Left-hand Product could not be constructed.
ValueError -- Right-hand Product could not be constructed.
- separate_into_n_terms(number_creators_annihilators_left, number_creators_annihilators_right)
Separate self into an operator with the terms of given number of creation and annihilation operators and an operator with the remaining operations.
- Parameters:
number_creators_annihilators_left (Tuple[int, int]) -- Number of creators and number of annihilators to filter for in the left term of the keys.
number_creators_annihilators_right (Tuple[int, int]) -- Number of creators and number of annihilators to filter for in the right term of the keys.
- Returns:
Operator with the noise terms where the number of creation and annihilation operators matches the number of spins the operator product acts on and Operator with all other contributions.
- Return type:
Tuple[FermionLindbladNoiseSystem, FermionLindbladNoiseSystem]
- Raises:
ValueError -- Error in adding terms to return values.
- set(key, value)
Overwrite an existing entry or set a new entry in self.
- Parameters:
key (Tuple[Product type, Product type]) -- The key of the value to set.
value (CalculatorComplex) -- The value to set.
- Returns:
Key existed if this is not None, and this is the value it had before it was overwritten.
- Return type:
Optional[CalculatorComplex]
- Raises:
ValueError -- Left-hand Product could not be constructed.
ValueError -- Right-hand Product could not be constructed.
- to_bincode()
Return the bincode representation of the object using the [bincode] crate.
- Returns:
The serialized object (in [bincode] form).
- Return type:
bytearray
- Raises:
ValueError -- Cannot serialize object to bytes.
- to_json()
Return the json representation of the object.
- Returns:
The serialized form of the object.
- Return type:
str
- Raises:
ValueError -- Cannot serialize object to json.
- truncate(threshold)
Truncate self by returning a copy without entries under a threshold.
- Parameters:
threshold -- The threshold for inclusion.
- Returns:
The truncated version of self.
- Return type:
self
- values()
Return unsorted values in self.
- Returns:
The sequence of values of self.
- Return type:
List[CalculatorComplex]
- class struqture_py.FermionLindbladOpenSystem(number_fermions=None)
These are representations of noisy systems of fermions.
In a FermionLindbladOpenSystem is characterized by a FermionLindbladOpenOperator to represent the hamiltonian of the system, and an optional number of fermions.
- Parameters:
number_fermions (Optional[int]) -- The number of fermions in the FermionLindbladOpenSystem.
- Returns:
The new FermionLindbladOpenSystem with the input number of fermions.
- Return type:
self
Examples
import numpy.testing as npt import scipy.sparse as sp from qoqo_calculator_pyo3 import CalculatorComplex from struqture_py.fermions import FermionLindbladOpenSystem, FermionProduct slns = FermionLindbladOpenSystem() dp = FermionProduct([0], [1]) slns.system_add_operator_product(dp, 2.0) npt.assert_equal(slns.current_number_modes(), 2) npt.assert_equal(slns.system().get(dp), CalculatorComplex(2))
- current_number_modes()
Return maximum index in object.
- Returns:
Maximum index.
- Return type:
int
- static current_version()
Returns the current version of the struqture library .
- Returns:
The current version of the library.
- Return type:
str
- empty_clone()
Return an instance of self that has no entries but clones all other properties, with the given capacity.
- Returns:
An empty clone with the same properties as self, with the given capacity.
- Return type:
self
- static from_bincode(input)
Convert the bincode representation of the object to an instance using the [bincode] crate.
- Parameters:
input (bytearray) -- The serialized object (in [bincode] form).
- Returns:
The deserialized object.
- Raises:
TypeError -- Input cannot be converted to byte array.
ValueError -- Input cannot be deserialized.
- static from_json(input)
Convert the json representation of the object to an instance.
- Parameters:
input (str) -- The serialized object in json form.
- Returns:
The deserialized object.
- Raises:
ValueError -- Input cannot be deserialized.
- static group(system, noise)
Take a tuple of a system term and a noise term and combines them to be a OpenSystem.
- Parameters:
system -- The system to have in the new instance.
noise -- The noise to have in the new instance.
- Returns:
The OpenSystem with input system and noise terms.
- Return type:
self
- Raises:
ValueError -- System could not be constructed.
ValueError -- Noise could not be constructed.
ValueError -- Grouping could not be constructed.
- jordan_wigner()
Transform the given fermionic object into a spin object using the Jordan Wigner mapping.
- static json_schema()
Return the JsonSchema for the json serialisation of the class.
- Returns:
The json schema serialized to json
- Return type:
str
- min_supported_version()
Return the minimum version of struqture that supports this object.
- Returns:
The minimum version of the struqture library to deserialize this object.
- Return type:
str
- noise()
Return the noise part of self.
- Returns:
The noise of self.
- Return type:
Noise type
- noise_add_operator_product(key, value)
Add a new entry to the system of the open system.
- Parameters:
key (Tuple[Product type, Product type]) -- Tuple of Products of set object.
value (CalculatorComplex) -- Value of set object.
- Returns:
The OpenSystem with the new entry.
- Return type:
OpenSystem
- Raises:
ValueError -- Left key element cannot be converted to product.
ValueError -- Right key element cannot be converted to product.
TypeError -- Value cannot be converted to CalculatorComplex.
- noise_get(key)
Get the CalculatorComplex coefficient corresponding to the key.
- Parameters:
key (Tuple[Product type, Product type]) -- Tuple of Products of set object.
- Returns:
Value at key (or 0.0).
- Return type:
CalculatorComplex
- Raises:
ValueError -- Left key element cannot be converted to product.
ValueError -- Right key element cannot be converted to product.
- noise_set(key, value)
Set a new entry in the noise of the open system.
- Parameters:
key (Tuple[Product type, Product type]) -- Tuple of Products of set object.
value (CalculatorComplex) -- CalculatorComplex value of set object.
- Returns:
The OpenSystem with the new entry.
- Return type:
OpenSystem
- Raises:
ValueError -- Left key element cannot be converted to product.
ValueError -- Right key element cannot be converted to product.
TypeError -- Value cannot be converted to Union[CalculatorComplex, CalculatorFloat].
- number_modes()
Return the number_modes input of self.
- Returns:
The number of modes in self.
- Return type:
int
- system()
Return the system part of self.
- Returns:
The system of self.
- Return type:
System type
- system_add_operator_product(key, value)
Add a new entry to the system of the open system.
- Parameters:
key (Product type) -- Product key of set object.
value (Union[CalculatorComplex, CalculatorFloat]) -- Value of set object.
- Returns:
The OpenSystem with the new entry.
- Return type:
OpenSystem
- Raises:
ValueError -- key element cannot be converted to product.
TypeError -- Value cannot be converted to Union[CalculatorComplex, CalculatorFloat].
- system_get(key)
Get the CalculatorComplex or CalculatorFloat coefficient corresponding to the key.
- Parameters:
key (Product type) -- Product key of set object.
- Returns:
Value at key (or 0.0).
- Return type:
CalculatorComplex or CalculatorFloat
- Raises:
ValueError -- key element cannot be converted to product.
- system_set(key, value)
Set a new entry in the system of the open system.
- Parameters:
key (Product type) -- Product key of set object.
value (Union[CalculatorComplex, CalculatorFloat]) -- Value of set object.
- Returns:
The OpenSystem with the new entry.
- Return type:
OpenSystem
- Raises:
ValueError -- key element cannot be converted to product.
TypeError -- Value cannot be converted to Union[CalculatorComplex, CalculatorFloat].
- to_bincode()
Return the bincode representation of the object using the [bincode] crate.
- Returns:
The serialized object (in [bincode] form).
- Return type:
bytearray
- Raises:
ValueError -- Cannot serialize object to bytes.
- to_json()
Return the json representation of the object.
- Returns:
The serialized form of the object.
- Return type:
str
- Raises:
ValueError -- Cannot serialize object to json.
- truncate(threshold)
Truncate self by returning a copy without entries under a threshold.
- Parameters:
threshold -- The threshold for inclusion.
- Returns:
The truncated version of self.
- Return type:
self
- ungroup()
Return a tuple of the system and the noise of self.
- Returns:
The system and noise of self.
- Return type:
(System, Noise)
- class struqture_py.FermionProduct(creators, annihilators)
A product of fermionic creation and annihilation operators.
The FermionProduct is used as an index for non-hermitian, normal ordered fermionic operators. A fermionic operator can be written as a sum over normal ordered products of creation and annihilation operators. The FermionProduct is used as an index when setting or adding new summands to a fermionic operator and when querrying the weight of a product of operators in the sum.
- Parameters:
creators (List[int]) -- List of creator sub-indices.
annihilators (List[int]) -- List of annihilator sub-indices.
- Returns:
The new (empty) FermionProduct.
- Return type:
self
Examples
from struqture_py.fermions import FermionProduct import numpy.testing as npt # For instance, to represent $c_0a_0$ fp = FermionProduct([0], [0]) npt.assert_equal(fp.creators(), [0]) npt.assert_equal(fp.annihilators(), [0])
- annihilators()
Return list of annihilator indices.
- Returns:
A list of the corresponding annihilator indices.
- Return type:
List[int]
- create_valid_pair(annihilators, value)
Create valid pair of index and value to be set in an operator.
The first item is the valid instance of self created from the input creators and annihilators. The second term is the input CalculatorComplex transformed according to the valid order of creators and annihilators.
- Parameters:
creators (List[int]) -- The creator indices to have in the instance of self.
annihilators (List[int]) -- The annihilators indices to have in the instance of self.
value (CalculatorComplex) -- The CalculatorComplex to transform.
- Returns:
The valid instance of self and the corresponding transformed CalculatorComplex.
- Return type:
(self, CalculatorComplex)
- Raises:
TypeError -- Value is not CalculatorComplex.
ValueError -- Indices given in either creators or annihilators contain a double index specification (only applicable to fermionic objects).
- creators()
Return list of creator indices.
- Returns:
A list of the corresponding creator indices.
- Return type:
List[int]
- current_number_modes()
Returns the maximal number of modes self acts on.
Self acts on a state space of unknown dimension. There is only a lower bound of the dimension or number of modes based on the maximal mode the product of operators in the index acts on. For example an index consisting of one creator acting on mode 0 would have a current_number_modes of one. An index consisting of one annhihilator acting on 3 would have current_number_modes of four.
- Returns:
The maximal number of modes self acts on.
- Return type:
int
- static current_version()
Returns the current version of the struqture library .
- Returns:
The current version of the library.
- Return type:
str
- static from_bincode(input)
Convert the bincode representation of the object to an instance using the [bincode] crate.
- Parameters:
input (bytearray) -- The serialized object (in [bincode] form).
- Returns:
The deserialized Spin System.
- Raises:
TypeError -- Input cannot be converted to byte array.
ValueError -- Input cannot be deserialized.
- static from_json(input)
Convert the json representation of the object to an instance.
- Parameters:
input (str) -- The serialized object in json form.
- Returns:
The deserialized object.
- Raises:
ValueError -- Input cannot be deserialized.
- static from_string(input)
Convert a string representation of the object to an instance.
- Parameters:
input (str) -- The serialized index in str representation.
- Returns:
The converted object.
- Return type:
self
- Raises:
ValueError -- Input cannot be converted from str.
- hermitian_conjugate()
Return the hermitian conjugate of self and its prefactor.
- Returns:
The hermitian conjugate of self and the potential sign it has picked up.
- Return type:
(self, float)
- is_natural_hermitian()
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:
Whether self is naturally hermitian or not.
- Return type:
bool
- jordan_wigner()
Transform the given fermionic object into a spin object using the Jordan Wigner mapping.
- static json_schema()
Return the JsonSchema for the json serialisation of the class.
- Returns:
The json schema serialized to json
- Return type:
str
- min_supported_version()
Return the minimum version of struqture that supports this object.
- Returns:
The minimum version of the struqture library to deserialize this object.
- Return type:
str
- number_annihilators()
Get the number of annihilator indices of self.
- Returns:
The number of annihilator indices in self.
- Return type:
int
- number_creators()
Get the number of creator indices of self.
- Returns:
The number of creator indices in self.
- Return type:
int
- remap_modes(reordering_dictionary)
Remap modes according to an input dictionary.
- Parameters:
reordering_dictionary (dict)
- Returns:
(Self, CalculatorComplex) - The instance of Self with modes remapped, and the sign resulting from symmetry/antisymmetry.
- Raises:
ValueError -- Input reordering dictionary is not a permutation of the indices.
- to_bincode()
Return the bincode representation of the object using the [bincode] crate.
- Returns:
The serialized object (in [bincode] form).
- Return type:
bytearray
- Raises:
ValueError -- Cannot serialize object to bytes.
- to_json()
Return the json representation of the object.
- Returns:
The serialized form of the object.
- Return type:
str
- Raises:
ValueError -- Cannot serialize object to json.
- class struqture_py.FermionSystem(number_fermions=None)
These are representations of systems of fermions.
FermionSystems are characterized by a FermionOperator to represent the hamiltonian of the spin system and an optional number of fermions.
- Parameters:
number_fermions (Optional[int]) -- The number of fermions in the FermionSystem.
- Returns:
The new FermionSystem with the input number of fermions.
- Return type:
self
Examples
import numpy.testing as npt import scipy.sparse as sp from qoqo_calculator_pyo3 import CalculatorComplex from struqture_py.fermions import FermionSystem, FermionProduct ssystem = FermionSystem(2) pp = FermionProduct([0], [0]) ssystem.add_operator_product(pp, 5.0) npt.assert_equal(ssystem.number_modes(), 2) npt.assert_equal(ssystem.get(pp), CalculatorComplex(5)) npt.assert_equal(ssystem.keys(), [pp])
- add_operator_product(key, value)
Add a new (key object, value Union[CalculatorComplex, CalculatorFloat]) pair to existing entries.
- Parameters:
key (Product type) -- The key object
- Raises:
TypeError -- Value is not CalculatorComplex or CalculatorFloat.
ValueError -- Product could not be constructed.
ValueError -- Error in add_operator_product function of self.
- current_number_modes()
Return maximum index in self.
- Returns:
Maximum index.
- Return type:
int
- static current_version()
Returns the current version of the struqture library .
- Returns:
The current version of the library.
- Return type:
str
- empty_clone(capacity=None)
Return an instance of self that has no entries but clones all other properties, with the given capacity.
- Parameters:
capacity (Optional[int]) -- The capacity of the new instance to create.
- Returns:
An empty clone with the same properties as self, with the given capacity.
- Return type:
self
- static from_bincode(input)
Convert the bincode representation of self to an instance using the [bincode] crate.
- Parameters:
input (bytearray) -- The serialized object (in [bincode] form).
- Returns:
The deserialized object.
- Raises:
TypeError -- Input cannot be converted to byte array.
ValueError -- Input cannot be deserialized.
- static from_json(input)
Convert the json representation of self to an instance.
- Parameters:
input (str) -- The serialized object in json form.
- Returns:
The deserialized object.
- Raises:
ValueError -- Input cannot be deserialized.
- get(key)
Get the coefficient corresponding to the key.
- Parameters:
key -- Product to get the value of.
- Returns:
Value at key (or 0.0).
- Return type:
CalculatorComplex
- Raises:
ValueError -- Product could not be constructed from key.
- hermitian_conjugate()
Return the hermitian conjugate of self.
- Returns:
The hermitian conjugate of self.
- Return type:
self
- is_empty()
Return true if self contains no values.
- Returns:
Whether self is empty or not.
- Return type:
bool
- jordan_wigner()
Transform the given fermionic object into a spin object using the Jordan Wigner mapping.
- static json_schema()
Return the JsonSchema for the json serialisation of the class.
- Returns:
The json schema serialized to json
- Return type:
str
- keys()
Return a list of the unsorted keys in self.
- Returns:
The sequence of keys of the self.
- Return type:
List[OperatorProduct]
- min_supported_version()
Return the minimum version of struqture that supports this object.
- Returns:
The minimum version of the struqture library to deserialize this object.
- Return type:
str
- number_modes()
Return the number_modes input of self.
- Returns:
The number of modes in self.
- Return type:
int
- remove(key)
Remove the value of the input key.
- Parameters:
key -- The key of the value to remove.
- Raises:
ValueError -- Product could not be constructed.
- separate_into_n_terms(number_creators_annihilators)
Separate self into an operator with the terms of given number of creation and annihilation operators and an operator with the remaining operations.
- Parameters:
number_creators_annihilators (Tuple[int, int]) -- Number of modes to filter for in the keys.
- Returns:
Operator with the noise terms where the number of creation and annihilation operators matches the number of spins the operator product acts on and Operator with all other contributions.
- Return type:
Tuple[Self, Self]
- Raises:
ValueError -- Error in adding terms to return values.
- set(key, value)
Overwrite an existing entry or set a new entry in self.
- Parameters:
key (Product type) -- The key to set.
value (Union[CalculatorComplex, CalculatorFloat]) -- The value to set.
- Returns:
Key existed if this is not None, and this is the value it had before it was overwritten.
- Return type:
Optional[Union[CalculatorComplex, CalculatorFloat]]
- Raises:
ValueError -- Product could not be constructed.
- to_bincode()
Return the bincode representation of self using the [bincode] crate.
- Returns:
The serialized object (in [bincode] form).
- Return type:
bytearray
- Raises:
ValueError -- Cannot serialize object to bytes.
- to_json()
Return the json representation of self.
- Returns:
The serialized form of self.
- Return type:
str
- Raises:
ValueError -- Cannot serialize object to json.
- truncate(threshold)
Truncate self by returning a copy without entries under a threshold.
- Parameters:
threshold (float) -- The threshold for inclusion.
- Returns:
The truncated version of self.
- Return type:
self
- values()
Return unsorted values in self.
- Returns:
The sequence of values of self.
- Return type:
List[Union[CalculatorComplex, CalculatorFloat]]
- class struqture_py.HermitianBosonProduct(creators, annihilators)
A product of bosonic creation and annihilation operators.
The HermitianBosonProduct is used as an index for non-hermitian, normal ordered bosonic operators. A bosonic operator can be written as a sum over normal ordered products of creation and annihilation operators. The HermitianBosonProduct is used as an index when setting or adding new summands to a bosonic operator and when querrying the weight of a product of operators in the sum.
- Parameters:
creators (List[int]) -- List of creator sub-indices.
annihilators (List[int]) -- List of annihilator sub-indices.
- Returns:
The new (empty) HermitianBosonProduct.
- Return type:
self
Examples
from struqture_py.bosons import HermitianBosonProduct import numpy.testing as npt # For instance, to represent $c_0a_0$ b_product = HermitianBosonProduct([0], [0]) npt.assert_equal(b_product.creators(), [0]) npt.assert_equal(b_product.annihilators(), [0])
- annihilators()
Return list of annihilator indices.
- Returns:
A list of the corresponding annihilator indices.
- Return type:
List[int]
- create_valid_pair(annihilators, value)
Create valid pair of index and value to be set in an operator.
The first item is the valid instance of self created from the input creators and annihilators. The second term is the input CalculatorComplex transformed according to the valid order of creators and annihilators.
- Parameters:
creators (List[int]) -- The creator indices to have in the instance of self.
annihilators (List[int]) -- The annihilators indices to have in the instance of self.
value (CalculatorComplex) -- The CalculatorComplex to transform.
- Returns:
The valid instance of self and the corresponding transformed CalculatorComplex.
- Return type:
(self, CalculatorComplex)
- Raises:
TypeError -- Value is not CalculatorComplex.
ValueError -- Indices given in either creators or annihilators contain a double index specification (only applicable to fermionic objects).
- creators()
Return list of creator indices.
- Returns:
A list of the corresponding creator indices.
- Return type:
List[int]
- current_number_modes()
Returns the maximal number of modes self acts on.
Self acts on a state space of unknown dimension. There is only a lower bound of the dimension or number of modes based on the maximal mode the product of operators in the index acts on. For example an index consisting of one creator acting on mode 0 would have a current_number_modes of one. An index consisting of one annhihilator acting on 3 would have current_number_modes of four.
- Returns:
The maximal number of modes self acts on.
- Return type:
int
- static current_version()
Returns the current version of the struqture library .
- Returns:
The current version of the library.
- Return type:
str
- static from_bincode(input)
Convert the bincode representation of the object to an instance using the [bincode] crate.
- Parameters:
input (bytearray) -- The serialized object (in [bincode] form).
- Returns:
The deserialized Spin System.
- Raises:
TypeError -- Input cannot be converted to byte array.
ValueError -- Input cannot be deserialized.
- static from_json(input)
Convert the json representation of the object to an instance.
- Parameters:
input (str) -- The serialized object in json form.
- Returns:
The deserialized object.
- Raises:
ValueError -- Input cannot be deserialized.
- static from_string(input)
Convert a string representation of the object to an instance.
- Parameters:
input (str) -- The serialized index in str representation.
- Returns:
The converted object.
- Return type:
self
- Raises:
ValueError -- Input cannot be converted from str.
- hermitian_conjugate()
Return the hermitian conjugate of self and its prefactor.
- Returns:
The hermitian conjugate of self and the potential sign it has picked up.
- Return type:
(self, float)
- is_natural_hermitian()
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:
Whether self is naturally hermitian or not.
- Return type:
bool
- static json_schema()
Return the JsonSchema for the json serialisation of the class.
- Returns:
The json schema serialized to json
- Return type:
str
- min_supported_version()
Return the minimum version of struqture that supports this object.
- Returns:
The minimum version of the struqture library to deserialize this object.
- Return type:
str
- number_annihilators()
Get the number of annihilator indices of self.
- Returns:
The number of annihilator indices in self.
- Return type:
int
- number_creators()
Get the number of creator indices of self.
- Returns:
The number of creator indices in self.
- Return type:
int
- remap_modes(reordering_dictionary)
Remap modes according to an input dictionary.
- Parameters:
reordering_dictionary (dict)
- Returns:
(Self, CalculatorComplex) - The instance of Self with modes remapped, and the sign resulting from symmetry/antisymmetry.
- Raises:
ValueError -- Input reordering dictionary is not a permutation of the indices.
- to_bincode()
Return the bincode representation of the object using the [bincode] crate.
- Returns:
The serialized object (in [bincode] form).
- Return type:
bytearray
- Raises:
ValueError -- Cannot serialize object to bytes.
- to_json()
Return the json representation of the object.
- Returns:
The serialized form of the object.
- Return type:
str
- Raises:
ValueError -- Cannot serialize object to json.
- class struqture_py.HermitianFermionProduct(creators, annihilators)
A product of fermionic creation and annihilation operators.
The HermitianFermionProduct is used as an index for non-hermitian, normal ordered fermionic operators. A fermionic operator can be written as a sum over normal ordered products of creation and annihilation operators. The HermitianFermionProduct is used as an index when setting or adding new summands to a fermionic operator and when querrying the weight of a product of operators in the sum.
- Parameters:
creators (List[int]) -- List of creator sub-indices.
annihilators (List[int]) -- List of annihilator sub-indices.
- Returns:
The new (empty) HermitianFermionProduct.
- Return type:
self
Examples
from struqture_py.fermions import HermitianFermionProduct import numpy.testing as npt # For instance, to represent $c_0a_1$ fp = HermitianFermionProduct([0], [0]) npt.assert_equal(fp.creators(), [0]) npt.assert_equal(fp.annihilators(), [0])
- annihilators()
Return list of annihilator indices.
- Returns:
A list of the corresponding annihilator indices.
- Return type:
List[int]
- create_valid_pair(annihilators, value)
Create valid pair of index and value to be set in an operator.
The first item is the valid instance of self created from the input creators and annihilators. The second term is the input CalculatorComplex transformed according to the valid order of creators and annihilators.
- Parameters:
creators (List[int]) -- The creator indices to have in the instance of self.
annihilators (List[int]) -- The annihilators indices to have in the instance of self.
value (CalculatorComplex) -- The CalculatorComplex to transform.
- Returns:
The valid instance of self and the corresponding transformed CalculatorComplex.
- Return type:
(self, CalculatorComplex)
- Raises:
TypeError -- Value is not CalculatorComplex.
ValueError -- Indices given in either creators or annihilators contain a double index specification (only applicable to fermionic objects).
- creators()
Return list of creator indices.
- Returns:
A list of the corresponding creator indices.
- Return type:
List[int]
- current_number_modes()
Returns the maximal number of modes self acts on.
Self acts on a state space of unknown dimension. There is only a lower bound of the dimension or number of modes based on the maximal mode the product of operators in the index acts on. For example an index consisting of one creator acting on mode 0 would have a current_number_modes of one. An index consisting of one annhihilator acting on 3 would have current_number_modes of four.
- Returns:
The maximal number of modes self acts on.
- Return type:
int
- static current_version()
Returns the current version of the struqture library .
- Returns:
The current version of the library.
- Return type:
str
- static from_bincode(input)
Convert the bincode representation of the object to an instance using the [bincode] crate.
- Parameters:
input (bytearray) -- The serialized object (in [bincode] form).
- Returns:
The deserialized Spin System.
- Raises:
TypeError -- Input cannot be converted to byte array.
ValueError -- Input cannot be deserialized.
- static from_json(input)
Convert the json representation of the object to an instance.
- Parameters:
input (str) -- The serialized object in json form.
- Returns:
The deserialized object.
- Raises:
ValueError -- Input cannot be deserialized.
- static from_string(input)
Convert a string representation of the object to an instance.
- Parameters:
input (str) -- The serialized index in str representation.
- Returns:
The converted object.
- Return type:
self
- Raises:
ValueError -- Input cannot be converted from str.
- hermitian_conjugate()
Return the hermitian conjugate of self and its prefactor.
- Returns:
The hermitian conjugate of self and the potential sign it has picked up.
- Return type:
(self, float)
- is_natural_hermitian()
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:
Whether self is naturally hermitian or not.
- Return type:
bool
- jordan_wigner()
Transform the given fermionic object into a spin object using the Jordan Wigner mapping.
- static json_schema()
Return the JsonSchema for the json serialisation of the class.
- Returns:
The json schema serialized to json
- Return type:
str
- min_supported_version()
Return the minimum version of struqture that supports this object.
- Returns:
The minimum version of the struqture library to deserialize this object.
- Return type:
str
- number_annihilators()
Get the number of annihilator indices of self.
- Returns:
The number of annihilator indices in self.
- Return type:
int
- number_creators()
Get the number of creator indices of self.
- Returns:
The number of creator indices in self.
- Return type:
int
- remap_modes(reordering_dictionary)
Remap modes according to an input dictionary.
- Parameters:
reordering_dictionary (dict)
- Returns:
(Self, CalculatorComplex) - The instance of Self with modes remapped, and the sign resulting from symmetry/antisymmetry.
- Raises:
ValueError -- Input reordering dictionary is not a permutation of the indices.
- to_bincode()
Return the bincode representation of the object using the [bincode] crate.
- Returns:
The serialized object (in [bincode] form).
- Return type:
bytearray
- Raises:
ValueError -- Cannot serialize object to bytes.
- to_json()
Return the json representation of the object.
- Returns:
The serialized form of the object.
- Return type:
str
- Raises:
ValueError -- Cannot serialize object to json.
- class struqture_py.HermitianMixedProduct(spins, bosons, fermions)
A mixed product of pauli products and boson products.
A PauliProduct <struqture_py.spins.PauliProduct> is a representation of products of pauli matrices acting on qubits. It is used in order to build the corresponding spin terms of a hamiltonian.
A BosonProduct <struqture_py.bosons.BosonProduct> is a product of bosonic creation and annihilation operators. It is used as an index for non-hermitian, normal ordered bosonic operators.
A FermionProduct <struqture_py.fermions.FermionProduct> is a product of bosonic creation and annihilation operators. It is used as an index for non-hermitian, normal ordered bosonic operators.
Note: For a physical system, the bosons (BosonProduct) are usually considered in presence of a system-spin part (PauliProduct) and a bath-spin part (PauliProduct), as shown in the example below.
- Parameters:
spins (List[PauliProduct]) -- Products of pauli operators acting on qubits.
bosons (List[BosonProduct]) -- Products of bosonic creation and annihilation operators.
fermions (List[FermionProduct]) -- Products of fermionic creation and annihilation operators.
- Returns:
a new HermitianMixedProduct with the input of spins, bosons and fermions.
- Return type:
- Raises:
ValueError -- if HermitianMixedProduct can not be constructed from the input.
Examples
from struqture_py.mixed_systems import HermitianMixedProduct from struqture_py.spins import PauliProduct from struqture_py.bosons import BosonProduct # For instance, to represent the terms $\sigma_0^{x} \sigma_2^{x}$ # and $\sigma_1^{x} \sigma_2^{x}$ mp_spins_system = PauliProduct().x(0).x(2) mp_spins_bath = PauliProduct().x(1).x(2) # For instance, to represent $a_1*a_1$ mp_bosons = BosonProduct([1], [1]) mp = HermitianMixedProduct([mp_spins_system, mp_spins_bath], [mp_bosons], []) npt.assert_equal(mp.spins(), [mp_spins_system, mp_spins_bath]) npt.assert_equal(mp.bosons(), [mp_bosons])
- bosons()
Get the boson products of self.
- Returns:
The boson products of self.
- Return type:
List[str]
- create_valid_pair(bosons, fermions, value)
Create a pair (HermitianMixedProduct, CalculatorComplex).
The first item is the valid HermitianMixedProduct created from the input creators and annihilators. The second term is the input CalculatorComplex transformed according to the valid order of creators and annihilators.
- Parameters:
creators -- The creator indices to have in the HermitianMixedProduct.
annihilators -- The annihilators indices to have in the HermitianMixedProduct.
value -- The CalculatorComplex to transform.
- Returns:
Tuple[self, CalculatorComplex] - The valid HermitianMixedProduct and the corresponding transformed CalculatorComplex.
- Raises:
ValueError -- Valid pair could not be constructed, pauli spins couldn't be converted from string.
ValueError -- Valid pair could not be constructed, bosons couldn't be converted from string.
ValueError -- Valid pair could not be constructed, fermions couldn't be converted from string.
TypeError -- Value cannot be converted to CalculatorComplex.
ValueError -- Valid pair could not be constructed.
- current_number_bosonic_modes()
Return the current number of bosonic modes each subsystem acts upon.
- Returns:
Number of bosonic modes in each spin sub-system.
- Return type:
List[int]
- current_number_fermionic_modes()
Return the current number of fermionic modes each subsystem acts upon.
- Returns:
Number of fermionic modes in each spin sub-system.
- Return type:
List[int]
- current_number_spins()
Return the current number of spins each subsystem acts upon.
- Returns:
Number of spins in each spin sub-system.
- Return type:
List[int]
- static current_version()
Returns the current version of the struqture library .
- Returns:
The current version of the library.
- Return type:
str
- fermions()
Get the fermion products of self.
- Returns:
The fermion products of self.
- Return type:
List[str]
- static from_bincode(input)
Convert the bincode representation of the object to an instance using the [bincode] crate.
- Parameters:
input (bytearray) -- The serialized object (in [bincode] form).
- Returns:
The deserialized Spin System.
- Raises:
TypeError -- Input cannot be converted to byte array.
ValueError -- Input cannot be deserialized.
- static from_json(input)
Convert the json representation of the object to an instance.
- Parameters:
input (str) -- The serialized object in json form.
- Returns:
The deserialized object.
- Raises:
ValueError -- Input cannot be deserialized.
- static from_string(input)
Convert a string representation of the object to an instance.
- Parameters:
input (str) -- The serialized index in str representation.
- Returns:
The converted object.
- Return type:
self
- Raises:
ValueError -- Input cannot be converted from str.
- hermitian_conjugate()
Return the hermitian conjugate of self and its prefactor.
- Returns:
The hermitian conjugate of self and the potential sign it has picked up.
- Return type:
(self, float)
- is_natural_hermitian()
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:
Whether self is naturally hermitian or not.
- Return type:
bool
- static json_schema()
Return the JsonSchema for the json serialisation of the class.
- Returns:
The json schema serialized to json
- Return type:
str
- min_supported_version()
Return the minimum version of struqture that supports this object.
- Returns:
The minimum version of the struqture library to deserialize this object.
- Return type:
str
- spins()
Get the spin products of self.
- Returns:
The spin products of self.
- Return type:
List[str]
- to_bincode()
Return the bincode representation of the object using the [bincode] crate.
- Returns:
The serialized object (in [bincode] form).
- Return type:
bytearray
- Raises:
ValueError -- Cannot serialize object to bytes.
- to_json()
Return the json representation of the object.
- Returns:
The serialized form of the object.
- Return type:
str
- Raises:
ValueError -- Cannot serialize object to json.
- class struqture_py.MixedDecoherenceProduct(spins, bosons, fermions)
A mixed product of pauli products and boson products.
A DecoherenceProduct <struqture_py.spins.DecoherenceProduct> is a representation of products of pauli matrices acting on qubits. It is used in order to build the corresponding spin terms of a hamiltonian.
A BosonProduct <struqture_py.bosons.BosonProduct> is a product of bosonic creation and annihilation operators. It is used as an index for non-hermitian, normal ordered bosonic operators.
A FermionProduct <struqture_py.fermions.FermionProduct> is a product of bosonic creation and annihilation operators. It is used as an index for non-hermitian, normal ordered bosonic operators.
Note: For a physical system, the bosons (BosonProduct) are usually considered in presence of a system-spin part (DecoherenceProduct) and a bath-spin part (DecoherenceProduct), as shown in the example below.
- Parameters:
spins (List[DecoherenceProduct]) -- products of pauli matrices acting on qubits.
bosons (List[BosonProduct]) -- products of bosonic creation and annihilation operators.
fermions (List[FermionProduct]) -- products of fermionic creation and annihilation operators.
- Returns:
a new MixedDecoherenceProduct with the input of spins, bosons and fermions.
- Return type:
- Raises:
ValueError -- if MixedDecoherenceProduct can not be constructed from the input.
Examples
from struqture_py.mixed_systems import MixedDecoherenceProduct from struqture_py.spins import DecoherenceProduct from struqture_py.bosons import BosonProduct # For instance, to represent the terms $\sigma_0^{x} \sigma_2^{x}$ # and $\sigma_1^{x} \sigma_2^{x}$ mp_spins_system = DecoherenceProduct().x(0).x(2) mp_spins_bath = DecoherenceProduct().x(1).x(2) # For instance, to represent $a_1*a_1$ mp_bosons = BosonProduct([1], [1]) mp = MixedDecoherenceProduct([mp_spins_system, mp_spins_bath], [mp_bosons], []) npt.assert_equal(mp.spins(), [mp_spins_system, mp_spins_bath]) npt.assert_equal(mp.bosons(), [mp_bosons])
- bosons()
Get the boson products of self.
- Returns:
The boson products of self.
- Return type:
List[str]
- create_valid_pair(bosons, fermions, value)
Create a pair (MixedDecoherenceProduct, CalculatorComplex).
The first item is the valid MixedDecoherenceProduct created from the input creators and annihilators. The second term is the input CalculatorComplex transformed according to the valid order of creators and annihilators.
- Parameters:
creators -- The creator indices to have in the MixedDecoherenceProduct.
annihilators -- The annihilators indices to have in the MixedDecoherenceProduct.
value -- The CalculatorComplex to transform.
- Returns:
Tuple[self, CalculatorComplex] - The valid MixedDecoherenceProduct and the corresponding transformed CalculatorComplex.
- Raises:
ValueError -- Valid pair could not be constructed, spins couldn't be converted from string.
ValueError -- Valid pair could not be constructed, bosons couldn't be converted from string.
ValueError -- Valid pair could not be constructed, fermions couldn't be converted from string.
TypeError -- Value cannot be converted to CalculatorComplex.
ValueError -- Valid pair could not be constructed.
- current_number_bosonic_modes()
Return the current number of bosonic modes each subsystem acts upon.
- Returns:
Number of bosonic modes in each spin sub-system.
- Return type:
List[int]
- current_number_fermionic_modes()
Return the current number of fermionic modes each subsystem acts upon.
- Returns:
Number of fermionic modes in each spin sub-system.
- Return type:
List[int]
- current_number_spins()
Return the current number of spins each subsystem acts upon.
- Returns:
Number of spins in each spin sub-system.
- Return type:
List[int]
- static current_version()
Returns the current version of the struqture library .
- Returns:
The current version of the library.
- Return type:
str
- fermions()
Get the fermion products of self.
- Returns:
The fermion products of self.
- Return type:
List[str]
- static from_bincode(input)
Convert the bincode representation of the object to an instance using the [bincode] crate.
- Parameters:
input (bytearray) -- The serialized object (in [bincode] form).
- Returns:
The deserialized Spin System.
- Raises:
TypeError -- Input cannot be converted to byte array.
ValueError -- Input cannot be deserialized.
- static from_json(input)
Convert the json representation of the object to an instance.
- Parameters:
input (str) -- The serialized object in json form.
- Returns:
The deserialized object.
- Raises:
ValueError -- Input cannot be deserialized.
- static from_string(input)
Convert a string representation of the object to an instance.
- Parameters:
input (str) -- The serialized index in str representation.
- Returns:
The converted object.
- Return type:
self
- Raises:
ValueError -- Input cannot be converted from str.
- hermitian_conjugate()
Return the hermitian conjugate of self and its prefactor.
- Returns:
The hermitian conjugate of self and the potential sign it has picked up.
- Return type:
(self, float)
- is_natural_hermitian()
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:
Whether self is naturally hermitian or not.
- Return type:
bool
- static json_schema()
Return the JsonSchema for the json serialisation of the class.
- Returns:
The json schema serialized to json
- Return type:
str
- min_supported_version()
Return the minimum version of struqture that supports this object.
- Returns:
The minimum version of the struqture library to deserialize this object.
- Return type:
str
- spins()
Get the spin products of self.
- Returns:
The spin products of self.
- Return type:
List[str]
- to_bincode()
Return the bincode representation of the object using the [bincode] crate.
- Returns:
The serialized object (in [bincode] form).
- Return type:
bytearray
- Raises:
ValueError -- Cannot serialize object to bytes.
- to_json()
Return the json representation of the object.
- Returns:
The serialized form of the object.
- Return type:
str
- Raises:
ValueError -- Cannot serialize object to json.
- class struqture_py.MixedHamiltonianSystem(number_spins=Ellipsis, number_bosons=Ellipsis, number_fermions=Ellipsis)
These are representations of systems of mixed_systems.
MixedHamiltonianSystems are characterized by a MixedOperator to represent the hamiltonian of the spin system and an optional number of mixed_systems.
- Parameters:
number_spins (List[Optional[int]]) -- The number of spin subsystems in the MixedHamiltonianSystem.
number_bosons (List[Optional[int]]) -- The number of boson subsystems in the MixedHamiltonianSystem.
number_fermions (List[Optional[int]]) -- The number of fermion subsystems in the MixedHamiltonianSystem.
- Returns:
The new (empty) MixedHamiltonianSystem.
- Return type:
self
Examples
import numpy.testing as npt import scipy.sparse as sp from qoqo_calculator_pyo3 import CalculatorComplex from struqture_py.mixed_systems import MixedHamiltonianSystem, HermitianMixedProduct from struqture_py.spins import PauliProduct from struqture_py.bosons import BosonProduct from struqture_py.fermions import FermionProduct ssystem = MixedHamiltonianSystem([2], [2], [2]) pp = HermitianMixedProduct([PauliProduct().z(0)], [BosonProduct([0], [1])], [FermionProduct([0], [0])]) ssystem.add_operator_product(pp, 5.0) npt.assert_equal(ssystem.number_spins(), [2]) npt.assert_equal(ssystem.get(pp), CalculatorComplex(5))
- add_operator_product(key, value)
Add a new (key object, value Union[CalculatorComplex, CalculatorFloat]) pair to existing entries.
- Parameters:
key (Product type) -- The key object
- Raises:
TypeError -- Value is not CalculatorComplex or CalculatorFloat.
ValueError -- Product could not be constructed.
ValueError -- Error in add_operator_product function of self.
- current_number_bosonic_modes()
Return the number of bosonic modes each bosonic subsystem of self acts on.
- Returns:
Maximum bosonic mode index currently used in each bosonic subsystem of self.
- Return type:
List[int]
- current_number_fermionic_modes()
Return the number of fermionic modes each fermionic subsystem of self acts on.
- Returns:
Maximum fermionic mode index currently used in each fermionic subsystem of self.
- Return type:
List[int]
- current_number_spins()
Return maximum spin index in each spin subsystem of self.
- Returns:
Maximum index in each spin subsystem of self.
- Return type:
int
- static current_version()
Returns the current version of the struqture library .
- Returns:
The current version of the library.
- Return type:
str
- empty_clone(capacity=None)
Return an instance of self that has no entries but clones all other properties, with the given capacity.
- Parameters:
capacity (Optional[int]) -- The capacity of the new instance to create.
- Returns:
An empty clone with the same properties as self, with the given capacity.
- Return type:
self
- static from_bincode(input)
Convert the bincode representation of self to an instance using the [bincode] crate.
- Parameters:
input (bytearray) -- The serialized object (in [bincode] form).
- Returns:
The deserialized object.
- Raises:
TypeError -- Input cannot be converted to byte array.
ValueError -- Input cannot be deserialized.
- static from_json(input)
Convert the json representation of self to an instance.
- Parameters:
input (str) -- The serialized object in json form.
- Returns:
The deserialized object.
- Raises:
ValueError -- Input cannot be deserialized.
- get(key)
Get the coefficient corresponding to the key.
- Parameters:
key -- Product to get the value of.
- Returns:
Value at key (or 0.0).
- Return type:
CalculatorComplex
- Raises:
ValueError -- Product could not be constructed from key.
- hermitian_conjugate()
Return the hermitian conjugate of self.
- Returns:
The hermitian conjugate of self.
- Return type:
self
- is_empty()
Return true if self contains no values.
- Returns:
Whether self is empty or not.
- Return type:
bool
- static json_schema()
Return the JsonSchema for the json serialisation of the class.
- Returns:
The json schema serialized to json
- Return type:
str
- keys()
Return a list of the unsorted keys in self.
- Returns:
The sequence of keys of the self.
- Return type:
List[OperatorProduct]
- min_supported_version()
Return the minimum version of struqture that supports this object.
- Returns:
The minimum version of the struqture library to deserialize this object.
- Return type:
str
- number_bosonic_modes()
Return the number of bosonic modes in each bosonic subsystem of self.
- Returns:
The number of bosonic modes in each bosonic subsystem of self.
- Return type:
List[int]
- number_fermionic_modes()
Return the number of fermionic modes in each fermionic subsystem of self.
- Returns:
The number of fermionic modes in each fermionic subsystem of self.
- Return type:
List[int]
- number_spins()
Return the number_spins input of each spin subsystem of self.
- Returns:
The number of spins in each spin subsystem of self.
- Return type:
int
- remove(key)
Remove the value of the input key.
- Parameters:
key -- The key of the value to remove.
- Raises:
ValueError -- Product could not be constructed.
- set(key, value)
Overwrite an existing entry or set a new entry in self.
- Parameters:
key (Product type) -- The key to set.
value (Union[CalculatorComplex, CalculatorFloat]) -- The value to set.
- Returns:
Key existed if this is not None, and this is the value it had before it was overwritten.
- Return type:
Optional[Union[CalculatorComplex, CalculatorFloat]]
- Raises:
ValueError -- Product could not be constructed.
- to_bincode()
Return the bincode representation of self using the [bincode] crate.
- Returns:
The serialized object (in [bincode] form).
- Return type:
bytearray
- Raises:
ValueError -- Cannot serialize object to bytes.
- to_json()
Return the json representation of self.
- Returns:
The serialized form of self.
- Return type:
str
- Raises:
ValueError -- Cannot serialize object to json.
- truncate(threshold)
Truncate self by returning a copy without entries under a threshold.
- Parameters:
threshold (float) -- The threshold for inclusion.
- Returns:
The truncated version of self.
- Return type:
self
- values()
Return unsorted values in self.
- Returns:
The sequence of values of self.
- Return type:
List[Union[CalculatorComplex, CalculatorFloat]]
- class struqture_py.MixedLindbladNoiseSystem(number_spins=Ellipsis, number_bosons=Ellipsis, number_fermions=Ellipsis)
These are representations of noisy systems of mixed_systems.
In a MixedLindbladNoiseSystem is characterized by a MixedLindbladNoiseOperator to represent the hamiltonian of the system, and an optional number of mixed_systems.
- Parameters:
number_spins (List[Optional[int]]) -- The number of spin subsystems in the MixedSystem.
number_bosons (List[Optional[int]]) -- The number of boson subsystems in the MixedSystem.
number_fermions (List[Optional[int]]) -- The number of fermion subsystems in the MixedSystem.
- Returns:
The new MixedLindbladNoiseSystem.
- Return type:
self
Examples
import numpy.testing as npt import scipy.sparse as sp from qoqo_calculator_pyo3 import CalculatorComplex, CalculatorFloat from struqture_py.mixed_systems import MixedLindbladNoiseSystem, MixedDecoherenceProduct from struqture_py.spins import DecoherenceProduct from struqture_py.bosons import BosonProduct from struqture_py.fermions import FermionProduct slns = MixedLindbladNoiseSystem() dp = MixedDecoherenceProduct([DecoherenceProduct().z(0)], [BosonProduct([0], [1])], [FermionProduct([0], [0])]) slns.add_operator_product((dp, dp), 2.0) npt.assert_equal(slns.current_number_spins(), [1]) npt.assert_equal(slns.get((dp, dp)), CalculatorFloat(2))
- add_operator_product(key, value)
Adds a new (key object, CalculatorComplex) pair to existing entries.
- Parameters:
key (Tuple[Product type, Product type]) -- The key of the value to add.
value (CalculatorComplex) -- The value to add.
- Raises:
TypeError -- Value is not CalculatorComplex or CalculatorFloat.
ValueError -- Left-hand product could not be constructed.
ValueError -- Right-hand product could not be constructed.
ValueError -- Error in add_operator_product function of self.
- current_number_bosonic_modes()
Return the number of bosonic modes each bosonic subsystem of self acts on.
- Returns:
Maximum bosonic mode index currently used in each bosonic subsystem of self.
- Return type:
List[int]
- current_number_fermionic_modes()
Return the number of fermionic modes each fermionic subsystem of self acts on.
- Returns:
Maximum fermionic mode index currently used in each fermionic subsystem of self.
- Return type:
List[int]
- current_number_spins()
Return maximum spin index in each spin subsystem of self.
- Returns:
Maximum index in each spin subsystem of self.
- Return type:
int
- static current_version()
Returns the current version of the struqture library .
- Returns:
The current version of the library.
- Return type:
str
- empty_clone(capacity=None)
Return an instance of self that has no entries but clones all other properties, with the given capacity.
- Parameters:
capacity -- The capacity of the object to create.
- Returns:
An empty clone with the same properties as self, with the given capacity.
- Return type:
self
- static from_bincode(input)
Convert the bincode representation of the object to an instance using the [bincode] crate.
- Parameters:
input (bytearray) -- The serialized object (in [bincode] form).
- Returns:
The deserialized object.
- Raises:
TypeError -- Input cannot be converted to byte array.
ValueError -- Input cannot be deserialized.
- static from_json(input)
Convert the json representation of the object to an instance.
- Parameters:
input (str) -- The serialized object in json form.
- Returns:
The deserialized object.
- Raises:
ValueError -- Input cannot be deserialized.
- get(key)
Get the coefficient corresponding to the key.
- Parameters:
key (Tuple[Product type, Product type]) -- Product to get the value of.
- Returns:
Value at key (or 0.0).
- Return type:
CalculatorComplex
- Raises:
ValueError -- Left-hand product could not be constructed from key.
ValueError -- Right-hand product could not be constructed from key.
- is_empty()
Return true if object contains no values.
- Returns:
Whether self is empty or not.
- Return type:
bool
- static json_schema()
Return the JsonSchema for the json serialisation of the class.
- Returns:
The json schema serialized to json
- Return type:
str
- keys()
Return unsorted keys in self.
- Returns:
The sequence of keys of self.
- Return type:
List[(OperatorProduct, OperatorProduct)]
- min_supported_version()
Return the minimum version of struqture that supports this object.
- Returns:
The minimum version of the struqture library to deserialize this object.
- Return type:
str
- number_bosonic_modes()
Return the number of bosonic modes in each bosonic subsystem of self.
- Returns:
The number of bosonic modes in each bosonic subsystem of self.
- Return type:
List[int]
- number_fermionic_modes()
Return the number of fermionic modes in each fermionic subsystem of self.
- Returns:
The number of fermionic modes in each fermionic subsystem of self.
- Return type:
List[int]
- number_spins()
Return the number_spins input of each spin subsystem of self.
- Returns:
The number of spins in each spin subsystem of self.
- Return type:
int
- remove(key)
Remove the value of the input object key.
- Parameters:
key (Tuple[Product type, Product type]) -- The key of the value to remove.
- Returns:
Key existed if this is not None, and this is the value it had before it was removed.
- Return type:
Optional[CalculatorComplex]
- Raises:
ValueError -- Left-hand Product could not be constructed.
ValueError -- Right-hand Product could not be constructed.
- set(key, value)
Overwrite an existing entry or set a new entry in self.
- Parameters:
key (Tuple[Product type, Product type]) -- The key of the value to set.
value (CalculatorComplex) -- The value to set.
- Returns:
Key existed if this is not None, and this is the value it had before it was overwritten.
- Return type:
Optional[CalculatorComplex]
- Raises:
ValueError -- Left-hand Product could not be constructed.
ValueError -- Right-hand Product could not be constructed.
- to_bincode()
Return the bincode representation of the object using the [bincode] crate.
- Returns:
The serialized object (in [bincode] form).
- Return type:
bytearray
- Raises:
ValueError -- Cannot serialize object to bytes.
- to_json()
Return the json representation of the object.
- Returns:
The serialized form of the object.
- Return type:
str
- Raises:
ValueError -- Cannot serialize object to json.
- truncate(threshold)
Truncate self by returning a copy without entries under a threshold.
- Parameters:
threshold -- The threshold for inclusion.
- Returns:
The truncated version of self.
- Return type:
self
- values()
Return unsorted values in self.
- Returns:
The sequence of values of self.
- Return type:
List[CalculatorComplex]
- class struqture_py.MixedLindbladOpenSystem(number_spins=Ellipsis, number_bosons=Ellipsis, number_fermions=Ellipsis)
These are representations of noisy systems of mixed_systems.
In a MixedLindbladOpenSystem is characterized by a MixedLindbladOpenOperator to represent the hamiltonian of the system, and an optional number of mixed_systems.
- Parameters:
number_spins (List[Optional[int]]) -- The number of spin subsystems in the MixedLindbladOpenSystem.
number_bosons (List[Optional[int]]) -- The number of boson subsystems in the MixedLindbladOpenSystem.
number_fermions (List[Optional[int]]) -- The number of fermion subsystems in the MixedLindbladOpenSystem.
- Returns:
The new MixedLindbladOpenSystem.
- Return type:
self
Examples
- current_number_bosonic_modes()
Return the number of bosonic modes each bosonic subsystem of self acts on.
- Returns:
Maximum bosonic mode index currently used in each bosonic subsystem of self.
- Return type:
List[int]
- current_number_fermionic_modes()
Return the number of fermionic modes each fermionic subsystem of self acts on.
- Returns:
Maximum fermionic mode index currently used in each fermionic subsystem of self.
- Return type:
List[int]
- current_number_spins()
Return maximum spin index in each spin subsystem of self.
- Returns:
Maximum index in each spin subsystem of self.
- Return type:
int
- static current_version()
Returns the current version of the struqture library .
- Returns:
The current version of the library.
- Return type:
str
- empty_clone()
Return an instance of self that has no entries but clones all other properties, with the given capacity.
- Returns:
An empty clone with the same properties as self, with the given capacity.
- Return type:
self
- static from_bincode(input)
Convert the bincode representation of the object to an instance using the [bincode] crate.
- Parameters:
input (bytearray) -- The serialized object (in [bincode] form).
- Returns:
The deserialized object.
- Raises:
TypeError -- Input cannot be converted to byte array.
ValueError -- Input cannot be deserialized.
- static from_json(input)
Convert the json representation of the object to an instance.
- Parameters:
input (str) -- The serialized object in json form.
- Returns:
The deserialized object.
- Raises:
ValueError -- Input cannot be deserialized.
- static group(system, noise)
Take a tuple of a system term and a noise term and combines them to be a OpenSystem.
- Parameters:
system -- The system to have in the new instance.
noise -- The noise to have in the new instance.
- Returns:
The OpenSystem with input system and noise terms.
- Return type:
self
- Raises:
ValueError -- System could not be constructed.
ValueError -- Noise could not be constructed.
ValueError -- Grouping could not be constructed.
- static json_schema()
Return the JsonSchema for the json serialisation of the class.
- Returns:
The json schema serialized to json
- Return type:
str
- min_supported_version()
Return the minimum version of struqture that supports this object.
- Returns:
The minimum version of the struqture library to deserialize this object.
- Return type:
str
- noise()
Return the noise part of self.
- Returns:
The noise of self.
- Return type:
Noise type
- noise_add_operator_product(key, value)
Add a new entry to the system of the open system.
- Parameters:
key (Tuple[Product type, Product type]) -- Tuple of Products of set object.
value (CalculatorComplex) -- Value of set object.
- Returns:
The OpenSystem with the new entry.
- Return type:
OpenSystem
- Raises:
ValueError -- Left key element cannot be converted to product.
ValueError -- Right key element cannot be converted to product.
TypeError -- Value cannot be converted to CalculatorComplex.
- noise_get(key)
Get the CalculatorComplex coefficient corresponding to the key.
- Parameters:
key (Tuple[Product type, Product type]) -- Tuple of Products of set object.
- Returns:
Value at key (or 0.0).
- Return type:
CalculatorComplex
- Raises:
ValueError -- Left key element cannot be converted to product.
ValueError -- Right key element cannot be converted to product.
- noise_set(key, value)
Set a new entry in the noise of the open system.
- Parameters:
key (Tuple[Product type, Product type]) -- Tuple of Products of set object.
value (CalculatorComplex) -- CalculatorComplex value of set object.
- Returns:
The OpenSystem with the new entry.
- Return type:
OpenSystem
- Raises:
ValueError -- Left key element cannot be converted to product.
ValueError -- Right key element cannot be converted to product.
TypeError -- Value cannot be converted to Union[CalculatorComplex, CalculatorFloat].
- number_bosonic_modes()
Return the number of bosonic modes in each bosonic subsystem of self.
- Returns:
The number of bosonic modes in each bosonic subsystem of self.
- Return type:
List[int]
- number_fermionic_modes()
Return the number of fermionic modes in each fermionic subsystem of self.
- Returns:
The number of fermionic modes in each fermionic subsystem of self.
- Return type:
List[int]
- number_spins()
Return the number_spins input of each spin subsystem of self.
- Returns:
The number of spins in each spin subsystem of self.
- Return type:
int
- system()
Return the system part of self.
- Returns:
The system of self.
- Return type:
System type
- system_add_operator_product(key, value)
Add a new entry to the system of the open system.
- Parameters:
key (Product type) -- Product key of set object.
value (Union[CalculatorComplex, CalculatorFloat]) -- Value of set object.
- Returns:
The OpenSystem with the new entry.
- Return type:
OpenSystem
- Raises:
ValueError -- key element cannot be converted to product.
TypeError -- Value cannot be converted to Union[CalculatorComplex, CalculatorFloat].
- system_get(key)
Get the CalculatorComplex or CalculatorFloat coefficient corresponding to the key.
- Parameters:
key (Product type) -- Product key of set object.
- Returns:
Value at key (or 0.0).
- Return type:
CalculatorComplex or CalculatorFloat
- Raises:
ValueError -- key element cannot be converted to product.
- system_set(key, value)
Set a new entry in the system of the open system.
- Parameters:
key (Product type) -- Product key of set object.
value (Union[CalculatorComplex, CalculatorFloat]) -- Value of set object.
- Returns:
The OpenSystem with the new entry.
- Return type:
OpenSystem
- Raises:
ValueError -- key element cannot be converted to product.
TypeError -- Value cannot be converted to Union[CalculatorComplex, CalculatorFloat].
- to_bincode()
Return the bincode representation of the object using the [bincode] crate.
- Returns:
The serialized object (in [bincode] form).
- Return type:
bytearray
- Raises:
ValueError -- Cannot serialize object to bytes.
- to_json()
Return the json representation of the object.
- Returns:
The serialized form of the object.
- Return type:
str
- Raises:
ValueError -- Cannot serialize object to json.
- truncate(threshold)
Truncate self by returning a copy without entries under a threshold.
- Parameters:
threshold -- The threshold for inclusion.
- Returns:
The truncated version of self.
- Return type:
self
- ungroup()
Return a tuple of the system and the noise of self.
- Returns:
The system and noise of self.
- Return type:
(System, Noise)
- class struqture_py.MixedPlusMinusOperator(number_spins, number_bosons, number_fermions)
These are representations of systems of mixed_systems.
MixedPlusMinusOperators are characterized by a MixedOperator to represent the hamiltonian of the spin system and an optional number of mixed_systems.
- Parameters:
number_spins (List[Optional[int]]) -- The number of spin subsystems in the MixedPlusMinusOperator.
number_bosons (List[Optional[int]]) -- The number of boson subsystems in the MixedPlusMinusOperator.
number_fermions (List[Optional[int]]) -- The number of fermion subsystems in the MixedPlusMinusOperator.
- Returns:
The new (empty) MixedPlusMinusOperator.
- Return type:
self
Examples
import numpy.testing as npt import scipy.sparse as sp from qoqo_calculator_pyo3 import CalculatorComplex from struqture_py.mixed_systems import MixedPlusMinusOperator, MixedPlusMinusProduct from struqture_py.spins import PauliProduct from struqture_py.bosons import BosonProduct from struqture_py.fermions import FermionProduct ssystem = MixedPlusMinusOperator(1, 1, 1) pp = MixedPlusMinusProduct([PauliProduct().z(0)], [BosonProduct([0], [1])], [FermionProduct([0], [0])]) ssystem.add_operator_product(pp, 5.0) npt.assert_equal(ssystem.number_spins(), [2]) npt.assert_equal(ssystem.get(pp), CalculatorComplex(5))
- add_operator_product(key, value)
Add a new (key object, value Union[CalculatorComplex, CalculatorFloat]) pair to existing entries.
- Parameters:
key (Product type) -- The key object
- Raises:
TypeError -- Value is not CalculatorComplex or CalculatorFloat.
ValueError -- Product could not be constructed.
ValueError -- Error in add_operator_product function of self.
- current_number_bosonic_modes()
Return the number of bosonic modes each bosonic subsystem of self acts on.
- Returns:
Maximum bosonic mode index currently used in each bosonic subsystem of self.
- Return type:
List[int]
- current_number_fermionic_modes()
Return the number of fermionic modes each fermionic subsystem of self acts on.
- Returns:
Maximum fermionic mode index currently used in each fermionic subsystem of self.
- Return type:
List[int]
- current_number_spins()
Return maximum spin index in each spin subsystem of self.
- Returns:
Maximum index in each spin subsystem of self.
- Return type:
int
- static current_version()
Returns the current version of the struqture library .
- Returns:
The current version of the library.
- Return type:
str
- empty_clone(capacity=None)
Return an instance of self that has no entries but clones all other properties, with the given capacity.
- Parameters:
capacity (Optional[int]) -- The capacity of the new instance to create.
- Returns:
An empty clone with the same properties as self, with the given capacity.
- Return type:
self
- static from_bincode(input)
Convert the bincode representation of self to an instance using the [bincode] crate.
- Parameters:
input (bytearray) -- The serialized object (in [bincode] form).
- Returns:
The deserialized object.
- Raises:
TypeError -- Input cannot be converted to byte array.
ValueError -- Input cannot be deserialized.
- static from_json(input)
Convert the json representation of self to an instance.
- Parameters:
input (str) -- The serialized object in json form.
- Returns:
The deserialized object.
- Raises:
ValueError -- Input cannot be deserialized.
- static from_mixed_system(value)
Convert a MixedSystem into a MixedPlusMinusOperator.
- Parameters:
value (MixedSystem) -- The MixedSystem to create the MixedPlusMinusOperator from.
- Returns:
The operator created from the input MixedSystem.
- Return type:
- Raises:
ValueError -- Could not create MixedSystem from input.
- get(key)
Get the coefficient corresponding to the key.
- Parameters:
key -- Product to get the value of.
- Returns:
Value at key (or 0.0).
- Return type:
CalculatorComplex
- Raises:
ValueError -- Product could not be constructed from key.
- hermitian_conjugate()
Return the hermitian conjugate of self.
- Returns:
The hermitian conjugate of self.
- Return type:
self
- is_empty()
Return true if self contains no values.
- Returns:
Whether self is empty or not.
- Return type:
bool
- static json_schema()
Return the JsonSchema for the json serialisation of the class.
- Returns:
The json schema serialized to json
- Return type:
str
- keys()
Return a list of the unsorted keys in self.
- Returns:
The sequence of keys of the self.
- Return type:
List[OperatorProduct]
- min_supported_version()
Return the minimum version of struqture that supports this object.
- Returns:
The minimum version of the struqture library to deserialize this object.
- Return type:
str
- number_bosonic_modes()
Return the number of bosonic modes in each bosonic subsystem of self.
- Returns:
The number of bosonic modes in each bosonic subsystem of self.
- Return type:
List[int]
- number_fermionic_modes()
Return the number of fermionic modes in each fermionic subsystem of self.
- Returns:
The number of fermionic modes in each fermionic subsystem of self.
- Return type:
List[int]
- number_spins()
Return the number_spins input of each spin subsystem of self.
- Returns:
The number of spins in each spin subsystem of self.
- Return type:
int
- remove(key)
Remove the value of the input key.
- Parameters:
key -- The key of the value to remove.
- Raises:
ValueError -- Product could not be constructed.
- set(key, value)
Overwrite an existing entry or set a new entry in self.
- Parameters:
key (Product type) -- The key to set.
value (Union[CalculatorComplex, CalculatorFloat]) -- The value to set.
- Returns:
Key existed if this is not None, and this is the value it had before it was overwritten.
- Return type:
Optional[Union[CalculatorComplex, CalculatorFloat]]
- Raises:
ValueError -- Product could not be constructed.
- to_bincode()
Return the bincode representation of self using the [bincode] crate.
- Returns:
The serialized object (in [bincode] form).
- Return type:
bytearray
- Raises:
ValueError -- Cannot serialize object to bytes.
- to_json()
Return the json representation of self.
- Returns:
The serialized form of self.
- Return type:
str
- Raises:
ValueError -- Cannot serialize object to json.
- to_mixed_system(number_spins, number_bosons, number_fermions)
Convert a MixedPlusMinusOperator into a MixedSystem.
- Parameters:
number_spins (List[Optional[int]]) -- The number of spins to initialize the MixedSystem with.
number_bosons (List[Optional[int]]) -- The number of bosons to initialize the MixedSystem with.
number_fermions (List[Optional[int]]) -- The number of fermions to initialize the MixedSystem with.
- Returns:
The operator created from the input MixedPlusMinusOperator and optional number of spins.
- Return type:
- Raises:
ValueError -- Could not create MixedOperator from MixedPlusMinusOperator.
ValueError -- Could not create MixedSystem from MixedOperator.
- truncate(threshold)
Truncate self by returning a copy without entries under a threshold.
- Parameters:
threshold (float) -- The threshold for inclusion.
- Returns:
The truncated version of self.
- Return type:
self
- values()
Return unsorted values in self.
- Returns:
The sequence of values of self.
- Return type:
List[Union[CalculatorComplex, CalculatorFloat]]
- class struqture_py.MixedPlusMinusProduct(spins, bosons, fermions)
A mixed product of pauli products and boson products.
A PlusMinusProduct <struqture_py.spins.PlusMinusProduct> is a representation of products of pauli matrices acting on qubits. It is used in order to build the corresponding spin terms of a hamiltonian.
A BosonProduct <struqture_py.bosons.BosonProduct> is a product of bosonic creation and annihilation operators. It is used as an index for non-hermitian, normal ordered bosonic operators.
A FermionProduct <struqture_py.fermions.FermionProduct> is a product of bosonic creation and annihilation operators. It is used as an index for non-hermitian, normal ordered bosonic operators.
Note: For a physical system, the bosons (BosonProduct) are usually considered in presence of a system-spin part (PlusMinusProduct) and a bath-spin part (PlusMinusProduct), as shown in the example below.
- Parameters:
spins (List[PlusMinusProduct]) -- Products of pauli operators acting on qubits.
bosons (List[BosonProduct]) -- Products of bosonic creation and annihilation operators.
fermions (List[FermionProduct]) -- Products of fermionic creation and annihilation operators.
- Returns:
a new MixedPlusMinusProduct with the input of spins, bosons and fermions.
- Return type:
- Raises:
ValueError -- MixedPlusMinusProduct can not be constructed from the input.
Examples
from struqture_py.mixed_systems import MixedPlusMinusProduct from struqture_py.spins import PlusMinusProduct from struqture_py.bosons import BosonProduct # For instance, to represent the terms $\sigma_0^{x} \sigma_2^{x}$ # and $\sigma_1^{x} \sigma_2^{x}$ mp_spins_system = PlusMinusProduct().x(0).x(2) mp_spins_bath = PlusMinusProduct().x(1).x(2) # For instance, to represent $a_1*a_1$ mp_bosons = BosonProduct([1], [1]) mp = MixedPlusMinusProduct([mp_spins_system, mp_spins_bath], [mp_bosons], []) npt.assert_equal(mp.spins(), [mp_spins_system, mp_spins_bath]) npt.assert_equal(mp.bosons(), [mp_bosons])
- bosons()
Get the boson products of self.
- Returns:
The boson products of self.
- Return type:
List[str]
- current_number_bosonic_modes()
Return the current number of bosonic modes each subsystem acts upon.
- Returns:
Number of bosonic modes in each spin sub-system.
- Return type:
List[int]
- current_number_fermionic_modes()
Return the current number of fermionic modes each subsystem acts upon.
- Returns:
Number of fermionic modes in each spin sub-system.
- Return type:
List[int]
- current_number_spins()
Return the current number of spins each subsystem acts upon.
- Returns:
Number of spins in each spin sub-system.
- Return type:
List[int]
- static current_version()
Returns the current version of the struqture library .
- Returns:
The current version of the library.
- Return type:
str
- fermions()
Get the fermion products of self.
- Returns:
The fermion products of self.
- Return type:
List[str]
- static from_bincode(input)
Convert the bincode representation of the object to an instance using the [bincode] crate.
- Parameters:
input (bytearray) -- The serialized object (in [bincode] form).
- Returns:
The deserialized Spin System.
- Raises:
TypeError -- Input cannot be converted to byte array.
ValueError -- Input cannot be deserialized.
- static from_json(input)
Convert the json representation of the object to an instance.
- Parameters:
input (str) -- The serialized object in json form.
- Returns:
The deserialized object.
- Raises:
ValueError -- Input cannot be deserialized.
- static from_mixed_product(value)
Creates a list of corresponding (MixedPlusMinusProduct, CalculatorComplex) tuples from the input MixedProduct.
- Parameters:
value (MixedProduct) -- The MixedProduct object to convert.
- Returns:
The converted input.
- Return type:
List[Tuple[(MixedPlusMinusProduct, CalculatorComplex)]]
- Raises:
ValueError -- Input is not a MixedProduct.
- static from_string(input)
Convert a string representation of the object to an instance.
- Parameters:
input (str) -- The serialized index in str representation.
- Returns:
The converted object.
- Return type:
self
- Raises:
ValueError -- Input cannot be converted from str.
- hermitian_conjugate()
Return the hermitian conjugate of self and its prefactor.
- Returns:
The hermitian conjugate of self and the potential sign it has picked up.
- Return type:
(self, float)
- is_natural_hermitian()
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:
Whether self is naturally hermitian or not.
- Return type:
bool
- static json_schema()
Return the JsonSchema for the json serialisation of the class.
- Returns:
The json schema serialized to json
- Return type:
str
- min_supported_version()
Return the minimum version of struqture that supports this object.
- Returns:
The minimum version of the struqture library to deserialize this object.
- Return type:
str
- spins()
Get the spin products of self.
- Returns:
The spin products of self.
- Return type:
List[str]
- to_bincode()
Return the bincode representation of the object using the [bincode] crate.
- Returns:
The serialized object (in [bincode] form).
- Return type:
bytearray
- Raises:
ValueError -- Cannot serialize object to bytes.
- to_json()
Return the json representation of the object.
- Returns:
The serialized form of the object.
- Return type:
str
- Raises:
ValueError -- Cannot serialize object to json.
- to_mixed_product_list()
Convert the self instance to the corresponding list of (MixedProduct, CalculatorComplex) instances.
- Returns:
The converted MixedPlusMinusProduct.
- Return type:
List[Tuple[(MixedProduct, CalculatorComplex)]]
- Raises:
ValueError -- The conversion was not successful.
- class struqture_py.MixedProduct(spins, bosons, fermions)
A mixed product of pauli products and boson products.
A PauliProduct <struqture_py.spins.PauliProduct> is a representation of products of pauli matrices acting on qubits. It is used in order to build the corresponding spin terms of a hamiltonian.
A BosonProduct <struqture_py.bosons.BosonProduct> is a product of bosonic creation and annihilation operators. It is used as an index for non-hermitian, normal ordered bosonic operators.
A FermionProduct <struqture_py.fermions.FermionProduct> is a product of bosonic creation and annihilation operators. It is used as an index for non-hermitian, normal ordered bosonic operators.
Note: For a physical system, the bosons (BosonProduct) are usually considered in presence of a system-spin part (PauliProduct) and a bath-spin part (PauliProduct), as shown in the example below.
- Parameters:
spins (List[PauliProduct]) -- Products of pauli operators acting on qubits.
bosons (List[BosonProduct]) -- Products of bosonic creation and annihilation operators.
fermions (List[FermionProduct]) -- Products of fermionic creation and annihilation operators.
- Returns:
a new MixedProduct with the input of spins, bosons and fermions.
- Return type:
- Raises:
ValueError -- MixedProduct can not be constructed from the input.
Examples
from struqture_py.mixed_systems import MixedProduct from struqture_py.spins import PauliProduct from struqture_py.bosons import BosonProduct # For instance, to represent the terms $\sigma_0^{x} \sigma_2^{x}$ # and $\sigma_1^{x} \sigma_2^{x}$ mp_spins_system = PauliProduct().x(0).x(2) mp_spins_bath = PauliProduct().x(1).x(2) # For instance, to represent $a_1*a_1$ mp_bosons = BosonProduct([1], [1]) mp = MixedProduct([mp_spins_system, mp_spins_bath], [mp_bosons], []) npt.assert_equal(mp.spins(), [mp_spins_system, mp_spins_bath]) npt.assert_equal(mp.bosons(), [mp_bosons])
- bosons()
Get the boson products of self.
- Returns:
The boson products of self.
- Return type:
List[str]
- create_valid_pair(bosons, fermions, value)
Create a pair (MixedProduct, CalculatorComplex).
The first item is the valid MixedProduct created from the input creators and annihilators. The second term is the input CalculatorComplex transformed according to the valid order of creators and annihilators.
- Parameters:
creators -- The creator indices to have in the MixedProduct.
annihilators -- The annihilators indices to have in the MixedProduct.
value -- The CalculatorComplex to transform.
- Returns:
Tuple[MixedProduct, CalculatorComplex] - The valid MixedProduct and the corresponding transformed CalculatorComplex.
- Raises:
ValueError -- Valid pair could not be constructed, pauli spins couldn't be converted from string.
ValueError -- Valid pair could not be constructed, bosons couldn't be converted from string.
ValueError -- Valid pair could not be constructed, fermions couldn't be converted from string.
TypeError -- Value cannot be converted to CalculatorComplex.
ValueError -- Valid pair could not be constructed.
- current_number_bosonic_modes()
Return the current number of bosonic modes each subsystem acts upon.
- Returns:
Number of bosonic modes in each spin sub-system.
- Return type:
List[int]
- current_number_fermionic_modes()
Return the current number of fermionic modes each subsystem acts upon.
- Returns:
Number of fermionic modes in each spin sub-system.
- Return type:
List[int]
- current_number_spins()
Return the current number of spins each subsystem acts upon.
- Returns:
Number of spins in each spin sub-system.
- Return type:
List[int]
- static current_version()
Returns the current version of the struqture library .
- Returns:
The current version of the library.
- Return type:
str
- fermions()
Get the fermion products of self.
- Returns:
The fermion products of self.
- Return type:
List[str]
- static from_bincode(input)
Convert the bincode representation of the object to an instance using the [bincode] crate.
- Parameters:
input (bytearray) -- The serialized object (in [bincode] form).
- Returns:
The deserialized Spin System.
- Raises:
TypeError -- Input cannot be converted to byte array.
ValueError -- Input cannot be deserialized.
- static from_json(input)
Convert the json representation of the object to an instance.
- Parameters:
input (str) -- The serialized object in json form.
- Returns:
The deserialized object.
- Raises:
ValueError -- Input cannot be deserialized.
- static from_string(input)
Convert a string representation of the object to an instance.
- Parameters:
input (str) -- The serialized index in str representation.
- Returns:
The converted object.
- Return type:
self
- Raises:
ValueError -- Input cannot be converted from str.
- hermitian_conjugate()
Return the hermitian conjugate of self and its prefactor.
- Returns:
The hermitian conjugate of self and the potential sign it has picked up.
- Return type:
(self, float)
- is_natural_hermitian()
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:
Whether self is naturally hermitian or not.
- Return type:
bool
- static json_schema()
Return the JsonSchema for the json serialisation of the class.
- Returns:
The json schema serialized to json
- Return type:
str
- min_supported_version()
Return the minimum version of struqture that supports this object.
- Returns:
The minimum version of the struqture library to deserialize this object.
- Return type:
str
- spins()
Get the spin products of self.
- Returns:
The spin products of self.
- Return type:
List[str]
- to_bincode()
Return the bincode representation of the object using the [bincode] crate.
- Returns:
The serialized object (in [bincode] form).
- Return type:
bytearray
- Raises:
ValueError -- Cannot serialize object to bytes.
- to_json()
Return the json representation of the object.
- Returns:
The serialized form of the object.
- Return type:
str
- Raises:
ValueError -- Cannot serialize object to json.
- class struqture_py.MixedSystem(number_spins=Ellipsis, number_bosons=Ellipsis, number_fermions=Ellipsis)
These are representations of systems of mixed_systems.
MixedSystems are characterized by a MixedOperator to represent the hamiltonian of the spin system and an optional number of mixed_systems.
- Parameters:
number_spins (List[Optional[int]]) -- The number of spin subsystems in the MixedSystem.
number_bosons (List[Optional[int]]) -- The number of boson subsystems in the MixedSystem.
number_fermions (List[Optional[int]]) -- The number of fermion subsystems in the MixedSystem.
- Returns:
The new (empty) MixedSystem.
- Return type:
self
Examples
import numpy.testing as npt import scipy.sparse as sp from qoqo_calculator_pyo3 import CalculatorComplex from struqture_py.mixed_systems import MixedSystem, MixedProduct from struqture_py.spins import PauliProduct from struqture_py.bosons import BosonProduct from struqture_py.fermions import FermionProduct ssystem = MixedSystem([2], [2], [2]) pp = MixedProduct([PauliProduct().z(0)], [BosonProduct([0], [1])], [FermionProduct([0], [0])]) ssystem.add_operator_product(pp, 5.0) npt.assert_equal(ssystem.number_spins(), [2]) npt.assert_equal(ssystem.get(pp), CalculatorComplex(5))
- add_operator_product(key, value)
Add a new (key object, value Union[CalculatorComplex, CalculatorFloat]) pair to existing entries.
- Parameters:
key (Product type) -- The key object
- Raises:
TypeError -- Value is not CalculatorComplex or CalculatorFloat.
ValueError -- Product could not be constructed.
ValueError -- Error in add_operator_product function of self.
- current_number_bosonic_modes()
Return the number of bosonic modes each bosonic subsystem of self acts on.
- Returns:
Maximum bosonic mode index currently used in each bosonic subsystem of self.
- Return type:
List[int]
- current_number_fermionic_modes()
Return the number of fermionic modes each fermionic subsystem of self acts on.
- Returns:
Maximum fermionic mode index currently used in each fermionic subsystem of self.
- Return type:
List[int]
- current_number_spins()
Return maximum spin index in each spin subsystem of self.
- Returns:
Maximum index in each spin subsystem of self.
- Return type:
int
- static current_version()
Returns the current version of the struqture library .
- Returns:
The current version of the library.
- Return type:
str
- empty_clone(capacity=None)
Return an instance of self that has no entries but clones all other properties, with the given capacity.
- Parameters:
capacity (Optional[int]) -- The capacity of the new instance to create.
- Returns:
An empty clone with the same properties as self, with the given capacity.
- Return type:
self
- static from_bincode(input)
Convert the bincode representation of self to an instance using the [bincode] crate.
- Parameters:
input (bytearray) -- The serialized object (in [bincode] form).
- Returns:
The deserialized object.
- Raises:
TypeError -- Input cannot be converted to byte array.
ValueError -- Input cannot be deserialized.
- static from_json(input)
Convert the json representation of self to an instance.
- Parameters:
input (str) -- The serialized object in json form.
- Returns:
The deserialized object.
- Raises:
ValueError -- Input cannot be deserialized.
- get(key)
Get the coefficient corresponding to the key.
- Parameters:
key -- Product to get the value of.
- Returns:
Value at key (or 0.0).
- Return type:
CalculatorComplex
- Raises:
ValueError -- Product could not be constructed from key.
- hermitian_conjugate()
Return the hermitian conjugate of self.
- Returns:
The hermitian conjugate of self.
- Return type:
self
- is_empty()
Return true if self contains no values.
- Returns:
Whether self is empty or not.
- Return type:
bool
- static json_schema()
Return the JsonSchema for the json serialisation of the class.
- Returns:
The json schema serialized to json
- Return type:
str
- keys()
Return a list of the unsorted keys in self.
- Returns:
The sequence of keys of the self.
- Return type:
List[OperatorProduct]
- min_supported_version()
Return the minimum version of struqture that supports this object.
- Returns:
The minimum version of the struqture library to deserialize this object.
- Return type:
str
- number_bosonic_modes()
Return the number of bosonic modes in each bosonic subsystem of self.
- Returns:
The number of bosonic modes in each bosonic subsystem of self.
- Return type:
List[int]
- number_fermionic_modes()
Return the number of fermionic modes in each fermionic subsystem of self.
- Returns:
The number of fermionic modes in each fermionic subsystem of self.
- Return type:
List[int]
- number_spins()
Return the number_spins input of each spin subsystem of self.
- Returns:
The number of spins in each spin subsystem of self.
- Return type:
int
- remove(key)
Remove the value of the input key.
- Parameters:
key -- The key of the value to remove.
- Raises:
ValueError -- Product could not be constructed.
- set(key, value)
Overwrite an existing entry or set a new entry in self.
- Parameters:
key (Product type) -- The key to set.
value (Union[CalculatorComplex, CalculatorFloat]) -- The value to set.
- Returns:
Key existed if this is not None, and this is the value it had before it was overwritten.
- Return type:
Optional[Union[CalculatorComplex, CalculatorFloat]]
- Raises:
ValueError -- Product could not be constructed.
- to_bincode()
Return the bincode representation of self using the [bincode] crate.
- Returns:
The serialized object (in [bincode] form).
- Return type:
bytearray
- Raises:
ValueError -- Cannot serialize object to bytes.
- to_json()
Return the json representation of self.
- Returns:
The serialized form of self.
- Return type:
str
- Raises:
ValueError -- Cannot serialize object to json.
- truncate(threshold)
Truncate self by returning a copy without entries under a threshold.
- Parameters:
threshold (float) -- The threshold for inclusion.
- Returns:
The truncated version of self.
- Return type:
self
- values()
Return unsorted values in self.
- Returns:
The sequence of values of self.
- Return type:
List[Union[CalculatorComplex, CalculatorFloat]]
- class struqture_py.PauliProduct
PauliProducts are combinations of SingleSpinOperators 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 \(\sigma_0^{x}\) \(\sigma_2^{x}\) :
PauliProduct().x(0).x(2).
PauliProduct is supposed to be used as input for the function set_pauli_product, for instance in the spin system classes SpinLindbladOpenSystem, SpinHamiltonianSystem or SpinSystem, or in the mixed systems as part of MixedProduct <mixed_systems.MixedProduct> or as part of HermitianMixedProduct <mixed_systems.HermitianMixedProduct>.
- Returns:
The new, empty PauliProduct.
- Return type:
self
Examples
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])
- concatenate(other)
Return the concatenation of two objects of type self with no overlapping qubits.
- Parameters:
other (self) -- The object to concatenate self with.
- Returns:
A list of the corresponding creator indices.
- Return type:
List[int]
- Raises:
ValueError -- The two objects could not be concatenated.
- current_number_spins()
Return maximum index in self.
- Returns:
Maximum index.
- Return type:
int
- static current_version()
Returns the current version of the struqture library .
- Returns:
The current version of the library.
- Return type:
str
- static from_bincode(input)
Convert the bincode representation of the object to an instance using the [bincode] crate.
- Parameters:
input (bytearray) -- The serialized object (in [bincode] form).
- Returns:
The deserialized Spin System.
- Raises:
TypeError -- Input cannot be converted to byte array.
ValueError -- Input cannot be deserialized.
- static from_json(input)
Convert the json representation of the object to an instance.
- Parameters:
input (str) -- The serialized object in json form.
- Returns:
The deserialized object.
- Raises:
ValueError -- Input cannot be deserialized.
- static from_string(input)
Convert a string representation of the object to an instance.
- Parameters:
input (str) -- The serialized index in str representation.
- Returns:
The converted object.
- Return type:
self
- Raises:
ValueError -- Input cannot be converted from str.
- get(index)
Get the pauli matrix corresponding to the index.
- Parameters:
index (int) -- Index of get object.
- Returns:
The key's corresponding value (if it exists).
- Return type:
Optional[str]
- hermitian_conjugate()
Return the hermitian conjugate of self and its prefactor.
- Returns:
The hermitian conjugate of self and the potential sign it has picked up.
- Return type:
(self, float)
- is_empty()
Return whether self is empty or not.
- Returns:
Whether self is empty or not.
- Return type:
bool
- is_natural_hermitian()
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:
Whether self is naturally hermitian or not.
- Return type:
bool
- jordan_wigner()
Transform the given spin object into a fermionic object using the Jordan Wigner mapping.
- static json_schema()
Return the JsonSchema for the json serialisation of the class.
- Returns:
The json schema serialized to json
- Return type:
str
- keys()
Return a list of the unsorted keys in self.
- Returns:
The sequence of qubit index keys of self.
- Return type:
List[int]
- min_supported_version()
Return the minimum version of struqture that supports this object.
- Returns:
The minimum version of the struqture library to deserialize this object.
- Return type:
str
- static multiply(left, right)
Multiplication function for a self-typed object by a self-typed object.
- Parameters:
left (self) -- Left-hand self typed object to be multiplied.
right (self) -- Right-hand self typed object to be multiplied.
- Returns:
The multiplied objects and the resulting prefactor.
- Return type:
(self, complex)
- remap_qubits(mapping)
Remap the qubits in a new instance of self (returned).
- Parameters:
mapping (Dict[int, int]) -- The map containing the {qubit: qubit} mapping to use.
- Returns:
The new instance of self with the qubits remapped.
- Return type:
self
- set_pauli(index, pauli)
Set a new entry in the internal_map. This function consumes self.
- Parameters:
index (int) -- Index of set object.
pauli (str) -- Value of set object.
- Returns:
The entry was correctly set and the PauliProduct is returned.
- Return type:
self
- to_bincode()
Return the bincode representation of the object using the [bincode] crate.
- Returns:
The serialized object (in [bincode] form).
- Return type:
bytearray
- Raises:
ValueError -- Cannot serialize object to bytes.
- to_json()
Return the json representation of the object.
- Returns:
The serialized form of the object.
- Return type:
str
- Raises:
ValueError -- Cannot serialize object to json.
- x(index)
Set a new entry for SingleSpinOperator X in the internal dictionary.
- Parameters:
index (int) -- Index of set object.
- Returns:
The PauliProduct with the new entry.
- Return type:
- y(index)
Set a new entry for SingleSpinOperator Y in the internal dictionary.
- Parameters:
index (int) -- Index of set object.
- Returns:
The PauliProduct with the new entry.
- Return type:
- z(index)
Set a new entry for SingleSpinOperator Z in the internal dictionary.
- Parameters:
index (int) -- Index of set object.
- Returns:
The PauliProduct with the new entry.
- Return type:
- class struqture_py.PlusMinusLindbladNoiseOperator
These are representations of noisy systems of spins.
In a PlusMinusLindbladNoiseOperator is characterized by a SpinLindbladNoiseOperator to represent the hamiltonian of the spin system, and an optional number of spins.
- Returns:
The new PlusMinusLindbladNoiseOperator with the input number of spins.
- Return type:
self
Examples
import numpy.testing as npt from qoqo_calculator_pyo3 import CalculatorComplex from struqture_py.spins import PlusMinusLindbladNoiseOperator, PlusMinusProduct slns = PlusMinusLindbladNoiseOperator() dp = PlusMinusProduct().z(0).plus(1) slns.add_operator_product((dp, dp), 2.0) npt.assert_equal(slns.get((dp, dp)), CalculatorComplex(2)) npt.assert_equal(slns.keys(), [(dp, dp)])
- add_operator_product(key, value)
Adds a new (key object, CalculatorComplex) pair to existing entries.
- Parameters:
key (Tuple[Product type, Product type]) -- The key of the value to add.
value (CalculatorComplex) -- The value to add.
- Raises:
TypeError -- Value is not CalculatorComplex or CalculatorFloat.
ValueError -- Left-hand product could not be constructed.
ValueError -- Right-hand product could not be constructed.
ValueError -- Error in add_operator_product function of self.
- static current_version()
Returns the current version of the struqture library .
- Returns:
The current version of the library.
- Return type:
str
- empty_clone(capacity=None)
Return an instance of self that has no entries but clones all other properties, with the given capacity.
- Parameters:
capacity -- The capacity of the object to create.
- Returns:
An empty clone with the same properties as self, with the given capacity.
- Return type:
self
- static from_bincode(input)
Convert the bincode representation of the object to an instance using the [bincode] crate.
- Parameters:
input (bytearray) -- The serialized object (in [bincode] form).
- Returns:
The deserialized object.
- Raises:
TypeError -- Input cannot be converted to byte array.
ValueError -- Input cannot be deserialized.
- static from_json(input)
Convert the json representation of the object to an instance.
- Parameters:
input (str) -- The serialized object in json form.
- Returns:
The deserialized object.
- Raises:
ValueError -- Input cannot be deserialized.
- static from_spin_noise_system(value)
Convert a SpinLindbladNoiseSystem into a PlusMinusLindbladNoiseOperator.
- Parameters:
value (SpinLindbladNoiseSystem) -- The SpinLindbladNoiseSystem to create the PlusMinusLindbladNoiseOperator from.
- Returns:
The operator created from the input SpinLindbladNoiseSystem.
- Return type:
- Raises:
ValueError -- Could not create SpinLindbladNoiseSystem from input.
- get(key)
Get the coefficient corresponding to the key.
- Parameters:
key (Tuple[Product type, Product type]) -- Product to get the value of.
- Returns:
Value at key (or 0.0).
- Return type:
CalculatorComplex
- Raises:
ValueError -- Left-hand product could not be constructed from key.
ValueError -- Right-hand product could not be constructed from key.
- is_empty()
Return true if object contains no values.
- Returns:
Whether self is empty or not.
- Return type:
bool
- jordan_wigner()
Transform the given spin object into a fermionic object using the Jordan Wigner mapping.
- static json_schema()
Return the JsonSchema for the json serialisation of the class.
- Returns:
The json schema serialized to json
- Return type:
str
- keys()
Return unsorted keys in self.
- Returns:
The sequence of keys of self.
- Return type:
List[(OperatorProduct, OperatorProduct)]
- min_supported_version()
Return the minimum version of struqture that supports this object.
- Returns:
The minimum version of the struqture library to deserialize this object.
- Return type:
str
- remove(key)
Remove the value of the input object key.
- Parameters:
key (Tuple[Product type, Product type]) -- The key of the value to remove.
- Returns:
Key existed if this is not None, and this is the value it had before it was removed.
- Return type:
Optional[CalculatorComplex]
- Raises:
ValueError -- Left-hand Product could not be constructed.
ValueError -- Right-hand Product could not be constructed.
- separate_into_n_terms(number_spins_left, number_spins_right)
Separate self into an operator with the terms of given number of spins (left and right) and an operator with the remaining operations.
- Args
number_spins_left (int): Number of spin to filter for in the left key. number_spins_right (int): Number of spin to filter for in the right key.
- Returns
Tuple[PlusMinusLindbladNoiseOperator, PlusMinusLindbladNoiseOperator]: Operator with the noise terms where number_spins (left and right) matches the number of spins the operator product acts on and Operator with all other contributions.
- Raises:
ValueError -- Error in adding terms to return values.
- set(key, value)
Overwrite an existing entry or set a new entry in self.
- Parameters:
key (Tuple[Product type, Product type]) -- The key of the value to set.
value (CalculatorComplex) -- The value to set.
- Returns:
Key existed if this is not None, and this is the value it had before it was overwritten.
- Return type:
Optional[CalculatorComplex]
- Raises:
ValueError -- Left-hand Product could not be constructed.
ValueError -- Right-hand Product could not be constructed.
- to_bincode()
Return the bincode representation of the object using the [bincode] crate.
- Returns:
The serialized object (in [bincode] form).
- Return type:
bytearray
- Raises:
ValueError -- Cannot serialize object to bytes.
- to_json()
Return the json representation of the object.
- Returns:
The serialized form of the object.
- Return type:
str
- Raises:
ValueError -- Cannot serialize object to json.
- to_spin_noise_system(number_spinss=None)
Convert a PlusMinusLindbladNoiseOperator into a SpinLindbladNoiseSystem.
- Parameters:
number_spinss (Optional[int]) -- The number of spins to initialize the SpinLindbladNoiseSystem with.
- Returns:
The operator created from the input PlusMinusLindbladNoiseOperator and optional number of spins.
- Return type:
- Raises:
ValueError -- Could not create SpinLindbladNoiseSystem from PlusMinusLindbladNoiseOperator.
- truncate(threshold)
Truncate self by returning a copy without entries under a threshold.
- Parameters:
threshold -- The threshold for inclusion.
- Returns:
The truncated version of self.
- Return type:
self
- values()
Return unsorted values in self.
- Returns:
The sequence of values of self.
- Return type:
List[CalculatorComplex]
- class struqture_py.PlusMinusOperator
These are representations of systems of spins.
PlusMinusOperators are characterized by a SpinOperator to represent the hamiltonian of the spin system and an optional number of spins.
- Returns:
The new PlusMinusOperator with the input number of spins.
- Return type:
self
Examples
import numpy.testing as npt from qoqo_calculator_pyo3 import CalculatorComplex from struqture_py.spins import PlusMinusOperator, PlusMinusProduct ssystem = PlusMinusOperator() pp = PlusMinusProduct().z(0) ssystem.add_operator_product(pp, 5.0) npt.assert_equal(ssystem.get(pp), CalculatorComplex(5)) npt.assert_equal(ssystem.keys(), [pp])
- add_operator_product(key, value)
Add a new (key object, value Union[CalculatorComplex, CalculatorFloat]) pair to existing entries.
- Parameters:
key (Product type) -- The key object
- Raises:
TypeError -- Value is not CalculatorComplex or CalculatorFloat.
ValueError -- Product could not be constructed.
ValueError -- Error in add_operator_product function of self.
- static current_version()
Returns the current version of the struqture library .
- Returns:
The current version of the library.
- Return type:
str
- empty_clone(capacity=None)
Return an instance of self that has no entries but clones all other properties, with the given capacity.
- Parameters:
capacity (Optional[int]) -- The capacity of the new instance to create.
- Returns:
An empty clone with the same properties as self, with the given capacity.
- Return type:
self
- static from_bincode(input)
Convert the bincode representation of self to an instance using the [bincode] crate.
- Parameters:
input (bytearray) -- The serialized object (in [bincode] form).
- Returns:
The deserialized object.
- Raises:
TypeError -- Input cannot be converted to byte array.
ValueError -- Input cannot be deserialized.
- static from_json(input)
Convert the json representation of self to an instance.
- Parameters:
input (str) -- The serialized object in json form.
- Returns:
The deserialized object.
- Raises:
ValueError -- Input cannot be deserialized.
- static from_spin_hamiltonian_system(value)
Convert a SpinHamiltonianSystem into a PlusMinusOperator.
- Parameters:
value (SpinHamiltonianSystem) -- The SpinHamiltonianSystem to create the PlusMinusOperator from.
- Returns:
The operator created from the input SpinSystem.
- Return type:
- Raises:
ValueError -- Could not create SpinHamiltonianSystem from input.
- static from_spin_system(value)
Convert a SpinSystem into a PlusMinusOperator.
- Parameters:
value (SpinSystem) -- The SpinSystem to create the PlusMinusOperator from.
- Returns:
The operator created from the input SpinSystem.
- Return type:
- Raises:
ValueError -- Could not create SpinSystem from input.
- get(key)
Get the coefficient corresponding to the key.
- Parameters:
key -- Product to get the value of.
- Returns:
Value at key (or 0.0).
- Return type:
CalculatorComplex
- Raises:
ValueError -- Product could not be constructed from key.
- hermitian_conjugate()
Return the hermitian conjugate of self.
- Returns:
The hermitian conjugate of self.
- Return type:
self
- is_empty()
Return true if self contains no values.
- Returns:
Whether self is empty or not.
- Return type:
bool
- jordan_wigner()
Transform the given spin object into a fermionic object using the Jordan Wigner mapping.
- static json_schema()
Return the JsonSchema for the json serialisation of the class.
- Returns:
The json schema serialized to json
- Return type:
str
- keys()
Return a list of the unsorted keys in self.
- Returns:
The sequence of keys of the self.
- Return type:
List[OperatorProduct]
- min_supported_version()
Return the minimum version of struqture that supports this object.
- Returns:
The minimum version of the struqture library to deserialize this object.
- Return type:
str
- remove(key)
Remove the value of the input key.
- Parameters:
key -- The key of the value to remove.
- Raises:
ValueError -- Product could not be constructed.
- separate_into_n_terms(number_spins)
Separate self into an operator with the terms of given number of spins and an operator with the remaining operations
- Args
number_spins (int): Number of spins to filter for in the keys.
- Returns
(PlusMinusOperator, PlusMinusOperator): Operator with the terms where number_spins matches the number of spins the operator product acts on and Operator with all other contributions.
- Raises:
ValueError -- Error in adding terms to return values.
- set(key, value)
Overwrite an existing entry or set a new entry in self.
- Parameters:
key (Product type) -- The key to set.
value (Union[CalculatorComplex, CalculatorFloat]) -- The value to set.
- Returns:
Key existed if this is not None, and this is the value it had before it was overwritten.
- Return type:
Optional[Union[CalculatorComplex, CalculatorFloat]]
- Raises:
ValueError -- Product could not be constructed.
- to_bincode()
Return the bincode representation of self using the [bincode] crate.
- Returns:
The serialized object (in [bincode] form).
- Return type:
bytearray
- Raises:
ValueError -- Cannot serialize object to bytes.
- to_json()
Return the json representation of self.
- Returns:
The serialized form of self.
- Return type:
str
- Raises:
ValueError -- Cannot serialize object to json.
- to_spin_hamiltonian_system(number_spins=None)
Convert a PlusMinusOperator into a SpinHamiltonianSystem.
- Parameters:
number_spins (Optional[int]) -- The number of spins to initialize the SpinHamiltonianSystem with.
- Returns:
The operator created from the input PlusMinusOperator and optional number of spins.
- Return type:
- Raises:
ValueError -- Could not create SpinHamiltonianSystem from PlusMinusOperator.
- to_spin_system(number_spins=None)
Convert a PlusMinusOperator into a SpinSystem.
- Parameters:
number_spins (Optional[int]) -- The number of spins to initialize the SpinSystem with.
- Returns:
The operator created from the input PlusMinusOperator and optional number of spins.
- Return type:
- Raises:
ValueError -- Could not create SpinSystem from PlusMinusOperator.
- truncate(threshold)
Truncate self by returning a copy without entries under a threshold.
- Parameters:
threshold (float) -- The threshold for inclusion.
- Returns:
The truncated version of self.
- Return type:
self
- values()
Return unsorted values in self.
- Returns:
The sequence of values of self.
- Return type:
List[Union[CalculatorComplex, CalculatorFloat]]
- class struqture_py.PlusMinusProduct
PlusMinusProducts are combinations of SinglePlusMinusOperators on specific qubits.
PlusMinusProducts 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 \(\sigma_0^{+}\) \(\sigma_2^{+}\) :
PlusMinusProduct().plus(0).plus(2).
- Returns:
The new, empty PlusMinusProduct.
- Return type:
self
Examples
import numpy.testing as npt from struqture_py.spins import PlusMinusProduct pp = PlusMinusProduct().plus(0).minus(1).z(2) pp = pp.set_pauli(3, "+") npt.assert_equal(pp.get(0), "+") npt.assert_equal(pp.keys(), [0, 1, 2, 3])
- concatenate(other)
Return the concatenation of two objects of type self with no overlapping qubits.
- Parameters:
other (self) -- The object to concatenate self with.
- Returns:
A list of the corresponding creator indices.
- Return type:
List[int]
- Raises:
ValueError -- The two objects could not be concatenated.
- current_number_spins()
Return maximum index in self.
- Returns:
Maximum index.
- Return type:
int
- static current_version()
Returns the current version of the struqture library .
- Returns:
The current version of the library.
- Return type:
str
- static from_bincode(input)
Convert the bincode representation of the object to an instance using the [bincode] crate.
- Parameters:
input (bytearray) -- The serialized object (in [bincode] form).
- Returns:
The deserialized Spin System.
- Raises:
TypeError -- Input cannot be converted to byte array.
ValueError -- Input cannot be deserialized.
- static from_json(input)
Convert the json representation of the object to an instance.
- Parameters:
input (str) -- The serialized object in json form.
- Returns:
The deserialized object.
- Raises:
ValueError -- Input cannot be deserialized.
- static from_product(value)
Creates a list of corresponding (PlusMinusProduct, CalculatorComplex) tuples from the input PauliProduct or DecoherenceProduct.
- Parameters:
value (PauliProduct or DecoherenceProduct) -- The input object to convert.
- Returns:
The converted input.
- Return type:
List[Tuple[(PlusMinusProduct, CalculatorComplex)]]
- Raises:
ValueError -- Input is neither a PauliProduct nor a DecoherenceProduct.
- static from_string(input)
Convert a string representation of the object to an instance.
- Parameters:
input (str) -- The serialized index in str representation.
- Returns:
The converted object.
- Return type:
self
- Raises:
ValueError -- Input cannot be converted from str.
- get(index)
Get the pauli matrix corresponding to the index.
- Parameters:
index (int) -- Index of get object.
- Returns:
The key's corresponding value (if it exists).
- Return type:
Optional[str]
- hermitian_conjugate()
Return the hermitian conjugate of self and its prefactor.
- Returns:
The hermitian conjugate of self and the potential sign it has picked up.
- Return type:
(self, float)
- is_natural_hermitian()
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:
Whether self is naturally hermitian or not.
- Return type:
bool
- jordan_wigner()
Transform the given spin object into a fermionic object using the Jordan Wigner mapping.
- static json_schema()
Return the JsonSchema for the json serialisation of the class.
- Returns:
The json schema serialized to json
- Return type:
str
- keys()
Return a list of the unsorted keys in self.
- Returns:
The sequence of qubit index keys of self.
- Return type:
List[int]
- min_supported_version()
Return the minimum version of struqture that supports this object.
- Returns:
The minimum version of the struqture library to deserialize this object.
- Return type:
str
- minus(index)
Set a new entry for SinglePlusMinusOperator Y in the internal dictionary.
- Parameters:
index (int) -- Index of set object.
- Returns:
The PlusMinusProduct with the new entry.
- Return type:
- plus(index)
Set a new entry for SinglePlusMinusOperator X in the internal dictionary.
- Parameters:
index (int) -- Index of set object.
- Returns:
The PlusMinusProduct with the new entry.
- Return type:
- remap_qubits(mapping)
Remap the qubits in a new instance of self (returned).
- Parameters:
mapping (Dict[int, int]) -- The map containing the {qubit: qubit} mapping to use.
- Returns:
The new instance of self with the qubits remapped.
- Return type:
self
- set_pauli(index, pauli)
Set a new entry in the internal_map. This function consumes self.
- Parameters:
index (int) -- Index of set object.
pauli (str) -- Value of set object.
- Returns:
The entry was correctly set and the PlusMinusProduct is returned.
- Return type:
self
- to_bincode()
Return the bincode representation of the object using the [bincode] crate.
- Returns:
The serialized object (in [bincode] form).
- Return type:
bytearray
- Raises:
ValueError -- Cannot serialize object to bytes.
- to_decoherence_product()
DEPRECATED: Convert self into a list of (DecoherenceProduct, CalculatorComplex) tuples.
This function is deprecated, please use to_decoherence_product_list
- Returns:
A list of the terms self corresponds to.
- Return type:
List[Tuple[(DecoherenceProduct, CalculatorComplex)]]
- to_decoherence_product_list()
Convert self into a list of (DecoherenceProduct, CalculatorComplex) tuples.
- Returns:
A list of the terms self corresponds to.
- Return type:
List[Tuple[(DecoherenceProduct, CalculatorComplex)]]
- to_json()
Return the json representation of the object.
- Returns:
The serialized form of the object.
- Return type:
str
- Raises:
ValueError -- Cannot serialize object to json.
- to_pauli_product()
DEPRECATED: Convert self into a list of (PauliProduct, CalculatorComplex) tuples.
This function is deprecated, please use to_pauli_product_list
- Returns:
A list of the terms self corresponds to.
- Return type:
List[Tuple[(PauliProduct, CalculatorComplex)]]
- to_pauli_product_list()
Convert self into a list of (PauliProduct, CalculatorComplex) tuples.
- Returns:
A list of the terms self corresponds to.
- Return type:
List[Tuple[(PauliProduct, CalculatorComplex)]]
- z(index)
Set a new entry for SinglePlusMinusOperator Z in the internal dictionary.
- Parameters:
index (int) -- Index of set object.
- Returns:
The PlusMinusProduct with the new entry.
- Return type:
- class struqture_py.SpinHamiltonianSystem(number_spins=None)
These are representations of systems of spins.
SpinHamiltonianSystems are characterized by a SpinOperator to represent the hamiltonian of the spin system and an optional number of spins.
- Parameters:
number_spins (Optional[int]) -- The number of spins in the SpinHamiltonianSystem.
- Returns:
The new SpinHamiltonianSystem with the input number of spins.
- Return type:
self
Examples
import numpy.testing as npt import scipy.sparse as sp from qoqo_calculator_pyo3 import CalculatorComplex from struqture_py.spins import SpinHamiltonianSystem, PauliProduct ssystem = SpinHamiltonianSystem(2) pp = PauliProduct().z(0) ssystem.add_operator_product(pp, 5.0) npt.assert_equal(ssystem.number_spins(), 2) npt.assert_equal(ssystem.get(pp), CalculatorComplex(5)) npt.assert_equal(ssystem.keys(), [pp]) dimension = 4**ssystem.number_spins() matrix = sp.coo_matrix(ssystem.sparse_matrix_superoperator_coo(), shape=(dimension, dimension))
- add_operator_product(key, value)
Add a new (key object, value Union[CalculatorComplex, CalculatorFloat]) pair to existing entries.
- Parameters:
key (Product type) -- The key object
- Raises:
TypeError -- Value is not CalculatorComplex or CalculatorFloat.
ValueError -- Product could not be constructed.
ValueError -- Error in add_operator_product function of self.
- current_number_spins()
Return maximum spin index in self.
- Returns:
Maximum index.
- Return type:
int
- static current_version()
Returns the current version of the struqture library .
- Returns:
The current version of the library.
- Return type:
str
- empty_clone(capacity=None)
Return an instance of self that has no entries but clones all other properties, with the given capacity.
- Parameters:
capacity (Optional[int]) -- The capacity of the new instance to create.
- Returns:
An empty clone with the same properties as self, with the given capacity.
- Return type:
self
- static from_bincode(input)
Convert the bincode representation of self to an instance using the [bincode] crate.
- Parameters:
input (bytearray) -- The serialized object (in [bincode] form).
- Returns:
The deserialized object.
- Raises:
TypeError -- Input cannot be converted to byte array.
ValueError -- Input cannot be deserialized.
- static from_json(input)
Convert the json representation of self to an instance.
- Parameters:
input (str) -- The serialized object in json form.
- Returns:
The deserialized object.
- Raises:
ValueError -- Input cannot be deserialized.
- get(key)
Get the coefficient corresponding to the key.
- Parameters:
key -- Product to get the value of.
- Returns:
Value at key (or 0.0).
- Return type:
CalculatorComplex
- Raises:
ValueError -- Product could not be constructed from key.
- hermitian_conjugate()
Return the hermitian conjugate of self.
- Returns:
The hermitian conjugate of self.
- Return type:
self
- is_empty()
Return true if self contains no values.
- Returns:
Whether self is empty or not.
- Return type:
bool
- jordan_wigner()
Transform the given spin object into a fermionic object using the Jordan Wigner mapping.
- static json_schema()
Return the JsonSchema for the json serialisation of the class.
- Returns:
The json schema serialized to json
- Return type:
str
- keys()
Return a list of the unsorted keys in self.
- Returns:
The sequence of keys of the self.
- Return type:
List[OperatorProduct]
- min_supported_version()
Return the minimum version of struqture that supports this object.
- Returns:
The minimum version of the struqture library to deserialize this object.
- Return type:
str
- number_spins()
Return the number_spins input of self.
- Returns:
The number of spins in self.
- Return type:
int
- remove(key)
Remove the value of the input key.
- Parameters:
key -- The key of the value to remove.
- Raises:
ValueError -- Product could not be constructed.
- separate_into_n_terms(number_spins)
Separate self into an operator with the terms of given number of spins and an operator with the remaining operations.
- Parameters:
number_spins (int) -- Number of spins to filter for in the keys.
- Returns:
Operator with the noise terms where the number of spins matches the number of spins the operator product acts on and Operator with all other contributions.
- Return type:
Tuple[Self, Self]
- Raises:
ValueError -- Error in adding terms to return values.
- set(key, value)
Overwrite an existing entry or set a new entry in self.
- Parameters:
key (Product type) -- The key to set.
value (Union[CalculatorComplex, CalculatorFloat]) -- The value to set.
- Returns:
Key existed if this is not None, and this is the value it had before it was overwritten.
- Return type:
Optional[Union[CalculatorComplex, CalculatorFloat]]
- Raises:
ValueError -- Product could not be constructed.
- sparse_lindblad_entries()
Output the Lindblad entries in the form (left, right, rate) where left/right are the left and right lindblad operators, and rate is the lindblad rate respectively.
- Returns:
The matrix representation of the noise part of self.
- Return type:
List[Tuple[Tuple[np.ndarray, Tuple[np.ndarray, np.ndarray]], Tuple[np.ndarray, Tuple[np.ndarray, np.ndarray]], complex]]
- Raises:
ValueError -- CalculatorError.
RuntimeError -- Could not convert to complex superoperator matrix.
- sparse_matrix_coo(number_spins=None)
Constructs the sparse matrix representation of self as a scipy COO matrix with a given number of spins.
- Parameters:
number_spins (Optional[int]) -- The number of spins in self.
- Returns:
The matrix representation of self.
- Return type:
Tuple[np.ndarray, Tuple[np.ndarray, np.ndarray]]
- Raises:
ValueError -- CalculatorError.
RuntimeError -- Could not convert to complex superoperator matrix.
- sparse_matrix_superoperator_coo(number_spins=None)
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.
- Parameters:
number_spins -- The number of spins to construct the matrix for.
- Returns:
The matrix representation of self.
- Return type:
Tuple[np.ndarray, Tuple[np.ndarray, np.ndarray]]
- Raises:
ValueError -- CalculatorError.
RuntimeError -- Could not convert to complex superoperator matrix.
- to_bincode()
Return the bincode representation of self using the [bincode] crate.
- Returns:
The serialized object (in [bincode] form).
- Return type:
bytearray
- Raises:
ValueError -- Cannot serialize object to bytes.
- to_json()
Return the json representation of self.
- Returns:
The serialized form of self.
- Return type:
str
- Raises:
ValueError -- Cannot serialize object to json.
- truncate(threshold)
Truncate self by returning a copy without entries under a threshold.
- Parameters:
threshold (float) -- The threshold for inclusion.
- Returns:
The truncated version of self.
- Return type:
self
- unitary_sparse_matrix_coo()
Return the unitary part of the superoperator in the sparse COO format.
- Returns:
The matrix representation of the unitary part of self.
- Return type:
Tuple[np.ndarray, Tuple[np.ndarray, np.ndarray]]
- Raises:
ValueError -- CalculatorError.
RuntimeError -- Could not convert to complex superoperator matrix.
- values()
Return unsorted values in self.
- Returns:
The sequence of values of self.
- Return type:
List[Union[CalculatorComplex, CalculatorFloat]]
- class struqture_py.SpinLindbladNoiseSystem(number_spins=None)
These are representations of noisy systems of spins.
In a SpinLindbladNoiseSystem is characterized by a SpinLindbladNoiseOperator to represent the hamiltonian of the spin system, and an optional number of spins.
- Parameters:
number_spins (Optional[int]) -- The number of spins in the SpinLindbladNoiseSystem.
- Returns:
The new SpinLindbladNoiseSystem with the input number of spins.
- Return type:
self
Examples
import numpy.testing as npt import scipy.sparse as sp from qoqo_calculator_pyo3 import CalculatorComplex from struqture_py.spins import SpinLindbladNoiseSystem, DecoherenceProduct slns = SpinLindbladNoiseSystem() dp = DecoherenceProduct().z(0).x(1) slns.add_operator_product((dp, dp), 2.0) npt.assert_equal(slns.current_number_spins(), 2) npt.assert_equal(slns.get((dp, dp)), CalculatorComplex(2)) npt.assert_equal(slns.keys(), [(dp, dp)]) dimension = 4**slns.number_spins() matrix = sp.coo_matrix(slns.sparse_matrix_superoperator_coo(), shape=(dimension, dimension))
- add_operator_product(key, value)
Adds a new (key object, CalculatorComplex) pair to existing entries.
- Parameters:
key (Tuple[Product type, Product type]) -- The key of the value to add.
value (CalculatorComplex) -- The value to add.
- Raises:
TypeError -- Value is not CalculatorComplex or CalculatorFloat.
ValueError -- Left-hand product could not be constructed.
ValueError -- Right-hand product could not be constructed.
ValueError -- Error in add_operator_product function of self.
- current_number_spins()
Return maximum spin index in object.
- Returns:
Maximum index.
- Return type:
int
- static current_version()
Returns the current version of the struqture library .
- Returns:
The current version of the library.
- Return type:
str
- empty_clone(capacity=None)
Return an instance of self that has no entries but clones all other properties, with the given capacity.
- Parameters:
capacity -- The capacity of the object to create.
- Returns:
An empty clone with the same properties as self, with the given capacity.
- Return type:
self
- static from_bincode(input)
Convert the bincode representation of the object to an instance using the [bincode] crate.
- Parameters:
input (bytearray) -- The serialized object (in [bincode] form).
- Returns:
The deserialized object.
- Raises:
TypeError -- Input cannot be converted to byte array.
ValueError -- Input cannot be deserialized.
- static from_json(input)
Convert the json representation of the object to an instance.
- Parameters:
input (str) -- The serialized object in json form.
- Returns:
The deserialized object.
- Raises:
ValueError -- Input cannot be deserialized.
- get(key)
Get the coefficient corresponding to the key.
- Parameters:
key (Tuple[Product type, Product type]) -- Product to get the value of.
- Returns:
Value at key (or 0.0).
- Return type:
CalculatorComplex
- Raises:
ValueError -- Left-hand product could not be constructed from key.
ValueError -- Right-hand product could not be constructed from key.
- is_empty()
Return true if object contains no values.
- Returns:
Whether self is empty or not.
- Return type:
bool
- jordan_wigner()
Transform the given spin object into a fermionic object using the Jordan Wigner mapping.
- static json_schema()
Return the JsonSchema for the json serialisation of the class.
- Returns:
The json schema serialized to json
- Return type:
str
- keys()
Return unsorted keys in self.
- Returns:
The sequence of keys of self.
- Return type:
List[(OperatorProduct, OperatorProduct)]
- min_supported_version()
Return the minimum version of struqture that supports this object.
- Returns:
The minimum version of the struqture library to deserialize this object.
- Return type:
str
- number_spins()
Return the number_spins input of self.
- Returns:
The number of spins in self.
- Return type:
int
- remove(key)
Remove the value of the input object key.
- Parameters:
key (Tuple[Product type, Product type]) -- The key of the value to remove.
- Returns:
Key existed if this is not None, and this is the value it had before it was removed.
- Return type:
Optional[CalculatorComplex]
- Raises:
ValueError -- Left-hand Product could not be constructed.
ValueError -- Right-hand Product could not be constructed.
- separate_into_n_terms(number_spins_left, number_spins_right)
Separate self into an operator with the terms of given number of spins and an operator with the remaining operations.
- Parameters:
number_spins_left (int) -- Number of spins to filter for in the left term of the keys.
number_spins_right (int) -- Number of spins to filter for in the right term of the keys.
- Returns:
Operator with the noise terms where the number of spins matches the number of spins the operator product acts on and Operator with all other contributions.
- Return type:
- Raises:
ValueError -- Error in adding terms to return values.
- set(key, value)
Overwrite an existing entry or set a new entry in self.
- Parameters:
key (Tuple[Product type, Product type]) -- The key of the value to set.
value (CalculatorComplex) -- The value to set.
- Returns:
Key existed if this is not None, and this is the value it had before it was overwritten.
- Return type:
Optional[CalculatorComplex]
- Raises:
ValueError -- Left-hand Product could not be constructed.
ValueError -- Right-hand Product could not be constructed.
- sparse_lindblad_entries()
Output the Lindblad entries in the form (left, right, rate) where left/right are the left and right lindblad operators, and rate is the lindblad rate respectively.
- Returns:
The matrix representation of the noise part of self.
- Return type:
List[Tuple[Tuple[np.ndarray, Tuple[np.ndarray, np.ndarray]], Tuple[np.ndarray, Tuple[np.ndarray, np.ndarray]], complex]]
- Raises:
ValueError -- CalculatorError.
RuntimeError -- Could not convert to complex superoperator matrix.
- sparse_matrix_superoperator_coo(number_spins=None)
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.
- Parameters:
number_spins -- The number of spins in self.
- Returns:
The matrix representation of self.
- Return type:
Tuple[np.ndarray, Tuple[np.ndarray, np.ndarray]]
- Raises:
ValueError -- CalculatorError.
RuntimeError -- Could not convert to complex superoperator matrix.
- to_bincode()
Return the bincode representation of the object using the [bincode] crate.
- Returns:
The serialized object (in [bincode] form).
- Return type:
bytearray
- Raises:
ValueError -- Cannot serialize object to bytes.
- to_json()
Return the json representation of the object.
- Returns:
The serialized form of the object.
- Return type:
str
- Raises:
ValueError -- Cannot serialize object to json.
- truncate(threshold)
Truncate self by returning a copy without entries under a threshold.
- Parameters:
threshold -- The threshold for inclusion.
- Returns:
The truncated version of self.
- Return type:
self
- unitary_sparse_matrix_coo()
Return the unitary part of the superoperator in the sparse COO format.
- Returns:
The matrix representation of the unitary part of self.
- Return type:
Tuple[np.ndarray, Tuple[np.ndarray, np.ndarray]]
- Raises:
ValueError -- CalculatorError.
RuntimeError -- Could not convert to complex superoperator matrix.
- values()
Return unsorted values in self.
- Returns:
The sequence of values of self.
- Return type:
List[CalculatorComplex]
- class struqture_py.SpinLindbladOpenSystem(number_spins=None)
These are representations of noisy systems of spins.
In a SpinLindbladOpenSystem is characterized by a SpinLindbladOpenOperator to represent the hamiltonian of the system, and an optional number of spins.
- Parameters:
number_spins (Optional[int]) -- The number of spins in the SpinLindbladOpenSystem.
- Returns:
The new SpinLindbladOpenSystem with the input number of spins.
- Return type:
Examples
import numpy.testing as npt import scipy.sparse as sp from qoqo_calculator_pyo3 import CalculatorComplex, CalculatorFloat from struqture_py.spins import SpinLindbladOpenSystem, DecoherenceProduct slns = SpinLindbladOpenSystem() dp = DecoherenceProduct().z(0).x(1) slns.system_add_operator_product(dp, 2.0) npt.assert_equal(slns.current_number_spins(), 2) npt.assert_equal(slns.system().get(dp), CalculatorFloat(2)) dimension = 4**slns.number_spins() matrix = sp.coo_matrix(slns.sparse_matrix_superoperator_coo(), shape=(dimension, dimension))
- current_number_spins()
Return maximum spin index in object.
- Returns:
Maximum index.
- Return type:
int
- static current_version()
Returns the current version of the struqture library .
- Returns:
The current version of the library.
- Return type:
str
- empty_clone()
Return an instance of self that has no entries but clones all other properties, with the given capacity.
- Returns:
An empty clone with the same properties as self, with the given capacity.
- Return type:
self
- static from_bincode(input)
Convert the bincode representation of the object to an instance using the [bincode] crate.
- Parameters:
input (bytearray) -- The serialized object (in [bincode] form).
- Returns:
The deserialized object.
- Raises:
TypeError -- Input cannot be converted to byte array.
ValueError -- Input cannot be deserialized.
- static from_json(input)
Convert the json representation of the object to an instance.
- Parameters:
input (str) -- The serialized object in json form.
- Returns:
The deserialized object.
- Raises:
ValueError -- Input cannot be deserialized.
- static group(system, noise)
Take a tuple of a system term and a noise term and combines them to be a OpenSystem.
- Parameters:
system -- The system to have in the new instance.
noise -- The noise to have in the new instance.
- Returns:
The OpenSystem with input system and noise terms.
- Return type:
self
- Raises:
ValueError -- System could not be constructed.
ValueError -- Noise could not be constructed.
ValueError -- Grouping could not be constructed.
- jordan_wigner()
Transform the given spin object into a fermionic object using the Jordan Wigner mapping.
- static json_schema()
Return the JsonSchema for the json serialisation of the class.
- Returns:
The json schema serialized to json
- Return type:
str
- min_supported_version()
Return the minimum version of struqture that supports this object.
- Returns:
The minimum version of the struqture library to deserialize this object.
- Return type:
str
- noise()
Return the noise part of self.
- Returns:
The noise of self.
- Return type:
Noise type
- noise_add_operator_product(key, value)
Add a new entry to the system of the open system.
- Parameters:
key (Tuple[Product type, Product type]) -- Tuple of Products of set object.
value (CalculatorComplex) -- Value of set object.
- Returns:
The OpenSystem with the new entry.
- Return type:
OpenSystem
- Raises:
ValueError -- Left key element cannot be converted to product.
ValueError -- Right key element cannot be converted to product.
TypeError -- Value cannot be converted to CalculatorComplex.
- noise_get(key)
Get the CalculatorComplex coefficient corresponding to the key.
- Parameters:
key (Tuple[Product type, Product type]) -- Tuple of Products of set object.
- Returns:
Value at key (or 0.0).
- Return type:
CalculatorComplex
- Raises:
ValueError -- Left key element cannot be converted to product.
ValueError -- Right key element cannot be converted to product.
- noise_set(key, value)
Set a new entry in the noise of the open system.
- Parameters:
key (Tuple[Product type, Product type]) -- Tuple of Products of set object.
value (CalculatorComplex) -- CalculatorComplex value of set object.
- Returns:
The OpenSystem with the new entry.
- Return type:
OpenSystem
- Raises:
ValueError -- Left key element cannot be converted to product.
ValueError -- Right key element cannot be converted to product.
TypeError -- Value cannot be converted to Union[CalculatorComplex, CalculatorFloat].
- number_spins()
Return the number_spins input of self.
- Returns:
The number of spins in self.
- Return type:
int
- sparse_lindblad_entries()
Output the Lindblad entries in the form (left, right, rate) where left/right are the left and right lindblad operators, and rate is the lindblad rate respectively.
- Returns:
The matrix representation of the noise part of self.
- Return type:
List[Tuple[Tuple[np.ndarray, Tuple[np.ndarray, np.ndarray]], Tuple[np.ndarray, Tuple[np.ndarray, np.ndarray]], complex]]
- Raises:
ValueError -- CalculatorError.
RuntimeError -- Could not convert to complex superoperator matrix.
- sparse_matrix_superoperator_coo(number_spins=None)
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.
- Parameters:
number_spins -- The number of spins in self.
- Returns:
The matrix representation of self.
- Return type:
Tuple[np.ndarray, Tuple[np.ndarray, np.ndarray]]
- Raises:
ValueError -- CalculatorError.
RuntimeError -- Could not convert to complex superoperator matrix.
- system()
Return the system part of self.
- Returns:
The system of self.
- Return type:
System type
- system_add_operator_product(key, value)
Add a new entry to the system of the open system.
- Parameters:
key (Product type) -- Product key of set object.
value (Union[CalculatorComplex, CalculatorFloat]) -- Value of set object.
- Returns:
The OpenSystem with the new entry.
- Return type:
OpenSystem
- Raises:
ValueError -- key element cannot be converted to product.
TypeError -- Value cannot be converted to Union[CalculatorComplex, CalculatorFloat].
- system_get(key)
Get the CalculatorComplex or CalculatorFloat coefficient corresponding to the key.
- Parameters:
key (Product type) -- Product key of set object.
- Returns:
Value at key (or 0.0).
- Return type:
CalculatorComplex or CalculatorFloat
- Raises:
ValueError -- key element cannot be converted to product.
- system_set(key, value)
Set a new entry in the system of the open system.
- Parameters:
key (Product type) -- Product key of set object.
value (Union[CalculatorComplex, CalculatorFloat]) -- Value of set object.
- Returns:
The OpenSystem with the new entry.
- Return type:
OpenSystem
- Raises:
ValueError -- key element cannot be converted to product.
TypeError -- Value cannot be converted to Union[CalculatorComplex, CalculatorFloat].
- to_bincode()
Return the bincode representation of the object using the [bincode] crate.
- Returns:
The serialized object (in [bincode] form).
- Return type:
bytearray
- Raises:
ValueError -- Cannot serialize object to bytes.
- to_json()
Return the json representation of the object.
- Returns:
The serialized form of the object.
- Return type:
str
- Raises:
ValueError -- Cannot serialize object to json.
- truncate(threshold)
Truncate self by returning a copy without entries under a threshold.
- Parameters:
threshold -- The threshold for inclusion.
- Returns:
The truncated version of self.
- Return type:
self
- ungroup()
Return a tuple of the system and the noise of self.
- Returns:
The system and noise of self.
- Return type:
(System, Noise)
- unitary_sparse_matrix_coo()
Return the unitary part of the superoperator in the sparse COO format.
- Returns:
The matrix representation of the unitary part of self.
- Return type:
Tuple[np.ndarray, Tuple[np.ndarray, np.ndarray]]
- Raises:
ValueError -- CalculatorError.
RuntimeError -- Could not convert to complex superoperator matrix.
- class struqture_py.SpinSystem(number_spins=None)
These are representations of systems of spins.
SpinSystems are characterized by a SpinOperator to represent the hamiltonian of the spin system and an optional number of spins.
- Args:
number_spins (Optional[int]): The number of spins in the SpinSystem.
- Returns:
The new SpinSystem with the input number of spins.
- Return type:
self
Examples
import numpy.testing as npt import scipy.sparse as sp from qoqo_calculator_pyo3 import CalculatorComplex from struqture_py.spins import SpinSystem, PauliProduct ssystem = SpinSystem(2) pp = PauliProduct().z(0) ssystem.add_operator_product(pp, 5.0) npt.assert_equal(ssystem.number_spins(), 2) npt.assert_equal(ssystem.get(pp), CalculatorComplex(5)) npt.assert_equal(ssystem.keys(), [pp]) dimension = 4**ssystem.number_spins() matrix = sp.coo_matrix(ssystem.sparse_matrix_superoperator_coo(), shape=(dimension, dimension))
- add_operator_product(key, value)
Add a new (key object, value Union[CalculatorComplex, CalculatorFloat]) pair to existing entries.
- Parameters:
key (Product type) -- The key object
- Raises:
TypeError -- Value is not CalculatorComplex or CalculatorFloat.
ValueError -- Product could not be constructed.
ValueError -- Error in add_operator_product function of self.
- current_number_spins()
Return maximum spin index in self.
- Returns:
Maximum index.
- Return type:
int
- static current_version()
Returns the current version of the struqture library .
- Returns:
The current version of the library.
- Return type:
str
- empty_clone(capacity=None)
Return an instance of self that has no entries but clones all other properties, with the given capacity.
- Parameters:
capacity (Optional[int]) -- The capacity of the new instance to create.
- Returns:
An empty clone with the same properties as self, with the given capacity.
- Return type:
self
- static from_bincode(input)
Convert the bincode representation of self to an instance using the [bincode] crate.
- Parameters:
input (bytearray) -- The serialized object (in [bincode] form).
- Returns:
The deserialized object.
- Raises:
TypeError -- Input cannot be converted to byte array.
ValueError -- Input cannot be deserialized.
- static from_json(input)
Convert the json representation of self to an instance.
- Parameters:
input (str) -- The serialized object in json form.
- Returns:
The deserialized object.
- Raises:
ValueError -- Input cannot be deserialized.
- get(key)
Get the coefficient corresponding to the key.
- Parameters:
key -- Product to get the value of.
- Returns:
Value at key (or 0.0).
- Return type:
CalculatorComplex
- Raises:
ValueError -- Product could not be constructed from key.
- hermitian_conjugate()
Return the hermitian conjugate of self.
- Returns:
The hermitian conjugate of self.
- Return type:
self
- is_empty()
Return true if self contains no values.
- Returns:
Whether self is empty or not.
- Return type:
bool
- jordan_wigner()
Transform the given spin object into a fermionic object using the Jordan Wigner mapping.
- static json_schema()
Return the JsonSchema for the json serialisation of the class.
- Returns:
The json schema serialized to json
- Return type:
str
- keys()
Return a list of the unsorted keys in self.
- Returns:
The sequence of keys of the self.
- Return type:
List[OperatorProduct]
- min_supported_version()
Return the minimum version of struqture that supports this object.
- Returns:
The minimum version of the struqture library to deserialize this object.
- Return type:
str
- number_spins()
Return the number_spins input of self.
- Returns:
The number of spins in self.
- Return type:
int
- remove(key)
Remove the value of the input key.
- Parameters:
key -- The key of the value to remove.
- Raises:
ValueError -- Product could not be constructed.
- separate_into_n_terms(number_spins)
Separate self into an operator with the terms of given number of spins and an operator with the remaining operations.
- Parameters:
number_spins (int) -- Number of spins to filter for in the keys.
- Returns:
Operator with the noise terms where the number of spins matches the number of spins the operator product acts on and Operator with all other contributions.
- Return type:
Tuple[Self, Self]
- Raises:
ValueError -- Error in adding terms to return values.
- set(key, value)
Overwrite an existing entry or set a new entry in self.
- Parameters:
key (Product type) -- The key to set.
value (Union[CalculatorComplex, CalculatorFloat]) -- The value to set.
- Returns:
Key existed if this is not None, and this is the value it had before it was overwritten.
- Return type:
Optional[Union[CalculatorComplex, CalculatorFloat]]
- Raises:
ValueError -- Product could not be constructed.
- sparse_lindblad_entries()
Output the Lindblad entries in the form (left, right, rate) where left/right are the left and right lindblad operators, and rate is the lindblad rate respectively.
- Returns:
The matrix representation of the noise part of self.
- Return type:
List[Tuple[Tuple[np.ndarray, Tuple[np.ndarray, np.ndarray]], Tuple[np.ndarray, Tuple[np.ndarray, np.ndarray]], complex]]
- Raises:
ValueError -- CalculatorError.
RuntimeError -- Could not convert to complex superoperator matrix.
- sparse_matrix_coo(number_spins=None)
Constructs the sparse matrix representation of self as a scipy COO matrix with a given number of spins.
- Parameters:
number_spins (Optional[int]) -- The number of spins in self.
- Returns:
The matrix representation of self.
- Return type:
Tuple[np.ndarray, Tuple[np.ndarray, np.ndarray]]
- Raises:
ValueError -- CalculatorError.
RuntimeError -- Could not convert to complex superoperator matrix.
- sparse_matrix_superoperator_coo(number_spins=None)
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.
- Parameters:
number_spins -- The number of spins to construct the matrix for.
- Returns:
The matrix representation of self.
- Return type:
Tuple[np.ndarray, Tuple[np.ndarray, np.ndarray]]
- Raises:
ValueError -- CalculatorError.
RuntimeError -- Could not convert to complex superoperator matrix.
- to_bincode()
Return the bincode representation of self using the [bincode] crate.
- Returns:
The serialized object (in [bincode] form).
- Return type:
bytearray
- Raises:
ValueError -- Cannot serialize object to bytes.
- to_json()
Return the json representation of self.
- Returns:
The serialized form of self.
- Return type:
str
- Raises:
ValueError -- Cannot serialize object to json.
- truncate(threshold)
Truncate self by returning a copy without entries under a threshold.
- Parameters:
threshold (float) -- The threshold for inclusion.
- Returns:
The truncated version of self.
- Return type:
self
- unitary_sparse_matrix_coo()
Return the unitary part of the superoperator in the sparse COO format.
- Returns:
The matrix representation of the unitary part of self.
- Return type:
Tuple[np.ndarray, Tuple[np.ndarray, np.ndarray]]
- Raises:
ValueError -- CalculatorError.
RuntimeError -- Could not convert to complex superoperator matrix.
- values()
Return unsorted values in self.
- Returns:
The sequence of values of self.
- Return type:
List[Union[CalculatorComplex, CalculatorFloat]]