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. |
|
These are representations of systems of bosons. |
|
|
A product of bosonic creation and annihilation operators. |
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. |
|
These are representations of systems of fermions. |
|
|
A product of fermionic creation and annihilation operators. |
|
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. |
|
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. |
PauliProducts are combinations of SingleQubitOperators 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.BosonHamiltonian
These are representations of systems of bosons.
BosonHamiltonians 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 BosonHamiltonian, HermitianBosonProduct ssystem = BosonHamiltonian(2) pp = HermitianBosonProduct([0], [0]) ssystem.add_operator_product(pp, 5.0) npt.assert_equal(ssystem.current_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 the current_number_modes input of self.
- Returns:
The number of modes in 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_json_struqture_1(input)
- static from_struqture_1(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
- 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.BosonLindbladNoiseOperator
These are representations of noisy systems of bosons.
In a BosonLindbladNoiseOperator is characterized by a BosonLindbladNoiseOperator to represent the hamiltonian of the system, and an optional number of bosons.
Examples
import numpy.testing as npt import scipy.sparse as sp from qoqo_calculator_pyo3 import CalculatorComplex from struqture_py.bosons import BosonLindbladNoiseOperator, BosonProduct slns = BosonLindbladNoiseOperator() 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 the current_number_modes input of self.
- Returns:
The number of modes in 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.
- static from_json_struqture_1(input)
- static from_struqture_1(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
- 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.
- 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
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.
- 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 the current_number_modes input of self.
- Returns:
The number of modes in 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 from_json_struqture_1(input)
- static from_struqture_1(input)
- 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].
- 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.BosonOperator
These are representations of systems of bosons.
BosonOperators are characterized by a BosonOperator to represent the hamiltonian of the spin system and an optional number of bosons.
- 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 BosonOperator, BosonProduct ssystem = BosonOperator(2) pp = BosonProduct([0], [1]) ssystem.add_operator_product(pp, 5.0) npt.assert_equal(ssystem.current_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 the current_number_modes input of self.
- Returns:
The number of modes in 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_json_struqture_1(input)
- static from_struqture_1(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
- 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.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_json_struqture_1(input)
- 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.
- static from_struqture_1(input)
- 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.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 QubitLindbladOpenSystem, SpinLindbladNoiseSystem or QubitLindbladNoiseOperator, 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_json_struqture_1(input)
- 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.
- static from_struqture_1(input)
- 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.FermionHamiltonian
These are representations of systems of fermions.
FermionHamiltonians are characterized by a FermionOperator to represent the hamiltonian of the spin system and an optional number of fermions.
- 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 FermionHamiltonian, HermitianFermionProduct ssystem = FermionHamiltonian() pp = HermitianFermionProduct([0], [0]) ssystem.add_operator_product(pp, 5.0) npt.assert_equal(ssystem.current_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 the current_number_modes input of self.
- Returns:
The number of modes in 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_json_struqture_1(input)
- static from_struqture_1(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 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
- 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.FermionLindbladNoiseOperator
These are representations of noisy systems of fermions.
In a FermionLindbladNoiseOperator is characterized by a FermionLindbladNoiseOperator to represent the hamiltonian of the system, and an optional number of fermions.
Examples
import numpy.testing as npt import scipy.sparse as sp from qoqo_calculator_pyo3 import CalculatorComplex from struqture_py.fermions import FermionLindbladNoiseOperator, FermionProduct slns = FermionLindbladNoiseOperator() 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 the current_number_modes input of self.
- Returns:
The number of modes in 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.
- static from_json_struqture_1(input)
- static from_struqture_1(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 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
- 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.FermionLindbladOpenSystem
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 the current_number_modes input of self.
- Returns:
The number of modes in 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 from_json_struqture_1(input)
- static from_struqture_1(input)
- 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].
- 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.FermionOperator
These are representations of systems of fermions.
FermionOperators are characterized by a FermionOperator to represent the hamiltonian of the spin system and an optional number of fermions.
- 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 FermionOperator, FermionProduct ssystem = FermionOperator(2) pp = FermionProduct([0], [0]) ssystem.add_operator_product(pp, 5.0) npt.assert_equal(ssystem.current_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 the current_number_modes input of self.
- Returns:
The number of modes in 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_json_struqture_1(input)
- static from_struqture_1(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 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
- 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.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_json_struqture_1(input)
- 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.
- static from_struqture_1(input)
- 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.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_json_struqture_1(input)
- 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.
- static from_struqture_1(input)
- 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_json_struqture_1(input)
- 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.
- static from_struqture_1(input)
- 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_json_struqture_1(input)
- 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.
- static from_struqture_1(input)
- 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_json_struqture_1(input)
- 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.
- static from_struqture_1(input)
- 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.MixedHamiltonian(number_spins, number_bosons, number_fermions)
These are representations of systems of mixed_systems.
MixedHamiltonians are characterized by a MixedOperator to represent the hamiltonian of the spin system and an optional number of mixed_systems.
- Parameters:
number_spins (int) -- The number of spin subsystems in the MixedHamiltonian.
number_bosons (int) -- The number of boson subsystems in the MixedHamiltonian.
number_fermions (int) -- The number of fermion subsystems in the MixedHamiltonian.
- Returns:
The new (empty) MixedHamiltonian.
- 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 MixedHamiltonian, HermitianMixedProduct from struqture_py.spins import PauliProduct from struqture_py.bosons import BosonProduct from struqture_py.fermions import FermionProduct ssystem = MixedHamiltonian(1, 1, 1) pp = HermitianMixedProduct([PauliProduct().z(0)], [BosonProduct([0], [1])], [FermionProduct([0], [0])]) ssystem.add_operator_product(pp, 5.0) npt.assert_equal(ssystem.current_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 in each bosonic subsystem of self.
- Returns:
The number of bosonic modes in each bosonic subsystem of self.
- Return type:
list[int]
- current_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]
- current_number_spins()
Return the current_number_spins input of each spin subsystem of self.
- Returns:
The number of spins 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_json_struqture_1(input)
- static from_struqture_1(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
- 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.MixedLindbladNoiseOperator(number_spins, number_bosons, number_fermions)
These are representations of noisy systems of mixed_systems.
In a MixedLindbladNoiseOperator is characterized by a MixedLindbladNoiseOperator to represent the hamiltonian of the system, and an optional number of mixed_systems.
Examples
import numpy.testing as npt import scipy.sparse as sp from qoqo_calculator_pyo3 import CalculatorComplex, CalculatorFloat from struqture_py.mixed_systems import MixedLindbladNoiseOperator, MixedDecoherenceProduct from struqture_py.spins import DecoherenceProduct from struqture_py.bosons import BosonProduct from struqture_py.fermions import FermionProduct slns = MixedLindbladNoiseOperator(1, 1, 1) 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 in each bosonic subsystem of self.
- Returns:
The number of bosonic modes in each bosonic subsystem of self.
- Return type:
list[int]
- current_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]
- current_number_spins()
Return the current_number_spins input of each spin subsystem of self.
- Returns:
The number of spins 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.
- static from_json_struqture_1(input)
- static from_struqture_1(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
- 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.
- 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, number_bosons, number_fermions)
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 (int) -- The number of spin subsystems in the MixedLindbladOpenSystem.
number_bosons (int) -- The number of boson subsystems in the MixedLindbladOpenSystem.
number_fermions (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 in each bosonic subsystem of self.
- Returns:
The number of bosonic modes in each bosonic subsystem of self.
- Return type:
list[int]
- current_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]
- current_number_spins()
Return the current_number_spins input of each spin subsystem of self.
- Returns:
The number of spins 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 from_json_struqture_1(input)
- static from_struqture_1(input)
- 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].
- 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.MixedOperator(number_spins, number_bosons, number_fermions)
These are representations of systems of mixed_systems.
MixedOperators are characterized by a MixedOperator to represent the hamiltonian of the spin system and an optional number of mixed_systems.
- Parameters:
number_spins (int) -- The number of spin subsystems in the MixedOperator.
number_bosons (int) -- The number of boson subsystems in the MixedOperator.
number_fermions (int) -- The number of fermion subsystems in the MixedOperator.
- Returns:
The new (empty) MixedOperator.
- 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 MixedOperator, MixedProduct from struqture_py.spins import PauliProduct from struqture_py.bosons import BosonProduct from struqture_py.fermions import FermionProduct ssystem = MixedOperator([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.current_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 in each bosonic subsystem of self.
- Returns:
The number of bosonic modes in each bosonic subsystem of self.
- Return type:
list[int]
- current_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]
- current_number_spins()
Return the current_number_spins input of each spin subsystem of self.
- Returns:
The number of spins 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_json_struqture_1(input)
- static from_struqture_1(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
- 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.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 (int) -- The number of spin subsystems in the MixedPlusMinusOperator.
number_bosons (int) -- The number of boson subsystems in the MixedPlusMinusOperator.
number_fermions (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.current_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 in each bosonic subsystem of self.
- Returns:
The number of bosonic modes in each bosonic subsystem of self.
- Return type:
list[int]
- current_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]
- current_number_spins()
Return the current_number_spins input of each spin subsystem of self.
- Returns:
The number of spins 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_json_struqture_1(input)
- static from_mixed_system(value)
Convert a MixedOperator into a MixedPlusMinusOperator.
- Parameters:
value (MixedOperator) -- The MixedOperator to create the MixedPlusMinusOperator from.
- Returns:
The operator created from the input MixedOperator.
- Return type:
- Raises:
ValueError -- Could not create MixedOperator from input.
- static from_struqture_1(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
- 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()
Convert a MixedPlusMinusOperator into a MixedOperator.
- 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 MixedOperator 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_json_struqture_1(input)
- 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.
- static from_struqture_1(input)
- 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_json_struqture_1(input)
- 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.
- static from_struqture_1(input)
- 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.PauliProduct
PauliProducts are combinations of SingleQubitOperators 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 QubitLindbladOpenSystem, QubitHamiltonian or QubitOperator, 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_json_struqture_1(input)
- 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.
- static from_struqture_1(input)
- 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 SingleQubitOperator 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 SingleQubitOperator 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 SingleQubitOperator 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 QubitLindbladNoiseOperator to represent the hamiltonian of the spin system, and an optional number of spins.
- Returns:
The new PlusMinusLindbladNoiseOperator.
- 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_json_struqture_1(input)
- static from_qubit_noise_operator(value)
Convert a QubitLindbladNoiseOperator into a PlusMinusLindbladNoiseOperator.
- Parameters:
value (QubitLindbladNoiseOperator) -- The QubitLindbladNoiseOperator to create the PlusMinusLindbladNoiseOperator from.
- Returns:
The operator created from the input QubitLindbladNoiseOperator.
- Return type:
- Raises:
ValueError -- Could not create QubitLindbladNoiseOperator from input.
- static from_struqture_1(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.
- 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_qubit_noise_operator()
Convert a PlusMinusLindbladNoiseOperator into a QubitLindbladNoiseOperator.
- Returns:
The operator created from the input PlusMinusLindbladNoiseOperator and optional number of spins.
- Return type:
- Raises:
ValueError -- Could not create QubitLindbladNoiseOperator 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 QubitOperator to represent the hamiltonian of the spin system and an optional number of spins.
- Returns:
The new PlusMinusOperator.
- 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.
- current_number_spins()
Return the current_number_spins input of self.
- Returns:
The number of spins in 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_json_struqture_1(input)
- static from_qubit_hamiltonian(value)
Convert a QubitHamiltonian into a PlusMinusOperator.
- Parameters:
value (QubitHamiltonian) -- The QubitHamiltonian to create the PlusMinusOperator from.
- Returns:
The operator created from the input QubitOperator.
- Return type:
- Raises:
ValueError -- Could not create QubitHamiltonian from input.
- static from_qubit_operator(value)
Convert a QubitOperator into a PlusMinusOperator.
- Parameters:
value (QubitOperator) -- The QubitOperator to create the PlusMinusOperator from.
- Returns:
The operator created from the input QubitOperator.
- Return type:
- Raises:
ValueError -- Could not create QubitOperator from input.
- static from_struqture_1(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
- number_spins()
Return maximum index in self.
- Returns:
Maximum index.
- 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_qubit_hamiltonian()
Convert a PlusMinusOperator into a QubitHamiltonian.
- Returns:
The operator created from the input PlusMinusOperator and optional number of spins.
- Return type:
- Raises:
ValueError -- Could not create QubitHamiltonian from PlusMinusOperator.
- to_qubit_operator()
Convert a PlusMinusOperator into a QubitOperator.
- Returns:
The operator created from the input PlusMinusOperator and optional number of spins.
- Return type:
- Raises:
ValueError -- Could not create QubitOperator 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_json_struqture_1(input)
- 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.
- static from_struqture_1(input)
- 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
- 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_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_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.QubitHamiltonian
These are representations of systems of spins.
QubitHamiltonians are characterized by a QubitOperator to represent the hamiltonian of the spin system and an optional number of spins.
- Returns:
The new QubitHamiltonian.
- 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 QubitHamiltonian, PauliProduct ssystem = QubitHamiltonian(2) pp = PauliProduct().z(0) ssystem.add_operator_product(pp, 5.0) npt.assert_equal(ssystem.current_number_spins(), 2) npt.assert_equal(ssystem.get(pp), CalculatorComplex(5)) npt.assert_equal(ssystem.keys(), [pp]) dimension = 4**ssystem.current_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 the current_number_spins input of self.
- Returns:
The number of spins in 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_json_struqture_1(input)
- static from_struqture_1(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
- number_spins()
Return maximum index in self.
- Returns:
Maximum index.
- 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.
- 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 little endian 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 little endian 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 little endian 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(number_spins=None)
Return the unitary part of the superoperator in the sparse COO format.
- Parameters:
number_spins -- The number of spins to construct the matrix for.
- Returns:
The little endian 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.QubitLindbladNoiseOperator
These are representations of noisy systems of spins.
In a QubitLindbladNoiseOperator is characterized by a QubitLindbladNoiseOperator to represent the hamiltonian of the spin system, and an optional number of spins.
- Returns:
The new QubitLindbladNoiseOperator.
- 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 QubitLindbladNoiseOperator, DecoherenceProduct slns = QubitLindbladNoiseOperator() 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.current_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 the current_number_spins input of self.
- Returns:
The number of spins in 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.
- static from_json_struqture_1(input)
- static from_struqture_1(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
- number_spins()
Return maximum index in self.
- Returns:
Maximum index.
- 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:
Tuple[QubitLindbladNoiseOperator, QubitLindbladNoiseOperator]
- 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 little endian 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 little endian 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(number_spins=None)
Return the unitary part of the superoperator in the sparse COO format.
- Parameters:
number_spins -- The number of spins in self.
- Returns:
The little endian 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.QubitLindbladOpenSystem
These are representations of noisy systems of spins.
In a QubitLindbladOpenSystem is characterized by a SpinLindbladOpenOperator to represent the hamiltonian of the system, and an optional number of spins.
- Returns:
The new SpinLindbladOpenSystem.
- Return type:
SpinLindbladOpenSystem
Examples
import numpy.testing as npt import scipy.sparse as sp from qoqo_calculator_pyo3 import CalculatorComplex, CalculatorFloat from struqture_py.spins import QubitLindbladOpenSystem, DecoherenceProduct slns = QubitLindbladOpenSystem() 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.current_number_spins() matrix = sp.coo_matrix(slns.sparse_matrix_superoperator_coo(), shape=(dimension, dimension))
- current_number_spins()
Return the current_number_spins input of self.
- Returns:
The number of spins in 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 from_json_struqture_1(input)
- static from_struqture_1(input)
- 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 maximum index in self.
- Returns:
Maximum index.
- 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 little endian 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 little endian 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(number_spins=None)
Return the unitary part of the superoperator in the sparse COO format.
- Parameters:
number_spins -- The number of spins in self.
- Returns:
The little endian 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.QubitOperator
These are representations of systems of spins.
QubitOperators are characterized by a QubitOperator to represent the hamiltonian of the spin system and an optional number of spins.
- Returns:
The new QubitOperator.
- 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 QubitOperator, PauliProduct ssystem = QubitOperator(2) pp = PauliProduct().z(0) ssystem.add_operator_product(pp, 5.0) npt.assert_equal(ssystem.current_number_spins(), 2) npt.assert_equal(ssystem.get(pp), CalculatorComplex(5)) npt.assert_equal(ssystem.keys(), [pp]) dimension = 4**ssystem.current_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 the current_number_spins input of self.
- Returns:
The number of spins in 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_json_struqture_1(input)
- static from_struqture_1(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
- number_spins()
Return maximum index in self.
- Returns:
Maximum index.
- 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.
- 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 little endian 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 little endian 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 little endian 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(number_spins=None)
Return the unitary part of the superoperator in the sparse COO format.
- Parameters:
number_spins -- The number of spins to construct the matrix for.
- Returns:
The little endian 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]]