Skip to content

Commit

Permalink
Optimise SparsePauliOp.from_operator (#11557)
Browse files Browse the repository at this point in the history
* Optimise `SparsePauliOp.from_operator`

This rewrites the `from_operator` handling (again!) from the initial
Rust implementation of the recursive matrix-addition form into an
iterative approach that re-uses the same scratch memory all the way
down.  This is significantly faster, and allocates far less often,
although in practice the peak heap memory usage will be not dissimilar.

The algorithm is rewritten to be a manual stack-based iteration, rather
than a functional recursion.  The size of a single stack entry in the
iteration is one `usize`, which is drastically smaller than whatever
per-function-call stack will have been used before.

* Improve documentation

* Increase test coverage
  • Loading branch information
jakelishman authored Oct 31, 2024
1 parent 4bd2dd8 commit 4e6fd36
Show file tree
Hide file tree
Showing 3 changed files with 792 additions and 166 deletions.
Loading

0 comments on commit 4e6fd36

Please sign in to comment.