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

Create SparseMatrix block encoding #1143

Merged
merged 6 commits into from
Jul 19, 2024
Merged

Create SparseMatrix block encoding #1143

merged 6 commits into from
Jul 19, 2024

Conversation

charlesyuan314
Copy link
Contributor

Add an instance of BlockEncoding that builds a block encoding of a sparse-access matrix given
oracles for the indices of non-zero entries in each row / column and an oracle for its entries.

For now, we test its behavior using oracles for a matrix with the same entry in every position.
Oracles for diagonal and tridiagonal matrices are planned next.

@charlesyuan314 charlesyuan314 force-pushed the sparse branch 2 times, most recently from 698fa9d to ca47003 Compare July 17, 2024 18:30
@charlesyuan314
Copy link
Contributor Author

@mpharrigan PTAL!

Copy link
Contributor

@anurudhp anurudhp left a comment

Choose a reason for hiding this comment

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

lgtm! % nits

qualtran/bloqs/block_encoding/sparse_matrix.py Outdated Show resolved Hide resolved
qualtran/bloqs/block_encoding/sparse_matrix.py Outdated Show resolved Hide resolved
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.

just a couple style things looks pretty nice 👍

qualtran/bloqs/block_encoding/sparse_matrix.py Outdated Show resolved Hide resolved
qualtran/bloqs/block_encoding/sparse_matrix.py Outdated Show resolved Hide resolved
alpha = bloq.alpha
bb = BloqBuilder()
system = bb.add_register("system", 2)
ancilla = cast(Soquet, bb.add(IntState(0, 3)))
Copy link
Collaborator

Choose a reason for hiding this comment

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

do you actually need this cast?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is for making my IDE type checker (Pylance) happier. Mypy is more forgiving here.

bb = BloqBuilder()
system = bb.add_register("system", 2)
ancilla = cast(Soquet, bb.add(IntState(0, 3)))
system, ancilla = bb.add_t(bloq, system=system, ancilla=ancilla)
Copy link
Collaborator

Choose a reason for hiding this comment

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

you can still use add here (which will return either a single value or a tuple depending on the bloq signature (this is how python function calls work))

Copy link
Contributor Author

@charlesyuan314 charlesyuan314 Jul 19, 2024

Choose a reason for hiding this comment

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

If I'm correct, you're expressing the same preference here as you did in #1158 (comment).

Is it a strong stylistic preference in Qualtran to use add over add_t? I didn't see this preference expressed in the documentation of BloqBuilder.add_t.

@charlesyuan314 charlesyuan314 enabled auto-merge (squash) July 19, 2024 20:51
@charlesyuan314 charlesyuan314 merged commit 0968762 into main Jul 19, 2024
10 checks passed
@charlesyuan314 charlesyuan314 deleted the sparse branch July 22, 2024 19:03
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