struqture_py.mixed_systems

Module for representing mixed physical systems.

A mixed physical system can contain any combination of none, one, or several subsystems of spin, bosonic, or fermionic types. For example a mixed system with two spin-subsystems or a mixed system with a bosonic-subsystem and a bosonic-subsystem would both be valid.

This module, here the python inferface for struqture, can be used to represent mixed quantum indices (MixedProduct, HermitianMixedProduct and MixedDecoherenceProduct), mixed systems (MixedOperator and MixedHamiltonian) and Lindblad type mixed open systems (MixedLindbladNoiseOperator and MixedLindbladOpenSystem).

MixedProduct(spins, bosons, fermions)

A mixed product of pauli products and boson products.

HermitianMixedProduct(spins, bosons, fermions)

A mixed product of pauli products and boson products.

MixedDecoherenceProduct(spins, bosons, fermions)

A mixed product of pauli products and boson products.

MixedOperator(number_spins, number_bosons, ...)

These are representations of systems of mixed_systems.

MixedHamiltonian(number_spins, ...)

These are representations of systems of mixed_systems.

MixedLindbladNoiseOperator(number_spins, ...)

These are representations of noisy systems of mixed_systems.

MixedLindbladOpenSystem(number_spins, ...)

These are representations of noisy systems of mixed_systems.

MixedPlusMinusProduct(spins, bosons, fermions)

A mixed product of pauli products and boson products.

MixedPlusMinusOperator(number_spins, ...)

These are representations of systems of mixed_systems.

Classes

HermitianMixedProduct(spins, bosons, fermions)

A mixed product of pauli products and boson products.

MixedDecoherenceProduct(spins, bosons, fermions)

A mixed product of pauli products and boson products.

MixedHamiltonian(number_spins, ...)

These are representations of systems of mixed_systems.

MixedLindbladNoiseOperator(number_spins, ...)

These are representations of noisy systems of mixed_systems.

MixedLindbladOpenSystem(number_spins, ...)

These are representations of noisy systems of mixed_systems.

MixedOperator(number_spins, number_bosons, ...)

These are representations of systems of mixed_systems.

MixedPlusMinusOperator(number_spins, ...)

These are representations of systems of mixed_systems.

MixedPlusMinusProduct(spins, bosons, fermions)

A mixed product of pauli products and boson products.

MixedProduct(spins, bosons, fermions)

A mixed product of pauli products and boson products.

class struqture_py.mixed_systems.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:

HermitianMixedProduct

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)

Convert a json corresponding to a struqture 1 object to the equivalent object in struqture 2.

Parameters:

input (Any) -- the json of the struqture 1 object to convert.

Returns:

the input object in struqture 2 form.

Return type:

Any

Raises:
  • ValueError -- Input could not be deserialised form json.

  • ValueError -- Struqture 1 object could not be converted to struqture 2.

static from_string(input)

Convert a string representation of the object to an instance.

Parameters:

input (str) -- The serialized index in str representation.

Returns:

The converted object.

Return type:

self

Raises:

ValueError -- Input cannot be converted from str.

hermitian_conjugate()

Return the hermitian conjugate of self and its prefactor.

Returns:

The hermitian conjugate of self and the potential sign it has picked up.

Return type:

(self, float)

is_natural_hermitian()

Return whether self is naturally hermitian.

For spin objects, this is true when applying the hermitian conjugation does not change the sign. For bosonic and fermionic objects, this is true when creators == annihilators. For mixed objects, this is true when all of the spin, bosonic and fermionic parts' is_naturally_hermitian functions evaluate to true.

Returns:

Whether self is naturally hermitian or not.

Return type:

bool

static json_schema()

Return the JsonSchema for the json serialisation of the class.

Returns:

The json schema serialized to json

Return type:

str

min_supported_version()

Return the minimum version of struqture that supports this object.

Returns:

The minimum version of the struqture library to deserialize this object.

Return type:

str

spins()

Get the spin products of self.

Returns:

The spin products of self.

Return type:

List[str]

