-
Notifications
You must be signed in to change notification settings - Fork 59
Add Always
metabloq to simplify decompositions with compute-uncompute pairs
#1605
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Always
metabloq to simplify decompositions with compute-uncompute pairs
#1605
Conversation
Thanks! I'll have to take a close look at this, and I may have some doc changes or naming suggestions since it will be especially important to communicate why and when this construct makes sense |
I suspect the "right" thing to do would be to have a Compute-Uncompute metabloq, but that's probably a lot of work. I have to think whether a construct like this could solve the immediate issue without introducing too much tech debt. |
Yeah, I think this makes me slightly too uncomfortable. The meta-bloq doesn't make sense on its own. If I tell you I have a Controlled(x) or Adjoint(x), that's an object you might actually want. Of course, we do have bookeeping bloqs including AutoPartition(x, ...). Even that makes sense as an object: it's x with a modified signature. The proposed metabloq is trying to "tag" the existing bloq object with a signal that can be interpreted by the default "controlled" infrastructure.
|
One thought would be to have an attribute on the prepare bloq that tells it whether it's part of a compute/uncompute pair, and it can decide whether to control itself based on that. This constrains the hackiness-surface to the issue at hand rather than giving a new bookkeeping bloq that could be used arbitrarily. In this case, it might be tricky because the prepare bloq is nested in parameter attributes. Just a thought |
Yep, this should be added at some point (#1221). A few issues that complicate it:
bb.add(U, ...)
# add many bloqs (on different registers)
bb.add(U.adjoint(), ...) so it forces writing a new bloq to pass as
This also seems to be the way quipper does it, for example. |
"nested" in the sense that the bloq is passed as an attribute, so the decompose method would have to set the 'always' flag on the subbloq (i.e. prepare) Another place where we want to "always" do a bloq that isn't part of compute/uncompute is something like Calling it You could use an |
I like the naming convention. Maybe just one minor thought, I wonder what would be a better name. 🤔 |
IgnoringCtrl
metabloq to support simpler decompositions with compute-uncompute pairsAlways
metabloq to simplify decompositions with compute-uncompute pairs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good
- let's refine the documentation a bit, since this is an unfamiliar concept in textbook quantum algorithms
- can you open an issue to port more things to use it, particularly
AddK
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some final wording suggestions
It's getting quite tedious to override bloqs with a
cv: Optional[int]
attribute, and writing a lot of if-else logic to wire the controlled version correctly.IgnoringCtrl
is an alternate idea I had that should hopefully simplify writing bloq decompositions. It:_BookkeepingBloq
)The user simply has to wrap their compute-uncompute bloqs in
IgnoringCtrl
and the rest should work automatically. Caveat: will produce wrong results (simulation and costs) if not correctly wrapped, so should be used with caution. But is probably slightly less error-prone as it avoids code duplication: the previous solution withcv
requires the user to carefully repeat the same logic in the if-else branches (one with and one without controls).@mpharrigan thoughts? Do you think this is a good idea?
fixes #1413
upd: renamed to
Always