refactor LocalOperator logic
Created by: PhilipVinc
This PR completely refactors the front-end logic of LocalOperator to match what happens in PauliString, that is:
-
LocalOperator
merely stores a list of operators and theiracting_on
when constructed and manipulated. Arrays/structures needed to performget_conn
, etc are constructed only when needed. This should alleviate slow-downs seen by users when trying to construct huge localoperators.'- This should make it easy in the future to separate the
LocalOperator
front-end code from the numba implementation and maybe write a jax implementation.
- This should make it easy in the future to separate the
- The logic is now simplified, in the sense that all matrices are never modified in-place. This makes it more memory efficient in some cases because we never duplicate arrays anymore (provided you build directly the LocalOperator with the correct matrices), which is what @VolodyaCO wanted.
- The logic is simpler to follow, IMHO, because we modify a very simple data structure in only one place, and user data can onlhy be inputted at the constructor. Therefore we can skip a lot of data validation in the internal methods.
This PR also gets us 98% of the way towards supporting both sparse and dense amtrices inside of Localoperators (there's just a function or two that must be fixed) which has been a longstanding feature request.