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

Bloq counts fails for LessThanGate / SingleQubitCompare decomposition #388

Closed
fdmalone opened this issue Oct 9, 2023 · 5 comments · Fixed by quantumlib/Cirq#6312
Closed

Comments

@fdmalone
Copy link
Collaborator

fdmalone commented Oct 9, 2023

This used to work with an older version of cirq_ft:

import cirq_ft
from qualtran.cirq_interop import CirqGateAsBloq

bloq = CirqGateAsBloq(cirq_ft.LessThanEqualGate(4, 4))
graph, sigma = get_bloq_counts_graph(bloq)

raises

BloqError: During finalization, {Soquet(binst=LeftDangle, reg=Register(name='less_than', bitsize=1, shape=(), side=<Side.THRU: 3>), idx=())} Soquets were not used.

Seems like the SingleQubitCompare is to blame

import cirq_ft
from qualtran.cirq_interop import CirqGateAsBloq

bloq = CirqGateAsBloq(cirq_ft.algos.SingleQubitCompare(False))
show_bloq(bloq.decompose_bloq())
BloqError: During finalization, {Soquet(binst=LeftDangle, reg=Register(name='less_than', bitsize=1, shape=(), side=<Side.THRU: 3>), idx=())} Soquets were not used.
@fdmalone
Copy link
Collaborator Author

fdmalone commented Oct 9, 2023

@tanujkhattar any idea?

@fdmalone fdmalone changed the title Bloq counts fails for LessThanGate Bloq counts fails for LessThanGate / SingleQubitCompare decomposition Oct 9, 2023
@fdmalone fdmalone mentioned this issue Oct 9, 2023
@tanujkhattar
Copy link
Collaborator

Looking into it now

@tanujkhattar
Copy link
Collaborator

It's because the target qubit in And gate in Cirq-FT now is a directional LEFT/RIGHT register, so it expects you to supply qubits which are newly allocated clean qubits; i.e. qubits which either appear in the signature of the parent gate as a LEFT / RIGHT register or don't appear in the signature of the parent gate at all and are allocated as CleanQubit / BorrowableQubit.

Tl;Dr - The fix here is to change the signature of SingleQubitCompare to make less_than and greater_than directional registers; just like you would do if you write them as valid Bloqs.

So this is less of a bug in the interop and more of a bug that arises due to old cirq-ft style implementation of the primitive where we didn't have directional registers. I'd imagine more such bugs would be discovered in other implementations and we can just fix them as we find them.

I'll send a PR to fix this now.

@tanujkhattar
Copy link
Collaborator

@fdmalone quantumlib/Cirq#6312 fixes the issue. It's hard to test the interop with the two codes living in separate repositories, but you can pull the Cirq PR, run source dev_tools/pypath in Cirq repository and then run your Qualtran code again to verify that this works.

I'm working on moving all Cirq-FT code to Qualtran and we can then have automated consistency checks for all Cirq-FT gate's using assert_valid_bloq_decomposition.

@fdmalone
Copy link
Collaborator Author

fdmalone commented Oct 9, 2023

I'm just reopening this so we remember to bump the cirq_ft requirements. I guess I can do that during #350.

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 a pull request may close this issue.

2 participants