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

Inverse of MCX gates to include ancillae #5020

Conversation

kdk
Copy link
Member

@kdk kdk commented Sep 2, 2020

Summary

Resolves #4953 by adding inverse methods to the MCXGate modes which return gates of the same mode.

Details and comments

Also, fixes some small related bugs that came up during testing:

  • SXGate().inverse() to return SXdgGate() and vice versa.
  • Instruction.inverse to no longer return modified copy of input gate.
    This is necessary for gates which do not have a defined inverse method and are not self-adjoint (e.g. DCX, iSwap), because the returned gate would have an updated definition, but still incorrectly retain properties of the original gate (namely to_matrix).
  • Fix C3XGate.inverse to negate angle if non-zero.

@kdk kdk added stable backport potential The bug might be minimal and/or import enough to be port to stable Changelog: Bugfix Include in the "Fixed" section of the changelog labels Sep 2, 2020
@kdk kdk requested a review from a team as a code owner September 2, 2020 21:06
@mtreinish
Copy link
Member

It looks like this introduces some import cycles. My guess is we'll probably have to revisit what I did in: #4450

@kdk kdk force-pushed the 4953-Inverse-of-MCX-gates-generated-without-qubits-for-ancillae branch from 56e2ce9 to 071f71c Compare September 3, 2020 14:24
Copy link
Contributor

@Cryoris Cryoris left a comment

Choose a reason for hiding this comment

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

LGTM 👍 It's a little strange that the incorrect inverse of C3X didn't break any tests, but maybe this was a case where the gate parameter in the test was set to 0.

@mergify mergify bot merged commit 70fc3f8 into Qiskit:master Sep 4, 2020
mergify bot pushed a commit that referenced this pull request Sep 4, 2020
* SXGate().inverse() to return SXdgGate() and vice versa.

* Instruction.inverse to no longer return modified copy of input gate.

* Fix C3XGate.inverse to negate angle if non-zero.

* MCXGate.inverse to return gate of same mode as original gate.

Co-authored-by: Julien Gacon <jules.gacon@googlemail.com>
Co-authored-by: Matthew Treinish <mtreinish@kortar.org>
(cherry picked from commit 70fc3f8)
kdk added a commit that referenced this pull request Sep 4, 2020
* SXGate().inverse() to return SXdgGate() and vice versa.

* Instruction.inverse to no longer return modified copy of input gate.

* Fix C3XGate.inverse to negate angle if non-zero.

* MCXGate.inverse to return gate of same mode as original gate.

Co-authored-by: Julien Gacon <jules.gacon@googlemail.com>
Co-authored-by: Matthew Treinish <mtreinish@kortar.org>
(cherry picked from commit 70fc3f8)

Co-authored-by: Kevin Krsulich <kevin.krsulich@ibm.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelog: Bugfix Include in the "Fixed" section of the changelog stable backport potential The bug might be minimal and/or import enough to be port to stable
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Inverse of MCX gates generated without qubits for ancillae
3 participants