Skip to content
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

Refactor block encoding bloqs to use abstract base class. #967

Merged
merged 23 commits into from
May 24, 2024

Conversation

fdmalone
Copy link
Collaborator

@fdmalone fdmalone commented May 20, 2024

  • Refactor block encoding bloqs to use an abstract base class to allow for using different constructions of block encodings other than LCUs. I also simplified the construction of the higher level block encoding to use attrs to automatically convert a SelectOracle and PrepareOracle into their "black boxes" to enable higher level abstractions.
  • Make SF and DF inherit from BlockEncoding and define the appropriate signal state reflections.
  • Update QubitizationWalkOperator to expect a block encoding rather than Sel and Prep.

cc @tanujkhattar: does this sound sensible? If so I'll continue down this path. The goal is to enable phase estimation of all chemistry bloqs, not just those which follow the more standard LCU form. It is possible that I could further refactor SF and DF to build the sub block encodings but I'll leave that as a follow up.

@fdmalone fdmalone requested a review from tanujkhattar May 20, 2024 20:04
Copy link
Collaborator

@tanujkhattar tanujkhattar left a comment

Choose a reason for hiding this comment

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

This is looking good! Do you want to merge this and continue the refactoring or continue the refactoring in this PR? Either way sounds good to me. I'll approve if you want to merge this once you mark it ready.

qualtran/bloqs/block_encoding.py Outdated Show resolved Hide resolved
qualtran/bloqs/block_encoding.py Outdated Show resolved Hide resolved
qualtran/bloqs/block_encoding.py Outdated Show resolved Hide resolved
qualtran/bloqs/block_encoding.py Outdated Show resolved Hide resolved
qualtran/bloqs/block_encoding.py Outdated Show resolved Hide resolved
@fdmalone
Copy link
Collaborator Author

Ok, I took way too long going back and forth but the block should work in the verbose and "black box" way (i.e hiding complexity with a partition). I think this will enable us to write diagrams similar to those in say the linear T paper:

Screenshot 2024-05-22 at 3 06 39 PM

@fdmalone fdmalone marked this pull request as ready for review May 22, 2024 22:42
@fdmalone
Copy link
Collaborator Author

I will follow up with the updates to QubitizationWalkOperator / chemistry block encodings.

@fdmalone
Copy link
Collaborator Author

@tanujkhattar PTAL, this is good to go I think

Copy link
Collaborator

@mpharrigan mpharrigan left a comment

Choose a reason for hiding this comment

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

It's admirable that the user can either use the raw select and prepare subroutines and get all the registers, but do we actually want this? I.e. why can't we always go via the "black-box" interfaces

qualtran/bloqs/block_encoding.py Outdated Show resolved Hide resolved
qualtran/bloqs/block_encoding.py Outdated Show resolved Hide resolved
qualtran/bloqs/block_encoding.py Show resolved Hide resolved
qualtran/bloqs/block_encoding.py Outdated Show resolved Hide resolved
@fdmalone
Copy link
Collaborator Author

It's admirable that the user can either use the raw select and prepare subroutines and get all the registers, but do we actually want this? I.e. why can't we always go via the "black-box" interfaces

Yeah, originally I had an attrs converter which would just convert it to the abstract black box, which is probably the right thing to do, but for the chemistry bloqs I'll need yet another black box for the big block encodings, so thought it better to do things incrementally. (and maybe add the AutoPartition first to handle this). All these wrappers would have to be structured etc.. so all this is to say is yes, I think the end point would be use the black boxes, but maybe wait a few PRs.

I also didn't want to open a can of worms here about how we want to write these algorithms, but I think now (or shortly) we can generate the more abstract linear T style diagrams of like a walk operator and QPE etc.

@mpharrigan
Copy link
Collaborator

Thanks for the additional color! Sounds good

@fdmalone fdmalone enabled auto-merge (squash) May 23, 2024 23:59
@fdmalone fdmalone merged commit 75bbaba into quantumlib:main May 24, 2024
7 checks passed
@fdmalone fdmalone deleted the revamp_block_encoding_bloqs branch May 24, 2024 04:33
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.

4 participants