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_single_qubit_gates does not preserve layout #118

Closed
JMuff22 opened this issue Sep 12, 2024 · 2 comments
Closed

optimize_single_qubit_gates does not preserve layout #118

JMuff22 opened this issue Sep 12, 2024 · 2 comments

Comments

@JMuff22
Copy link
Contributor

JMuff22 commented Sep 12, 2024

When using the function optimize_single_qubit_gates on an already transpiled circuit (as per the docs), the layout provided to the transpiler is not preserved. The means that an additional transpiler pass is needed after running optimize_single_qubit_gates.

Reproducible example

from qiskit import QuantumCircuit
from qiskit import transpile
from iqm.qiskit_iqm import IQMFakeAdonis
from iqm.qiskit_iqm.iqm_transpilation import optimize_single_qubit_gates

qc = QuantumCircuit(3)
qc.h(0)
qc.cx(0, 1)
qc.cx(0, 2)
qc.measure_all()

print(qc.draw(output='text'))

backend = IQMFakeAdonis()
transpiled_circuit = transpile(qc, backend=backend)

print()
print(transpiled_circuit.draw(output='text'))

qc_optimized = optimize_single_qubit_gates(transpiled_circuit)

print()
print(qc_optimized.draw(output='text', idle_wires=False))

Gives

        ┌───┐           ░ ┌─┐      
   q_0: ┤ H ├──■────■───░─┤M├──────
        └───┘┌─┴─┐  │   ░ └╥┘┌─┐   
   q_1: ─────┤ X ├──┼───░──╫─┤M├───
             └───┘┌─┴─┐ ░  ║ └╥┘┌─┐
   q_2: ──────────┤ X ├─░──╫──╫─┤M├
                  └───┘ ░  ║  ║ └╥┘
meas: 3/═══════════════════╩══╩══╩═
                           0  1  2 
layout=None

global phase: π/2
               ┌────────────┐┌────────┐   ┌────────────┐  ┌────────┐             ░    ┌─┐   
      q_1 -> 0 ┤ R(π/2,π/2) ├┤ R(π,0) ├─■─┤ R(π/2,π/2) ├──┤ R(π,0) ├─────────────░────┤M├───
               └────────────┘└────────┘ │ └────────────┘  └────────┘             ░    └╥┘   
ancilla_0 -> 1 ─────────────────────────┼──────────────────────────────────────────────╫────
               ┌────────────┐┌────────┐ │                                        ░ ┌─┐ ║    
      q_0 -> 2 ┤ R(π/2,π/2) ├┤ R(π,0) ├─■───────■────────────────────────────────░─┤M├─╫────
               └────────────┘└────────┘         │                                ░ └╥┘ ║    
ancilla_1 -> 3 ─────────────────────────────────┼───────────────────────────────────╫──╫────
               ┌────────────┐┌────────┐         │       ┌────────────┐┌────────┐ ░  ║  ║ ┌─┐
      q_2 -> 4 ┤ R(π/2,π/2) ├┤ R(π,0) ├─────────■───────┤ R(π/2,π/2) ├┤ R(π,0) ├─░──╫──╫─┤M├
               └────────────┘└────────┘                 └────────────┘└────────┘ ░  ║  ║ └╥┘
       meas: 3/═════════════════════════════════════════════════════════════════════╩══╩══╩═
                                                                                    0  1  2 

global phase: 3π/2
        ┌─────────────┐   ┌─────────────┐                ░    ┌─┐   
   q_0: ┤ R(π/2,3π/2) ├─■─┤ R(π/2,5π/2) ├────────────────░────┤M├───
        ├─────────────┤ │ └─────────────┘                ░ ┌─┐└╥┘   
   q_2: ┤ R(π/2,3π/2) ├─■────────■───────────────────────░─┤M├─╫────
        ├─────────────┤          │       ┌─────────────┐ ░ └╥┘ ║ ┌─┐
   q_4: ┤ R(π/2,3π/2) ├──────────■───────┤ R(π/2,5π/2) ├─░──╫──╫─┤M├
        └─────────────┘                  └─────────────┘ ░  ║  ║ └╥┘
meas: 3/════════════════════════════════════════════════════╩══╩══╩═
                                                            0  1  2 

The also applies when providing a layout to the transpiler e.g with initial_layout.

@Aerylia
Copy link
Contributor

Aerylia commented Dec 10, 2024

This bug has been made obsolete with the integration of the IQMOptimizeSingleQubitGates pass into the native Qiskit transpiler logic in the form of a transpiler plugin. Additionally, the transpile_to_IQM function has made the optimize_single_qubit_gates function obsolete and will be deprecated with version 16.0.

Tests cases for this bug have been created and the issue should be resolved with #116

@Aerylia Aerylia closed this as completed Dec 10, 2024
@JMuff22
Copy link
Contributor Author

JMuff22 commented Dec 10, 2024

This bug has been made obsolete with the integration of the IQMOptimizeSingleQubitGates pass into the native Qiskit transpiler logic in the form of a transpiler plugin. Additionally, the transpile_to_IQM function has made the optimize_single_qubit_gates function obsolete and will be deprecated with version 16.0.

Tests cases for this bug have been created and the issue should be resolved with #116

Thanks @Aerylia !!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

2 participants