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.
The way
Observable::observe
generates allCompositeInstruction
s at once may consume a very large amount of memory.In particular, all these
CompositeInstruction
s are deep copiesIt 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
CompositeInstruction
sWe 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.