Skip to content

Add build_call_graph and symbolic resource estimation to StatePreparationViaRotation#1037

Merged
tanujkhattar merged 5 commits intoquantumlib:mainfrom
tanujkhattar:state_prep_rotations_symb_v2
May 31, 2024
Merged

Add build_call_graph and symbolic resource estimation to StatePreparationViaRotation#1037
tanujkhattar merged 5 commits intoquantumlib:mainfrom
tanujkhattar:state_prep_rotations_symb_v2

Conversation

@tanujkhattar
Copy link
Copy Markdown
Collaborator

Pulled out from #1017

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"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does close enough mean here? What's the discrepancy from?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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):
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need a __repr__ here?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nicer for debugging. We should probably add a __repr__ everywhere we have classes that store data: NDArray as attributes (like qroms)

@tanujkhattar tanujkhattar enabled auto-merge (squash) May 31, 2024 06:14
@tanujkhattar tanujkhattar merged commit cf2044d into quantumlib:main May 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants