eclipse / xacc

XACC - eXtreme-scale Accelerator programming framework
https://xacc.readthedocs.io
BSD 3-Clause "New" or "Revised" License
163 stars 84 forks source link

Memory consumption optimization for `Observable::observe` #542

Open 1tnguyen opened 2 years ago

1tnguyen commented 2 years ago

The way Observable::observe generates all CompositeInstructions at once may consume a very large amount of memory.

In particular, all these CompositeInstructions are deep copies

It has always been like that for a long time and I think a deep copy is properly needed anyway since we don't want any interference between potential IRTransformation passes (if any) down the track.

For example, UCCSD ansatz + H8 Hamiltonian may consume multiple GBs just for these CompositeInstructions

We need to come up with a way to handle this more efficiently. A potential solution is to have the upper layer (e.g., VQE) to process this in chunks, i.e., create observe circuits for subsets of the terms in chunks.