LocalOperator: Don't return the diagonal element if it is zero
Created by: PhilipVinc
This PR does two things. The main thing of the PR is the following:
- If the diagonal of a LocalOperator is zero, meaning that all the diagonal elements of all operators are 0 and the constant shift is zero, then we no longer return
x
withmel=0
when callingget_conn(x)
.
While this is negligible in the case of hamiltonians, as it's only 1 nonzero element, in the case of liouvillians we have terms like \sum_i L_i\otimes L_i
where L usually has no diagonal elements, so in the best case scenario we were getting 4N
nonzero elements where actually only N
are potentially nonzero.
This PR leads to a speedup of 20% so I think it's a good thing. The points where we have to compute whever those elements are nonzero are several, and it's messy, but I hope to address this in the future by rewriting localoperator...
--
- The other thing that this PR does is giving a method to compute the maximum number of nonzero elements in an operator. This is useful for Liouvillians to preallocate the space needed before calling
get_conn
.
todo: tests