Skip to content

Commit

Permalink
Added mutli gate qubit connection requirement (solving Qiskit#7155)
Browse files Browse the repository at this point in the history
  • Loading branch information
ChilliPenguin committed Aug 6, 2024
1 parent 1fdd527 commit 5456475
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions qiskit/transpiler/passes/layout/csp_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,19 @@ def run(self, dag):
"map."
)
qubits = dag.qubits
cxs = set()
qubit_connections = set()

from constraint import Problem, AllDifferentConstraint, RecursiveBacktrackingSolver
from qiskit.transpiler.passes.layout._csp_custom_solver import CustomSolver

for gate in dag.two_qubit_ops():
cxs.add((qubits.index(gate.qargs[0]), qubits.index(gate.qargs[1])))
qubit_connections.add((qubits.index(gate.qargs[0]), qubits.index(gate.qargs[1])))

for gate in dag.multi_qubit_ops():
for i in range(len(gate.qargs)):
for j in range(i+1,len(gate.qargs)):
qubit_connections.add((qubits.index(gate.qargs[i]), qubits.index(gate.qargs[j]))) #last qubit in qargs will always be the target, thus always on the right here

edges = set(self.coupling_map.get_edges())

if self.time_limit is None and self.call_limit is None:
Expand All @@ -111,7 +117,7 @@ def constraint(control, target):
def constraint(control, target):
return (control, target) in edges or (target, control) in edges

for pair in cxs:
for pair in qubit_connections:
problem.addConstraint(constraint, [pair[0], pair[1]])

solution = problem.getSolution()
Expand Down

0 comments on commit 5456475

Please sign in to comment.