Exceptions

Various exceptions that can be raised by qitensor functions.

exception qitensor.exceptions.DuplicatedSpaceError(spaces, msg=None)

Bases: qitensor.exceptions.HilbertError

Raised when an operation would result in an output with two copies of a HilbertAtom.

>>> from qitensor import qubit
>>> ha = qubit('a')
>>> ha * ha
Traceback (most recent call last):
    ...
DuplicatedSpaceError: '|a>'
>>> x = ha.array()
>>> x * x
Traceback (most recent call last):
    ...
DuplicatedSpaceError: '|a>'
exception qitensor.exceptions.HilbertError(msg)

Bases: exceptions.Exception

The generic exception used by qitensor. All of this package’s other exceptions derive from this one.

exception qitensor.exceptions.HilbertIndexError(msg)

Bases: qitensor.exceptions.HilbertError, exceptions.LookupError

Raised when an invalid array subscript is given.

>>> from qitensor import qubit
>>> ha = qubit('a')
>>> x = ha.array()
>>> x[2]
Traceback (most recent call last):
    ...
HilbertIndexError: 'Index set for |a> does not contain 2'
>>> x[{ ha.H: 0 }]
Traceback (most recent call last):
    ...
HilbertIndexError: 'Hilbert space not part of this array: <a|'
exception qitensor.exceptions.HilbertShapeError(shape1, shape2)

Bases: qitensor.exceptions.HilbertError, exceptions.ValueError

Raised when an array is not the right shape for the requested operation.

exception qitensor.exceptions.MismatchedSpaceError(msg)

Bases: qitensor.exceptions.HilbertError

Raised when two HilbertAtoms have the same label but different properties, or when the HilbertSpace requested for an operation doesn’t match that of an array.

exception qitensor.exceptions.NotKetSpaceError(msg)

Bases: qitensor.exceptions.HilbertError

Raised when a bra space is given to an operation that only works on ket spaces.

Previous topic

Hilbert Space Atoms

Next topic

Array Formatter

This Page