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

Open
JMuff22 opened this issue Sep 12, 2024 · 0 comments · May be fixed by #119
Open

optimize_single_qubit_gates does not preserve layout #118

JMuff22 opened this issue Sep 12, 2024 · 0 comments · May be fixed by #119

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.

@JMuff22 JMuff22 linked a pull request Sep 12, 2024 that will close this issue
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.

1 participant