to_bincode()

Return the bincode representation of the object using the [bincode] crate.

Returns:

The serialized object (in [bincode] form).

Return type:

bytearray

Raises:

ValueError -- Cannot serialize object to bytes.

to_json()

Return the json representation of the object.

Returns:

The serialized form of the object.

Return type:

str

Raises:

ValueError -- Cannot serialize object to json.

class struqture_py.mixed_systems.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:

MixedDecoherenceProduct

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)

Convert a json corresponding to a struqture 1 object to the equivalent object in struqture 2.

Parameters:

input (Any) -- the json of the struqture 1 object to convert.

Returns:

the input object in struqture 2 form.

Return type:

Any

Raises:
  • ValueError -- Input could not be deserialised form json.

  • ValueError -- Struqture 1 object could not be converted to struqture 2.

static from_string(input)

Convert a string representation of the object to an instance.

Parameters:

input (str) -- The serialized index in str representation.

Returns:

The converted object.

Return type:

self

Raises:

ValueError -- Input cannot be converted from str.

hermitian_conjugate()

Return the hermitian conjugate of self and its prefactor.

Returns:

The hermitian conjugate of self and the potential sign it has picked up.

Return type:

(self, float)

is_natural_hermitian()

Return whether self is naturally hermitian.

For spin objects, this is true when applying the hermitian conjugation does not change the sign. For bosonic and fermionic objects, this is true when creators == annihilators. For mixed objects, this is true when all of the spin, bosonic and fermionic parts' is_naturally_hermitian functions evaluate to true.

Returns:

Whether self is naturally hermitian or not.

Return type:

bool

static json_schema()

Return the JsonSchema for the json serialisation of the class.

Returns:

The json schema serialized to json

Return type:

str

min_supported_version()

Return the minimum version of struqture that supports this object.

Returns:

The minimum version of the struqture library to deserialize this object.

Return type:

str

spins()

Get the spin products of self.

Returns:

The spin products of self.

Return type:

List[str]

to_bincode()

Return the bincode representation of the object using the [bincode] crate.

Returns:

The serialized object (in [bincode] form).

Return type:

bytearray

Raises:

ValueError -- Cannot serialize object to bytes.

to_json()

Return the json representation of the object.

Returns:

The serialized form of the object.

Return type:

str

Raises:

ValueError -- Cannot serialize object to json.

class struqture_py.mixed_systems.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

system = MixedHamiltonian(1, 1, 1)
pp = HermitianMixedProduct([PauliProduct().z(0)], [BosonProduct([0], [1])], [FermionProduct([0], [0])])
system.add_operator_product(pp, 5.0)
npt.assert_equal(system.current_number_spins(), [2])
npt.assert_equal(system.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

  • value (Union[CalculatorComplex, CalculatorFloat]) -- The value to add.

Raises:
  • TypeError -- Value is not CalculatorComplex or CalculatorFloat.

  • ValueError -- Product could not be constructed.

  • ValueError -- Error in add_operator_product function of self.

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:

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

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)

Convert a json corresponding to a struqture 1 object to the equivalent object in struqture 2.

Parameters:

input (Any) -- the json of the struqture 1 object to convert.

Returns:

the input object in struqture 2 form.

Return type:

Any

Raises:
  • ValueError -- Input could not be deserialised form json.

  • ValueError -- Struqture 1 object could not be converted to struqture 2.

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.mixed_systems.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:

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

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)

Convert a json corresponding to a struqture 1 object to the equivalent object in struqture 2.

Parameters:

input (Any) -- the json of the struqture 1 object to convert.

Returns:

the input object in struqture 2 form.

Return type:

Any

Raises:
  • ValueError -- Input could not be deserialised form json.

  • ValueError -- Struqture 1 object could not be converted to struqture 2.

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.mixed_systems.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:

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

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)

Convert a json corresponding to a struqture 1 object to the equivalent object in struqture 2.

Parameters:

input (Any) -- the json of the struqture 1 object to convert.

Returns:

the input object in struqture 2 form.

