Skip to content

Commit 3d477f6

Browse files
committed
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.
1 parent fc567f0 commit 3d477f6

2 files changed

Lines changed: 457 additions & 151 deletions

File tree

0 commit comments

Comments
 (0)