qalgebra.core.hilbert_space_algebra module¶
Core class hierarchy for Hilbert spaces
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¶
Classes:
Base class for Hilbert spaces |
|
Hilbert space for a single degree of freedom. |
|
Tensor product of local Hilbert spaces. |
Data:
The ‘full space’, i.e. a Hilbert space that includes any other Hilbert space as a tensor factor. |
|
The ‘nullspace’, i.e. a one dimensional Hilbert space, which is a factor space of every other Hilbert space. |
__all__
: FullSpace
, HilbertSpace
, LocalSpace
, ProductSpace
, TrivialSpace
Reference¶
-
class
qalgebra.core.hilbert_space_algebra.
HilbertSpace
[source]¶ Bases:
object
Base class for Hilbert spaces
-
abstract property
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
ifself == other
.- Parameters
other (HilbertSpace) – Other Hilbert space
- Return type
-
is_strict_tensor_factor_of
(other)[source]¶ Test if a space is included within a larger tensor product space. Not
True
ifself == other
.
-
property
dimension
¶ Full dimension of the Hilbert space.
- Raises
BasisNotSetError – if the Hilbert space has no defined basis
-
property
has_basis
¶ True if the Hilbert space has a basis
-
property
basis_states
¶ Yield an iterator over the states (
State
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
-
property
basis_labels
¶ Tuple of basis labels.
- Raises
BasisNotSetError – if the Hilbert space has no defined basis
-
abstract property
-
class
qalgebra.core.hilbert_space_algebra.
LocalSpace
(label, *, basis=None, dimension=None, local_identifiers=None, order_index=None)[source]¶ Bases:
qalgebra.core.hilbert_space_algebra.HilbertSpace
,qalgebra.core.abstract_algebra.Expression
Hilbert space for a single degree of freedom.
- Parameters
label (str or int or StrLabel) – 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
A
LocalSpace
fundamentally has a Fock-space like structure, in that its basis states may be understood as an “excitation”. The spectrum can be infinite, with levels labeled by integers 0, 1, …:>>> hs = LocalSpace(label=0)
or truncated to a finite dimension:
>>> hs = LocalSpace(0, dimension=5) >>> hs.basis_labels ('0', '1', '2', '3', '4')
For finite-dimensional (truncated) Hilbert spaces, we also allow an arbitrary alternative labeling of the canonical basis:
>>> hs = LocalSpace('rydberg', dimension=3, basis=('g', 'e', 'r'))
-
property
args
¶ List of arguments, consisting only of label
-
property
label
¶ Label of the Hilbert space.
-
property
has_basis
¶ True if the Hilbert space has a basis.
-
property
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
-
property
basis_labels
¶ Tuple of basis labels (strings).
- Raises
BasisNotSetError – if the Hilbert space has no defined basis
-
property
dimension
¶ Dimension of the Hilbert space.
- Raises
BasisNotSetError – if the Hilbert space has no defined basis
-
property
kwargs
¶ The dictionary of keyword-only arguments for the instantiation of the Expression
-
property
minimal_kwargs
¶ A “minimal” dictionary of keyword-only arguments, i.e. a subset of kwargs that may exclude default options
-
property
local_factors
¶ Return tuple of LocalSpace objects that tensored together yield this Hilbert space.
-
is_strict_subfactor_of
(other)[source]¶ Test whether a Hilbert space occures as a strict sub-factor in a (larger) Hilbert space
-
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 or SymbolicLabelBase) – 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 anint
, nor aSymbolicLabelBase
-
class
qalgebra.core.hilbert_space_algebra.
ProductSpace
(*local_spaces)[source]¶ Bases:
qalgebra.core.hilbert_space_algebra.HilbertSpace
,qalgebra.core.abstract_algebra.Operation
Tensor product of local Hilbert spaces.
For example:
>>> 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')
-
simplifications
= [<function empty_trivial>, <function assoc>, <function convert_to_spaces>, <function idem>, <function filter_neutral>]¶
-
classmethod
create
(*local_spaces)[source]¶ Instantiate while applying automatic simplifications.
Instead of directly instantiating cls, it is recommended to use
create()
, which applies simplifications to the args and keyword arguments according to the simplifications class attribute, and returns an appropriate object (which may or may not be an instance of the original cls).Two simplifications of particular importance are
match_replace()
andmatch_replace_binary()
which apply rule-based simplifications.The
temporary_rules()
context manager may be used to allow temporary modification of the automatic simplifications thatcreate()
uses, in particular the rules formatch_replace()
andmatch_replace_binary()
. Inside the managed context, the simplifications class attribute may be modified and rules can be managed withadd_rule()
anddel_rules()
.
-
property
has_basis
¶ True if the all the local factors of the ProductSpace have a defined basis
-
property
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
-
property
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
-
property
dimension
¶ Dimension of the Hilbert space.
- Raises
BasisNotSetError – if the Hilbert space has no defined basis
-
property
local_factors
¶ The
LocalSpace
instances that make up the product
-
-
qalgebra.core.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