Return type:

Any

Raises:
  • ValueError -- Input could not be deserialised form json.

  • ValueError -- Struqture 1 object could not be converted to struqture 2.

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.mixed_systems.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

system = MixedOperator(1, 1, 1)
pp = MixedProduct([PauliProduct().z(0)], [BosonProduct([0], [1])], [FermionProduct([0], [0])])
system.add_operator_product(pp, 5.0)
npt.assert_equal(system.current_number_spins(), [2])
npt.assert_equal(system.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

  • value (Union[CalculatorComplex, CalculatorFloat]) -- The value to add.

Raises:
  • TypeError -- Value is not CalculatorComplex or CalculatorFloat.

  • ValueError -- Product could not be constructed.

  • ValueError -- Error in add_operator_product function of self.

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:

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

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)

Convert a json corresponding to a struqture 1 object to the equivalent object in struqture 2.

Parameters:

input (Any) -- the json of the struqture 1 object to convert.

Returns:

the input object in struqture 2 form.

Return type:

Any

Raises:
  • ValueError -- Input could not be deserialised form json.

  • ValueError -- Struqture 1 object could not be converted to struqture 2.

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.mixed_systems.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

system = MixedPlusMinusOperator(1, 1, 1)
pp = MixedPlusMinusProduct([PauliProduct().z(0)], [BosonProduct([0], [1])], [FermionProduct([0], [0])])
system.add_operator_product(pp, 5.0)
npt.assert_equal(system.current_number_spins(), [2])
npt.assert_equal(system.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

  • value (Union[CalculatorComplex, CalculatorFloat]) -- The value to add.

Raises:
  • TypeError -- Value is not CalculatorComplex or CalculatorFloat.

  • ValueError -- Product could not be constructed.

  • ValueError -- Error in add_operator_product function of self.

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:

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

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)

Convert a json corresponding to a struqture 1 object to the equivalent object in struqture 2.

Parameters:

input (Any) -- the json of the struqture 1 object to convert.

Returns:

the input object in struqture 2 form.

Return type:

Any

Raises:
  • ValueError -- Input could not be deserialised form json.

  • ValueError -- Struqture 1 object could not be converted to struqture 2.

static from_mixed_operator(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:

MixedPlusMinusOperator

Raises:

ValueError -- Could not create MixedOperator from input.

get(key)

Get the coefficient corresponding to the key.

Parameters:

key -- Product to get the value of.

Returns:

Value at key (or 0.0).

Return type:

CalculatorComplex

Raises:

ValueError -- Product could not be constructed from key.

hermitian_conjugate()

Return the hermitian conjugate of self.

Returns:

The hermitian conjugate of self.

Return type:

self

is_empty()

Return true if self contains no values.

Returns:

Whether self is empty or not.

Return type:

bool

static json_schema()

Return the JsonSchema for the json serialisation of the class.

Returns:

The json schema serialized to json

Return type:

str

keys()

Return a list of the unsorted keys in self.

Returns:

The sequence of keys of the self.

Return type:

List[OperatorProduct]

min_supported_version()

Return the minimum version of struqture that supports this object.

Returns:

The minimum version of the struqture library to deserialize this object.

Return type:

str

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_operator()

Convert a MixedPlusMinusOperator into a MixedOperator.

Returns:

The operator created from the input MixedPlusMinusOperator and optional number of spins.

Return type:

MixedOperator

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.mixed_systems.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:

MixedPlusMinusProduct

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)

Convert a json corresponding to a struqture 1 object to the equivalent object in struqture 2.

Parameters:

input (Any) -- the json of the struqture 1 object to convert.

Returns:

the input object in struqture 2 form.

Return type:

Any

Raises:
  • ValueError -- Input could not be deserialised form json.

  • ValueError -- Struqture 1 object could not be converted to struqture 2.

static from_mixed_product(value)

Creates a list of corresponding (MixedPlusMinusProduct, CalculatorComplex) tuples from the input MixedProduct.

Parameters:

value (MixedProduct) -- The MixedProduct object to convert.

