Skip to content

ElidePermutations does not work correctly with PermutationGates #14602

@alexanderivrii

Description

@alexanderivrii

Environment

  • Qiskit version: 2.0+
  • Python version:
  • Operating system:

What is happening?

The Rust version of the ElidePermutations transpiler pass does not work correctly when the circuit contains PermutationGates.

How can we reproduce the issue?

Consider the following code snippet:

from qiskit.circuit import QuantumCircuit
from qiskit.transpiler import PassManager
from qiskit.transpiler.passes import ElidePermutations

qc = QuantumCircuit(5)
qc.h(1)
qc.swap(1, 2)

pm = PassManager([ElidePermutations()])
res = pm.run(qc)
print(res.layout.final_index_layout())

The ElidePermutations transpiler pass removes the swap gate and instead updates the "final_layout" property of the pass manager. Printing the final_index_layout outputs [0, 2, 1, 3, 4], which is correct.

Now, let's modify the code snippet as follows:

from qiskit.circuit import QuantumCircuit
from qiskit.transpiler import PassManager
from qiskit.transpiler.passes import ElidePermutations
from qiskit.circuit.library import PermutationGate

qc = QuantumCircuit(5)
qc.h(1)
qc.swap(1, 2)
qc.append(PermutationGate([0, 1, 2]), [1, 2, 3])

pm = PassManager([ElidePermutations()])
res = pm.run(qc)
print(res.layout.final_index_layout())

Note that the permutation gate does not do anything -- it's the identity permutation of 3 qubits. However, the final_index_layout is now [0, 1, 2, 3, 4].

The core of the problem is that the mapping in elide_permutations.rs is not updated correctly in the presence of permutation gates. Also note that the problem is worse than just an incorrect final layout: as soon as the mapping becomes incorrect, the following gates are not placed correctly by the pass.

What should happen?

The ElidePermutations pass should work correctly.

Any suggestions?

I am going to submit a PR fixing this problem shortly.

Metadata

Metadata

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions