dtype handling of graph and local operators
Created by: femtobit
This PR mainly fixes some sources of unnecessary copies of the component operators of GraphOperator
, which should results in a reduced memory consumption.
One example was Heisenberg
: It was previously built as a GraphOperator
, but since the coupling operator was specified as an integer array in the code, the constructor of LocalOperator
performed n_edges
copies of the same bond op, each time changing the type. Therefore this was true:
>>> h = Heisenberg(hi, g)
>>> np.all(h._operators[0] == h._operators[1]) # same entries
True
>>> h._operators[0] is h._operators[1] # different array object
False
With the change in the first commit of this PR, no more duplication occurs:
# this PR
>>> h._operators[0] is h._operators[1]
True # same objects, so no extra memory for the array contents is required
The second commit should fix similar potential issue and the third one fixes a bug in the logic which determined the default dtype
of LocalOperator
.
These changes likely don't make a noticeable difference with small local operators (like in Heisenberg) unless the graph is very large. But for higher-dimensional local Hilbert spaces, it might be useful.