Returns:

The converted input.

Return type:

List[Tuple[(MixedPlusMinusProduct, CalculatorComplex)]]

Raises:

ValueError -- Input is not a MixedProduct.

static from_string(input)

Convert a string representation of the object to an instance.

Parameters:

input (str) -- The serialized index in str representation.

Returns:

The converted object.

Return type:

self

Raises:

ValueError -- Input cannot be converted from str.

hermitian_conjugate()

Return the hermitian conjugate of self and its prefactor.

Returns:

The hermitian conjugate of self and the potential sign it has picked up.

Return type:

(self, float)

is_natural_hermitian()

Return whether self is naturally hermitian.

For spin objects, this is true when applying the hermitian conjugation does not change the sign. For bosonic and fermionic objects, this is true when creators == annihilators. For mixed objects, this is true when all of the spin, bosonic and fermionic parts' is_naturally_hermitian functions evaluate to true.

Returns:

Whether self is naturally hermitian or not.

Return type:

bool

static json_schema()

Return the JsonSchema for the json serialisation of the class.

Returns:

The json schema serialized to json

Return type:

str

min_supported_version()

Return the minimum version of struqture that supports this object.

Returns:

The minimum version of the struqture library to deserialize this object.

Return type:

str

spins()

Get the spin products of self.

Returns:

The spin products of self.

Return type:

List[str]

to_bincode()

Return the bincode representation of the object using the [bincode] crate.

Returns:

The serialized object (in [bincode] form).

Return type:

bytearray

Raises:

ValueError -- Cannot serialize object to bytes.

to_json()

Return the json representation of the object.

Returns:

The serialized form of the object.

Return type:

str

Raises:

ValueError -- Cannot serialize object to json.

to_mixed_product_list()

Convert the self instance to the corresponding list of (MixedProduct, CalculatorComplex) instances.

Returns:

The converted MixedPlusMinusProduct.

Return type:

List[Tuple[(MixedProduct, CalculatorComplex)]]

Raises:

ValueError -- The conversion was not successful.

class struqture_py.mixed_systems.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:

MixedProduct

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)

Convert a json corresponding to a struqture 1 object to the equivalent object in struqture 2.

Parameters:

input (Any) -- the json of the struqture 1 object to convert.

Returns:

the input object in struqture 2 form.

Return type:

Any

Raises:
  • ValueError -- Input could not be deserialised form json.

  • ValueError -- Struqture 1 object could not be converted to struqture 2.

static from_string(input)

Convert a string representation of the object to an instance.

Parameters:

input (str) -- The serialized index in str representation.

Returns:

The converted object.

Return type:

self

Raises:

ValueError -- Input cannot be converted from str.

hermitian_conjugate()

Return the hermitian conjugate of self and its prefactor.

Returns:

The hermitian conjugate of self and the potential sign it has picked up.

Return type:

(self, float)

is_natural_hermitian()

Return whether self is naturally hermitian.

For spin objects, this is true when applying the hermitian conjugation does not change the sign. For bosonic and fermionic objects, this is true when creators == annihilators. For mixed objects, this is true when all of the spin, bosonic and fermionic parts' is_naturally_hermitian functions evaluate to true.

Returns:

Whether self is naturally hermitian or not.

Return type:

bool

static json_schema()

Return the JsonSchema for the json serialisation of the class.

Returns:

The json schema serialized to json

Return type:

str

min_supported_version()

Return the minimum version of struqture that supports this object.

Returns:

The minimum version of the struqture library to deserialize this object.

Return type:

str

spins()

Get the spin products of self.

Returns:

The spin products of self.

Return type:

List[str]

to_bincode()

Return the bincode representation of the object using the [bincode] crate.

Returns:

The serialized object (in [bincode] form).

Return type:

bytearray

Raises:

ValueError -- Cannot serialize object to bytes.

to_json()

Return the json representation of the object.

Returns:

The serialized form of the object.

Return type:

str

Raises:

ValueError -- Cannot serialize object to json.