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

Add Product block encoding #1106

Merged
merged 9 commits into from
Jul 11, 2024
Merged

Conversation

charlesyuan314
Copy link
Contributor

Add an instance of BlockEncoding that implements the product of constituent block encodings.

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.

Some minor things to consider, but LGTM

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.

Please add an explanation of the decomposition to the docstring and consider doing the partitions and unpartitions once outside the for-loop

qualtran/symbolics/math_funcs.py Show resolved Hide resolved
qualtran/symbolics/math_funcs.py Show resolved Hide resolved
qualtran/bloqs/block_encoding/product.py Show resolved Hide resolved
qualtran/bloqs/block_encoding/product.py Show resolved Hide resolved
@charlesyuan314
Copy link
Contributor Author

I will do the suggested refactor to clean up the circuit diagram in a follow-up PR.

@mpharrigan I've addressed all of the other feedback.

Comment on lines +100 to +102
'product_block_encoding',
'product_block_encoding_override',
'product_block_encoding_symb',
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why are these not serializable ?

Copy link
Collaborator

Choose a reason for hiding this comment

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

@charlesyuan314 I'll merge the PR and we can continue this discussion and potentially address in a follow-up PR

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I believe it is because this bloq has an attribute of type Tuple[BlockEncoding, ...]. It results in the following at serialization time:

qualtran.testing.BloqCheckException: Serialization Failed:
Object arrays cannot be saved when allow_pickle=False

Are bloqs contained as attributes something that can be made serializable?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Object arrays cannot be saved when allow_pickle=False

I think it's because so far we haven't had any bloq that stores a sequence of subbloqs as an attribute.

To support serialization we'll have to update

int32 subbloq = 7;
to add a new NDArray subbloqs that stores an NDArray of integers corresponding to IDs of each of the subbloqs and then update
if isinstance(val, Bloq):
to check if the argument is an ndarray of bloqs, then delegate to a different method that serializes it.

Can you please open an issue to track this?

@tanujkhattar tanujkhattar enabled auto-merge (squash) July 11, 2024 18:42
@tanujkhattar tanujkhattar merged commit f8d2db0 into quantumlib:main Jul 11, 2024
7 checks passed
@charlesyuan314 charlesyuan314 deleted the product branch July 11, 2024 18:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants