Add build_call_graph and symbolic resource estimation to StatePreparationViaRotation#1037
Conversation
…ate_prep_rotations_symb_v2
| assert bloq.t_complexity().t == expected_t_count_expr | ||
|
|
||
| # Compare bloq counts via expression to actual bloq counts and make sure they | ||
| # are "close enough" |
There was a problem hiding this comment.
What does close enough mean here? What's the discrepancy from?
There was a problem hiding this comment.
The prepare amplitudes calls PRGA for 0 + 1 + 2 + 3 + 4 + 5 ... + n - 1 bitsize (where n is size of selection register) and corresponding rom_values of length 2 ** 0 + 2 ** 1 + 2 ** 2 + ... + 2 ** (n - 1)
When n is symbolic, we can't simulate this in the build_call_graph so I instead return a single call to PRGA with bitsize n and rom_values of size 2^n. The constant factor of the dominant cost of QROM scales as 4 * L and sum of 2 ** 0 + 2 ** 1 + 2 ** 2 + ... + 2 ** (n - 1) is 2^n so dominant cost matches. But the smaller costs like addition into phase gradient register scale with selection bitsize; and so 1 + 2 + 3 + ... + n - 1 > n -- this is where the discrepancy comes from.
| def build_call_graph(self, ssa: 'SympySymbolAllocator') -> Set['BloqCountT']: | ||
| return {(self.qrom_bloq, 1), (self.qrom_bloq.adjoint(), 1), (self.add_into_phase_grad, 1)} | ||
|
|
||
| def __repr__(self): |
There was a problem hiding this comment.
Why do we need a __repr__ here?
There was a problem hiding this comment.
Nicer for debugging. We should probably add a __repr__ everywhere we have classes that store data: NDArray as attributes (like qroms)
…ate_prep_rotations_symb_v2
Pulled out from #1017