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 2q fractional gates to the ConsolidateBlocks transpiler pass #13884

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

ShellyGarion
Copy link
Member

Summary

With the introduction of new 2q-fractional gates, such as RZZGate as part of the QPU, we add them to the ConsolidateBlocks transpiler pass.
https://www.ibm.com/quantum/blog/fractional-gates

This PR should close #13428

Details and comments

Note that this PR may be eventually superseded by #13419

@ShellyGarion ShellyGarion added Changelog: Bugfix Include in the "Fixed" section of the changelog mod: transpiler Issues and PRs related to Transpiler labels Feb 19, 2025
@ShellyGarion ShellyGarion added this to the 2.0.0 milestone Feb 19, 2025
@ShellyGarion ShellyGarion self-assigned this Feb 19, 2025
@ShellyGarion ShellyGarion requested a review from a team as a code owner February 19, 2025 11:56
@qiskit-bot
Copy link
Collaborator

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

  • @Qiskit/terra-core

@mtreinish mtreinish self-assigned this Feb 24, 2025
@ShellyGarion
Copy link
Member Author

ShellyGarion commented Feb 25, 2025

The only test currently failing is:

def test_no_kak_gates_in_preset_pm(self, opt_level):

This test was added in #13450 to handle issue #13438, and I wonder if we should remove it.
@mtreinish @ElePT - what's your opinion?

the original circuit is:

        ┌────┐   
q_0: ─■─┤ √X ├─■─
      │ ├────┤ │ 
q_1: ─■─┤ √X ├─■─
        └────┘   

the circuit after basis translation is:

global phase: 7π/4
               ┌──────────┐   ┌────┐            ┌──────────┐
q_0: ─■────────┤ Rz(-π/2) ├───┤ √X ├───■────────┤ Rz(-π/2) ├
      │ZZ(π/2) ├──────────┤┌──┴────┴─┐ │ZZ(π/2) ├──────────┤
q_1: ─■────────┤ Rz(-π/2) ├┤ Rx(π/2) ├─■────────┤ Rz(-π/2) ├
               └──────────┘└─────────┘          └──────────┘

The circuit after optimization_level 2 or 3 transpilation is:

global phase: 3π/2
     ┌──────────┐┌───────┐           ┌──────────┐┌────────┐           »
q_0: ┤ Rz(-π/2) ├┤ Rx(π) ├─■─────────┤ Rx(-π/2) ├┤ Rz(-π) ├─■─────────»
     ├─────────┬┘└───────┘ │ZZ(-π/2) ├──────────┤├────────┤ │ZZ(-π/2) »
q_1: ┤ Rz(π/2) ├───────────■─────────┤ Rx(-π/2) ├┤ Rz(-π) ├─■─────────»
     └─────────┘                     └──────────┘└────────┘           »
«     ┌──────────┐
«q_0: ┤ Rz(-π/2) ├
«     ├─────────┬┘
«q_1: ┤ Rz(π/2) ├─
«     └─────────┘ 

The reason that this circuit is being consolidated is that it originally contains CZ gates. If it had contained only RZZ gates, then it would not had been consolidated.

I think that it would be better handled in #13419 (which should take into account the 1-qubit gates).

consolidate_pass = ConsolidateBlocks(basis_gates=["rzz", "rx", "rz"])
res = consolidate_pass(qc)
self.assertEqual({"unitary": 1}, res.count_ops())
self.assertEqual(Operator.from_circuit(qc), Operator(res.data[0].operation.params[0]))
Copy link
Member Author

@ShellyGarion ShellyGarion Feb 25, 2025

Choose a reason for hiding this comment

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

Note that due to the TwoQubitControlledUDecomposer synthesis algorithm, the synthesized circuit is:

q_0: ──────────■──────────────────
     ┌───────┐ │ZZ(-0.3) ┌───────┐
q_1: ┤ Rx(π) ├─■─────────┤ Rx(π) ├
     └───────┘           └───────┘

and not just RZZGate(0.3)

@ShellyGarion ShellyGarion changed the title [WIP] Add 2q fractional gates to the ConsolidateBlocks transpiler pass Add 2q fractional gates to the ConsolidateBlocks transpiler pass Feb 27, 2025
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 mod: transpiler Issues and PRs related to Transpiler
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Optimize consecutive RZZ gates into a single RZZ gate
3 participants