qnet.algebra.hilbert_space_algebra module

This module defines some simple classes to describe simple and composite/tensor (i.e., multiple degree of freedom) Hilbert spaces of quantum systems.

For more details see Algebraic Manipulations.

Summary

Exceptions:

BasisNotSetError Raised if the basis or a Hilbert space dimension is requested but is not

Classes:

HilbertSpace Basic Hilbert space class from which concrete classes are derived.
LocalSpace A local Hilbert space, i.e., for a single degree of freedom.
ProductSpace Tensor product space class for an arbitrary number of LocalSpace factors.

Functions:

convert_to_spaces For all operands that are merely of type str or int, substitute LocalSpace objects with corresponding labels: For a string, just itself, for an int, a string version of that int.
empty_trivial A ProductSpace of zero Hilbert spaces should yield the TrivialSpace

Data:

FullSpace The ‘full space’, i.e.
TrivialSpace The ‘nullspace’, i.e.

__all__: BasisNotSetError, FullSpace, HilbertSpace, LocalSpace, ProductSpace, TrivialSpace

Reference

exception qnet.algebra.hilbert_space_algebra.BasisNotSetError[source]

Bases: qnet.algebra.abstract_algebra.AlgebraError

Raised if the basis or a Hilbert space dimension is requested but is not available

qnet.algebra.hilbert_space_algebra.convert_to_spaces(cls, ops, kwargs)[source]

For all operands that are merely of type str or int, substitute LocalSpace objects with corresponding labels: For a string, just itself, for an int, a string version of that int.

qnet.algebra.hilbert_space_algebra.empty_trivial(cls, ops, kwargs)[source]

A ProductSpace of zero Hilbert spaces should yield the TrivialSpace

class qnet.algebra.hilbert_space_algebra.HilbertSpace[source]

Bases: object

Basic Hilbert space class from which concrete classes are derived.

tensor(*others)[source]

Tensor product between Hilbert spaces

Parameters:others (HilbertSpace) – Other Hilbert space(s)
Returns:Tensor product space.
Return type:HilbertSpace
remove(other)[source]

Remove a particular factor from a tensor product space.

intersect(other)[source]

Find the mutual tensor factors of two Hilbert spaces.

local_factors

Return tuple of LocalSpace objects that tensored together yield this Hilbert space.

isdisjoint(other)[source]

Check whether two Hilbert spaces are disjoint (do not have any common local factors). Note that FullSpace is not disjoint with any other Hilbert space, while TrivialSpace is disjoint with any other HilbertSpace (even itself)

is_tensor_factor_of(other)[source]

Test if a space is included within a larger tensor product space. Also True if self == other.

Parameters:other (HilbertSpace) – Other Hilbert space
Return type:bool
is_strict_tensor_factor_of(other)[source]

Test if a space is included within a larger tensor product space. Not True if self == other.

dimension

Full dimension of the Hilbert space.

Raises:BasisNotSetError – if the Hilbert space has no defined basis
has_basis

True if the Hilbert space has a basis

basis_states

Yield an iterator over the states (Ket instances) that form the canonical basis of the Hilbert space

Raises:BasisNotSetError – if the Hilbert space has no defined basis
basis_state(index_or_label)[source]

Return the basis state with the given index or label.

Raises:
  • BasisNotSetError – if the Hilbert space has no defined basis
  • IndexError – if there is no basis state with the given index
  • KeyError – if there is not basis state with the given label
basis_labels

Tuple of basis labels.

Raises:BasisNotSetError – if the Hilbert space has no defined basis
is_strict_subfactor_of(other)[source]

Test whether a Hilbert space occures as a strict sub-factor in a (larger) Hilbert space

__len__()[source]

The number of LocalSpace factors / degrees of freedom.

class qnet.algebra.hilbert_space_algebra.LocalSpace(label, *, basis=None, dimension=None, local_identifiers=None, order_index=None)[source]

Bases: qnet.algebra.hilbert_space_algebra.HilbertSpace, qnet.algebra.abstract_algebra.Expression

A local Hilbert space, i.e., for a single degree of freedom.

