Skip to content

refactor LocalOperator logic

Vicentini Filippo requested to merge pv/localop into master

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 their acting_on when constructed and manipulated. Arrays/structures needed to perform get_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.
  • 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.

Merge request reports