Closed goerz closed 7 years ago
Actually, there are reasons for supporting both numeric indices and string labels: For numeric indices, we can do a number of operations without having to specify the basis (or dimension) of the underlying Hilbert space. For example, we can apply a Creation operator.
However, we need a strict and explicit interface for handling this: BasisKet
can be instantiated with a label_or_index
parameter. If this parameter is an int, it is taken as the index, if it is a string, as the label. Add an index
property which is different from the label
property (always a string!)
Using integers as labels e.g. for
BasisKet
should not be allowed (or rather, an integer label should be converted viastr
in the__init__
routine). Allowing integers makes it tempting to do arithmetic on the labels. However, any code that does this will fail if the labels are actually strings! Instead, numerical indices should be obtained via anindex
method / property