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

implement swap update algorithm for adjacency constraint resolution when placing circuits on hardware #146

Merged
merged 7 commits into from
Mar 2, 2021

Conversation

weinstein
Copy link
Contributor

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.

@weinstein weinstein marked this pull request as ready for review February 16, 2021 18:51
Copy link
Collaborator

@wingers wingers 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 great! so exciting to see it all coming together :)

recirq/quantum_chess/swap_update_transformer.py Outdated Show resolved Hide resolved
recirq/quantum_chess/swap_update_transformer.py Outdated Show resolved Hide resolved
recirq/quantum_chess/swap_update_transformer.py Outdated Show resolved Hide resolved
recirq/quantum_chess/mcpe_utils.py Outdated Show resolved Hide resolved
recirq/quantum_chess/mcpe_utils.py Outdated Show resolved Hide resolved
recirq/quantum_chess/mcpe_utils.py Outdated Show resolved Hide resolved
recirq/quantum_chess/mcpe_utils.py Show resolved Hide resolved
recirq/quantum_chess/mcpe_utils.py Outdated Show resolved Hide resolved
recirq/quantum_chess/swap_updater.py Outdated Show resolved Hide resolved
recirq/quantum_chess/swap_updater.py Outdated Show resolved Hide resolved
recirq/quantum_chess/swap_updater.py Outdated Show resolved Hide resolved
recirq/quantum_chess/swap_updater_test.py Outdated Show resolved Hide resolved
generate_decomposed_swap)
# First iteration adds a swap between Q0 and Q1.
# generate_decomposed_swap implements that swap operation as four
# sqrt-iswaps.
Copy link
Collaborator

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).

Copy link
Contributor Author

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.

@mpharrigan
Copy link
Collaborator

Is this of general utility? Should this be upstreamed to cirq?

@rmlarose
Copy link
Contributor

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.

@dstrain115
Copy link
Collaborator

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?

@weinstein
Copy link
Contributor Author

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.

@rmlarose
Copy link
Contributor

Maybe we could try it out in Quantum chess and export it to cirq after some testing?

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."""
Copy link
Collaborator

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.

Copy link
Collaborator

@cantwellc cantwellc left a comment

Choose a reason for hiding this comment

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

lgtm.

@weinstein weinstein merged commit e796b28 into quantumlib:master Mar 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants