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

Optimize consecutive RZZ gates into a single RZZ gate #13428

Open
t-imamichi opened this issue Nov 13, 2024 · 5 comments
Open

Optimize consecutive RZZ gates into a single RZZ gate #13428

t-imamichi opened this issue Nov 13, 2024 · 5 comments
Labels
mod: transpiler Issues and PRs related to Transpiler type: feature request New feature or request

Comments

@t-imamichi
Copy link
Member

t-imamichi commented Nov 13, 2024

What should we add?

Since the fractional gates are available, RZZ can be used as a basis gate.
But, optimization of consecutive RZZ gates does not seem to be enough as follows.
It would be nice to merge them into a single RZZ.

from qiskit import generate_preset_pass_manager, QuantumCircuit

qc = QuantumCircuit(2)
qc.rzz(0.1, 0, 1)
qc.rzz(0.2, 0, 1)

pm = generate_preset_pass_manager(optimization_level=3, basis_gates=["rzz"])
qc2 = pm.run(qc)
print(qc2)

output (both 1.2.4 and main branch)

q_0: ─■─────────■────────
      │ZZ(0.1)  │ZZ(0.2)
q_1: ─■─────────■────────
@t-imamichi t-imamichi added type: feature request New feature or request mod: transpiler Issues and PRs related to Transpiler labels Nov 13, 2024
@melechlapson
Copy link
Contributor

Is this issue limited to the rzz gates and not other gates like ryy rzx etc.?

@t-imamichi
Copy link
Member Author

Not limited to RZZ. But I don't mind RYY and RZX because RZZ becomes a basis gate of devices that supports fractional gates. RYY and RZX are not basis gates of any device.
https://docs.quantum.ibm.com/guides/fractional-gates

@ShellyGarion
Copy link
Member

There is a synthesis algorithm TwoQubitControlledUDecomposer that takes a 2q-unitary and synthesizes it using the 2q basis gate RZZGate (with angles in the range [-pi/2, pi/2]. This algorithm has recently been ported to rust in #13139.

Here is an example of the output of this algorithm on the circuit suggested below:

        from qiskit.quantum_info import Operator
        from qiskit.synthesis.two_qubit.two_qubit_decompose import TwoQubitControlledUDecomposer
        unitary = Operator(qc)
        decomposer = TwoQubitControlledUDecomposer(RZZGate)
        qc3 = decomposer(unitary)
        print (qc3)

outputs:

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

This algorithm should be added to the unitary synthesis tranpiler pass (#13320).
Then I think that this issues will be solved. Note that the redundant 1q gates should be eliminated by the 1q synthesis transpiler passes.

@ShellyGarion
Copy link
Member

Is this issue limited to the rzz gates and not other gates like ryy rzx etc.?

@melechlapson -
Note that the synthesis algorithm TwoQubitControlledUDecomposer suggested above works also for gates like RYY, RZX, RXX etc. that are equivalent to an RZZ up to 1q-unitary gates.

@t-imamichi
Copy link
Member Author

Thank you for your information, @ShellyGarion. I would like to use the algorithm as a transpiler pass. So I wait for #13320.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mod: transpiler Issues and PRs related to Transpiler type: feature request New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants