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 cirq.QubitPermutationGate #3298

Merged
merged 10 commits into from
Sep 12, 2020
Merged

Conversation

balopat
Copy link
Contributor

@balopat balopat commented Sep 3, 2020

Adds cirq.QubitPermutationGate. This is a refactor of cirq.interop.quirk.QuirkPermutationGate.
I also pulled out testing utilities for it from the quirk pacakge into cirq.testing.assert_equivalent_computational_basis_map.

Fixes #2671.

@googlebot googlebot added the cla: yes Makes googlebot stop complaining. label Sep 3, 2020
@balopat balopat mentioned this pull request Sep 3, 2020
@balopat balopat changed the title adds cirq.QubitPermutationGate Add cirq.QubitPermutationGate Sep 3, 2020
cirq/ops/permutation_gate.py Outdated Show resolved Hide resolved
cirq/ops/permutation_gate.py Show resolved Hide resolved
cirq/ops/permutation_gate.py Outdated Show resolved Hide resolved
cirq/testing/equivalent_basis_map.py Outdated Show resolved Hide resolved


@value.value_equality
class QubitPermutationGate(raw_types.Gate):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Out of scope for this PR: I initially thought this would be a gate that permutes computational basis. Instead, it permutes qubits which is a less general operation. I think we should also implement the former, but not necessarily in this PR. I guess the reason to have both is that QubitPermutationGate has an efficient _apply_unitary_ .

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 agree. I was just following almost mechanically @mpharrigan's requirements from #2671 - thus this one is the same as the quirk gate minus the name + id. Having a permutation gate on the computational basis states might be 1) valuable for use cases (although I'm not aware of those just yet) 2) an even better option to consolidate the permutation gate hierarchy in the contrib.aqcuaintance package.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Regarding use-cases of the more general permutation gate: unitary corresponding to any bijective function from n-bitstrings to n-bitstrings (including e.g. arithmetic operations) is a permutation matrix. This may not be sufficient grounds for a generic permutation gate since it's reasonable to implement specific gates for such operations instead.

We can defer until we see more use-cases.

Copy link
Collaborator

@viathor viathor left a comment

Choose a reason for hiding this comment

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

LGTM with one comment. Feel free to go ahead and merge once addressed.

cirq/ops/permutation_gate.py Show resolved Hide resolved
@balopat balopat added the automerge Tells CirqBot to sync and merge this PR. (If it's running.) label Sep 12, 2020
@CirqBot CirqBot added the front_of_queue_automerge CirqBot uses this label to indicate (and remember) what's being merged next. label Sep 12, 2020
@CirqBot CirqBot merged commit 20df07e into quantumlib:master Sep 12, 2020
@CirqBot CirqBot removed automerge Tells CirqBot to sync and merge this PR. (If it's running.) front_of_queue_automerge CirqBot uses this label to indicate (and remember) what's being merged next. labels Sep 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes Makes googlebot stop complaining.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Permutation Gate
4 participants