Parameters:
  • label (str) – label (subscript) of the Hilbert space
  • basis (tuple or None) – Set an explicit basis for the Hilbert space (tuple of labels for the basis states)
  • dimension (int or None) – Specify the dimension \(n\) of the Hilbert space. This implies a basis numbered from 0 to \(n-1\).
  • local_identifiers (dict) – Mapping of class names of LocalOperator subclasses to identifier names. Used e.g. ‘b’ instead of the default ‘a’ for the anihilation operator. This can be a dict or a dict-compatible structure, e.g. a list/tuple of key-value tuples.
  • order_index (int or None) – An optional key that determines the preferred order of Hilbert spaces. This also changes the order of e.g. sums or products of Operators. Hilbert spaces will be ordered from left to right be increasing order_index; Hilbert spaces without an explicit order_index are sorted by their label
args

List of arguments, consisting only of label

label

Label of the Hilbert space

has_basis

True if the Hilbert space has a basis

basis_states

Yield an iterator over the states (BasisKet instances) that form the canonical basis of the Hilbert space

Raises:BasisNotSetError – if the Hilbert space has no defined basis
basis_state(index_or_label)[source]

Return the basis state with the given index or label.

Raises:
  • BasisNotSetError – if the Hilbert space has no defined basis
  • IndexError – if there is no basis state with the given index
  • KeyError – if there is not basis state with the given label
basis_labels

Tuple of basis labels.

Raises:BasisNotSetError – if the Hilbert space has no defined basis
dimension

Dimension of the Hilbert space.

Raises:BasisNotSetError – if the Hilbert space has no defined basis
kwargs
minimal_kwargs
all_symbols()[source]

Empty list

remove(other)[source]
intersect(other)[source]
local_factors
is_strict_subfactor_of(other)[source]
next_basis_label_or_index(label_or_index, n=1)[source]

Given the label or index of a basis state, return the label/index of the next basis state.

More generally, if n is given, return the n’th next basis state label/index; n may also be negative to obtain previous basis state labels/indices.

The return type is the same as the type of label_or_index.

Parameters:
  • label_or_index (int or str) – If int, the index of a basis state; if str, the label of a basis state
  • n (int) – The increment
Raises:
  • IndexError – If going beyond the last or first basis state
  • ValueError – If label is not a label for any basis state in the Hilbert space
  • BasisNotSetError – If the Hilbert space has no defined basis
  • TypeError – if label_or_index is neither a str nor an int
qnet.algebra.hilbert_space_algebra.TrivialSpace = TrivialSpace[source]

The ‘nullspace’, i.e. a one dimensional Hilbert space, which is a factor space of every other Hilbert space.

qnet.algebra.hilbert_space_algebra.FullSpace = FullSpace[source]

The ‘full space’, i.e. a Hilbert space that includes any other Hilbert space as a tensor factor.

The FullSpace has no defined basis, any related properties will raise BasisNotSetError

class qnet.algebra.hilbert_space_algebra.ProductSpace(*local_spaces)[source]

Bases: qnet.algebra.hilbert_space_algebra.HilbertSpace, qnet.algebra.abstract_algebra.Operation

Tensor product space class for an arbitrary number of LocalSpace factors.

>>> hs1 = LocalSpace('1', basis=(0,1))
>>> hs2 = LocalSpace('2', basis=(0,1))
>>> hs = hs1 * hs2
>>> hs.basis_labels
('0,0', '0,1', '1,0', '1,1')
neutral_element = TrivialSpace

The ‘nullspace’, i.e. a one dimensional Hilbert space, which is a factor space of every other Hilbert space.

classmethod create(*local_spaces)[source]
has_basis

True if the all the local factors of the ProductSpace have a defined basis

basis_states

Yield an iterator over the states (TensorKet instances) that form the canonical basis of the Hilbert space

Raises:BasisNotSetError – if the Hilbert space has no defined basis
basis_labels

Tuple of basis labels. Each basis label consists of the labels of the BasisKet states that factor the basis state, separated by commas.

Raises:BasisNotSetError – if the Hilbert space has no defined basis
basis_state(index_or_label)[source]

Return the basis state with the given index or label.

Raises:
  • BasisNotSetError – if the Hilbert space has no defined basis
  • IndexError – if there is no basis state with the given index
  • KeyError – if there is not basis state with the given label
dimension

Dimension of the Hilbert space.

Raises:BasisNotSetError – if the Hilbert space has no defined basis
remove(other)[source]

Remove a particular factor from a tensor product space.

local_factors

The LocalSpace instances that make up the product

classmethod order_key(obj)[source]

Key by which operands are sorted

intersect(other)[source]

Find the mutual tensor factors of two Hilbert spaces.

is_strict_subfactor_of(other)[source]

Test if a space is included within a larger tensor product space. Not True if self == other.