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 equivalence-library rules between rzz and cp #13019

Merged
merged 2 commits into from
Sep 9, 2024

Conversation

jakelishman
Copy link
Member

Summary

These gates are locally equivalence (as are all the Ising-interaction gates), and this simple additional rule lets things like QFT, which are defined by Qiskit's default constructor in terms of cp, get converted into rzz or rzx.

Details and comments

I also have a complete rewrite of the equivalence library that is complete and in theory optimal (in 2q gate count) for translations at jakelishman/qiskit-terra@6654059193, but the current BasisTranslator algorithm does not work as well with the structuring of the rules. I have a new algorithm for translation in mind that I'm calling the BasisConstructor, which will solve that problem, and also make basis translation for overcomplete basis sets and heterogeneous architectures more accurate, reliable and performant (hopefully!), but I haven't had chance to write it up yet.

@jakelishman jakelishman added Changelog: New Feature Include in the "Added" section of the changelog mod: transpiler Issues and PRs related to Transpiler mod: circuit Related to the core of the `QuantumCircuit` class or the circuit library labels Aug 23, 2024
@jakelishman jakelishman added this to the 1.3.0 milestone Aug 23, 2024
@jakelishman jakelishman requested a review from a team as a code owner August 23, 2024 10:50
@qiskit-bot
Copy link
Collaborator

One or more of the following people are relevant to this code:

  • @Cryoris
  • @Qiskit/terra-core
  • @ajavadia

These gates are locally equivalence (as are all the Ising-interaction
gates), and this simple additional rule lets things like QFT, which are
defined by Qiskit's default constructor in terms of `cp`, get converted
into `rzz` or `rzx`.

One `ControlledGate` test needed a case removing, because the underlying
control mechanism now works correctly.
@jakelishman jakelishman force-pushed the cphase-rzz-equivalence branch from 4b6b203 to 9a2add5 Compare August 25, 2024 19:27
@coveralls
Copy link

coveralls commented Aug 25, 2024

Pull Request Test Coverage Report for Build 10577197425

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 18 of 18 (100.0%) changed or added relevant lines in 1 file are covered.
  • 85 unchanged lines in 5 files lost coverage.
  • Overall coverage increased (+0.007%) to 89.189%

Files with Coverage Reduction New Missed Lines %
qiskit/transpiler/passes/synthesis/unitary_synthesis.py 1 88.26%
crates/qasm2/src/lex.rs 4 92.23%
qiskit/circuit/gate.py 4 94.12%
crates/circuit/src/circuit_data.rs 32 91.96%
qiskit/circuit/library/n_local/n_local.py 44 83.85%
Totals Coverage Status
Change from base Build 10529709209: 0.007%
Covered Lines: 71644
Relevant Lines: 80328

💛 - Coveralls

@@ -1438,7 +1438,6 @@ def test_control_zero_operand_gate(self, num_ctrl_qubits):
@data(
RXGate,
RYGate,
RZGate,
Copy link
Member

Choose a reason for hiding this comment

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

why did you need to remove this test?

Copy link
Member Author

Choose a reason for hiding this comment

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

The test is asserting that a failure occurs, and for most of the gates in the list, they shouldn't really fail - we've got enough equivalence and translation rules that it should be possible to translate the gate into one we can represent better. The add_control logic is just not super smart about gate translation.

As a side effect of this PR, the RZ path now happens to convert things to CPhaseGate rather than CRZGate (or something like that), so the control works further than it did before.

ShellyGarion
ShellyGarion previously approved these changes Aug 26, 2024
Copy link
Member

@ShellyGarion ShellyGarion left a comment

Choose a reason for hiding this comment

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

LGTM. My only comment is that some equivalences related to rotation gates do not have an image, but this is not directly related to this PR, and can be added in another PR.

features_circuits:
- |
New equivalence rules in the standard equivalence library mean that the transpiler can now
directly convert between two-qubit continuous Pauli rotations, rather than always decomposing
Copy link
Contributor

Choose a reason for hiding this comment

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

Did it always decompose into CX? There are some existing 2q Pauli equivalences that should allow to convert between some two-qubit rotations, no? 🙂

Suggested change
directly convert between two-qubit continuous Pauli rotations, rather than always decomposing
directly convert between two-qubit continuous Pauli rotations, rather than sometimes decomposing

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll tweak this note - I wrote it under the same false assumption about how the basis translator works that's alluded to in the PR comment. We need a new translation algorithm to make any choice of translation reliable - the current system is good at finding an arbitrary valid translation, but not at finding the best translation (for any definition of "best").

Copy link
Member Author

Choose a reason for hiding this comment

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

I've written a new version of the release note in bbe529b.

@Cryoris Cryoris added this pull request to the merge queue Sep 9, 2024
Merged via the queue into Qiskit:main with commit 3aa58cc Sep 9, 2024
15 checks passed
@jakelishman jakelishman deleted the cphase-rzz-equivalence branch September 9, 2024 16:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelog: New Feature Include in the "Added" section of the changelog mod: circuit Related to the core of the `QuantumCircuit` class or the circuit library mod: transpiler Issues and PRs related to Transpiler
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants