Skip to content

Fix CSPLayout to detect 3-or-more-qubit gates (fix #7155)#15921

Open
hijirii wants to merge 1 commit intoQiskit:mainfrom
hijirii:fix/csp-layout-3qubit-gate
Open

Fix CSPLayout to detect 3-or-more-qubit gates (fix #7155)#15921
hijirii wants to merge 1 commit intoQiskit:mainfrom
hijirii:fix/csp-layout-3qubit-gate

Conversation

@hijirii
Copy link
Copy Markdown

@hijirii hijirii commented Mar 31, 2026

Summary

CSPLayout was only checking 2-qubit gates (via dag.two_qubit_ops()) and ignoring gates with 3+ qubits like CCX. This caused the pass to incorrectly report 'solution found' for circuits with multi-qubit gates that cannot be mapped to a linear coupling map.

Fix

Added a check for any gate with more than 2 qubits before running the CSP solver. If such a gate is found, the pass now fails gracefully with CSPLayout_stop_reason = "3-or-more-qubit gate found".

Changes

  • csp_layout.py: Added early-exit check for 3+ qubit gates
  • test_csp_layout.py: Added test case covering CCX on linear coupling map

Reproduction (before fix)

from qiskit import QuantumCircuit
from qiskit.transpiler import CouplingMap
from qiskit.transpiler.passes import CSPLayout

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

pass_ = CSPLayout(CouplingMap([[0, 1], [1, 2]]))
result = pass_(qc)
print(pass_.property_set["CSPLayout_stop_reason"])
# Before: 'solution found' (WRONG - CCX needs complete connectivity)
# After:  '3-or-more-qubit gate found'

Checklist

  • Tests pass (existing + new test for this case)
  • Follows Qiskit coding style
  • Documentation updated (if needed)
  • Changelog entry (if applicable)

Closes #7155

CSPLayout was only checking 2-qubit gates (via dag.two_qubit_ops())
and ignoring gates with 3+ qubits like CCX. This caused the pass to
incorrectly report 'solution found' for circuits with multi-qubit
gates that cannot be mapped to a linear coupling.

Now the pass checks for any gate with more than 2 qubits and fails
gracefully with '3-or-more-qubit gate found' instead.

Fixes Qiskit#7155
@hijirii hijirii requested a review from a team as a code owner March 31, 2026 04:57
@qiskit-bot qiskit-bot added the Community PR PRs from contributors that are not 'members' of the Qiskit repo label Mar 31, 2026
@qiskit-bot
Copy link
Copy Markdown
Collaborator

Thank you for opening a new pull request.

Before your PR can be merged it will first need to pass continuous integration tests and be reviewed. Sometimes the review process can be slow, so please be patient.

While you're waiting, please feel free to review other open PRs. While only a subset of people are authorized to approve pull requests for merging, everyone is encouraged to review open pull requests. Doing reviews helps reduce the burden on the core team and helps make the project's code better for everyone.

One or more of the following people are relevant to this code:

  • @Qiskit/terra-core

@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

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

Labels

Community PR PRs from contributors that are not 'members' of the Qiskit repo

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

CSP ignores 3-or-more-qubit gates

3 participants