mabuchilab / QNET

Computer algebra package for quantum mechanics and photonic quantum networks
https://qnet.readthedocs.io/
MIT License
71 stars 23 forks source link

Labels should always be strings, never ints #50

Closed goerz closed 7 years ago

goerz commented 7 years ago

Using integers as labels e.g. for BasisKet should not be allowed (or rather, an integer label should be converted via str 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 an index method / property

goerz commented 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!)