-
Notifications
You must be signed in to change notification settings - Fork 117
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
implement swap update algorithm for adjacency constraint resolution when placing circuits on hardware #146
Conversation
…and QubitMapping data structures, and implement the swap update algorithm
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.
this is great! so exciting to see it all coming together :)
…UpdateTransformer
generate_decomposed_swap) | ||
# First iteration adds a swap between Q0 and Q1. | ||
# generate_decomposed_swap implements that swap operation as four | ||
# sqrt-iswaps. |
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.
Instead of testing the implementation, we should test the effect. For instance, that the effect is equivalent to swapping Q[0] and Q[1] (via cirq.unitary or some other method).
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.
great idea.
Related question: how is the unitary matrix index determined for a circuit's qubits? For some of these tests, it would be cool to compare the logical circuit's unitary before and after adding swaps; they should be the same, but only after ignoring any ancillary qubits.
…nd add test coverage for previously untested public functions
Is this of general utility? Should this be upstreamed to cirq? |
FWIW, I had a university partner ask about routing code. I pointed them to cirq.contrib and here, and found it odd to point someone to quantum chess for this. |
Maybe we could try it out in Quantum chess and export it to cirq after some testing? |
That would be my preference as well. Happy to file a separate PR against cirq.contrib later but I'd prefer to do some evaluation first and iron out some of the kinks. |
Seems reasonable to me! |
|
||
def generate_decomposed_swap( | ||
q1: cirq.Qid, q2: cirq.Qid) -> Generator[cirq.Operation, None, None]: | ||
"""Generates a SWAP operation using sqrt-iswap gates.""" |
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.
Calling optimized_for_sycamore might be less efficient, but it's probably fine for now.
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.
lgtm.
This is the second half of the algorithm described in this paper and is related to #127 and quantumlib/unitary#48
The swap updater takes an initial logical -> device qubit mapping and adds additional qubits and swap operations to ensure all gates operate on adjacent qubits. When combined with the initial placement implementation from #144 we'll get a complete circuit placement algorithm.