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

ElidePermutation undoes routing #13144

Closed
ajavadia opened this issue Sep 12, 2024 · 0 comments · Fixed by #13184
Closed

ElidePermutation undoes routing #13144

ajavadia opened this issue Sep 12, 2024 · 0 comments · Fixed by #13184
Labels
bug Something isn't working
Milestone

Comments

@ajavadia
Copy link
Member

Environment

  • Qiskit version: 1.3 dev
  • Python version: 3.10
  • Operating system: mac

What is happening?

Circuits that are mapped and routed can become unmapped unintentionally due to ElidePermutation treating inserted SWAPs as unwanted.

How can we reproduce the issue?

Suppose i ran some routing passes and got the following circuit on a line of 4 qubits. Then i just want to bring it down to some basis gates. Optimization level 2 and 3 (due to ElidePermutation) will undo the mapping.

circuit_routed = QuantumCircuit(4)
circuit_routed.cx(0, 1)
circuit_routed.h(1)
circuit_routed.swap(1, 2)
circuit_routed.cx(2, 3)
print(circuit_routed)

pm = generate_preset_pass_manager(basis_gates=['cx', 'sx', 'rz'],  routing_method='none', optimization_level=2)
circuit_basis = pm.run(circuit_routed)

circuit_basis = pm.run(circuit_routed)
print(circuit_basis)

gives

q_0: ──■───────────────
     ┌─┴─┐┌───┐        
q_1: ┤ X ├┤ H ├─X──────
     └───┘└───┘ │      
q_2: ───────────X───■──
                  ┌─┴─┐
q_3: ─────────────┤ X ├
                  └───┘
global phase: π/4
                                                                             
Qubit(QuantumRegister(4, 'q'), 0) -> 0 ──■───────────────────────────────────
                                       ┌─┴─┐┌─────────┐┌────┐┌─────────┐     
Qubit(QuantumRegister(4, 'q'), 1) -> 1 ┤ X ├┤ Rz(π/2) ├┤ √X ├┤ Rz(π/2) ├──■──
                                       └───┘└─────────┘└────┘└─────────┘  │  
Qubit(QuantumRegister(4, 'q'), 2) -> 2 ───────────────────────────────────┼──
                                                                        ┌─┴─┐
Qubit(QuantumRegister(4, 'q'), 3) -> 3 ─────────────────────────────────┤ X ├
                                                                        └───┘

What should happen?

routing_method='none' should disable ElidePermutation (or anything that wants to remove swaps)

Any suggestions?

No response

@ajavadia ajavadia added the bug Something isn't working label Sep 12, 2024
@mtreinish mtreinish added this to the 1.2.2 milestone Sep 12, 2024
mtreinish added a commit to mtreinish/qiskit-core that referenced this issue Sep 18, 2024
We have a routing plugin named "none" which is used to assert that no
routing should be performed (it errors if there is routing required).
We were previously running the ElidePermutations pass in this case which
is not the expected or correct behavior because it causes the same kind
of permutation as routing and would eliminate and swap gates in the
circuit. As the typical use case for routing_method='none' is when
you've already routed a circuit (or constructed it by hand to match the
connectivity constraints) we shouldn't be doing this. This commit fixes
this behavior so if the routing_method is set to "none" we no longer run
the ElidePermutations pass.

Fixes Qiskit#13144
github-merge-queue bot pushed a commit that referenced this issue Sep 19, 2024
* Don't run ElidePermutation if routing is disabled

We have a routing plugin named "none" which is used to assert that no
routing should be performed (it errors if there is routing required).
We were previously running the ElidePermutations pass in this case which
is not the expected or correct behavior because it causes the same kind
of permutation as routing and would eliminate and swap gates in the
circuit. As the typical use case for routing_method='none' is when
you've already routed a circuit (or constructed it by hand to match the
connectivity constraints) we shouldn't be doing this. This commit fixes
this behavior so if the routing_method is set to "none" we no longer run
the ElidePermutations pass.

Fixes #13144

* Move release note to the correct location
mergify bot pushed a commit that referenced this issue Sep 19, 2024
* Don't run ElidePermutation if routing is disabled

We have a routing plugin named "none" which is used to assert that no
routing should be performed (it errors if there is routing required).
We were previously running the ElidePermutations pass in this case which
is not the expected or correct behavior because it causes the same kind
of permutation as routing and would eliminate and swap gates in the
circuit. As the typical use case for routing_method='none' is when
you've already routed a circuit (or constructed it by hand to match the
connectivity constraints) we shouldn't be doing this. This commit fixes
this behavior so if the routing_method is set to "none" we no longer run
the ElidePermutations pass.

Fixes #13144

* Move release note to the correct location

(cherry picked from commit 9a896d3)
github-merge-queue bot pushed a commit that referenced this issue Sep 20, 2024
* Don't run ElidePermutation if routing is disabled

We have a routing plugin named "none" which is used to assert that no
routing should be performed (it errors if there is routing required).
We were previously running the ElidePermutations pass in this case which
is not the expected or correct behavior because it causes the same kind
of permutation as routing and would eliminate and swap gates in the
circuit. As the typical use case for routing_method='none' is when
you've already routed a circuit (or constructed it by hand to match the
connectivity constraints) we shouldn't be doing this. This commit fixes
this behavior so if the routing_method is set to "none" we no longer run
the ElidePermutations pass.

Fixes #13144

* Move release note to the correct location

(cherry picked from commit 9a896d3)

Co-authored-by: Matthew Treinish <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants