OperatorList class to keep memory usage low when storing operators
Created by: VolodyaCO
This PR presents a data class to handle the matrix representation of operators when building local operators, so that we don't keep unnecessary copies of the same operators over and over.
For fermionic two- and four-body operators, the memory overhead of storing many times the same matrix representation of an operator is not very costly. However, for bosonic two- and four-body operators, the matrix representations can become very large, and therefore, a lot of memory might be consumed unnecessarily.
This issue is resolved with this OperatorList
class which handles the attribute _operators
from a LocalOperator
. Before, the LocalOperator._operators
attribute was a list, and now it's an object of OperatorList
. Before, every operator was stored in the list, even though in most of the applications the operators are actually repeated because they have the same form. Now, operators are hashed, and a lookup table is implemented so that no repetition of the matrix representation of the operators are stored.
I haven't checked the code, but maybe something similar can be done for operators in LocalLiouvillian
. This was particularly intended to create GraphOperator
s so that it does not store the same operator over and over. In this PR I have not modified the GraphOperator
's logic. You tell me if you want me to do it here, or in other PRs, as I understand you want to have small PRs.