qiskit icon indicating copy to clipboard operation
qiskit copied to clipboard

CSP ignores 3-or-more-qubit gates

Open 1ucian0 opened this issue 3 years ago • 12 comments

Information

  • Qiskit Terra version: main

What is the current behavior?

Take the following circuit:

from qiskit import QuantumCircuit
qc = QuantumCircuit(3)
qc.cx(0,1)
qc.ccx(2,0,1)
qc.draw()
q_0: ──■────■──
     ┌─┴─┐┌─┴─┐
q_1: ┤ X ├┤ X ├
     └───┘└─┬─┘
q_2: ───────■──

CSPLayout should not be able to find a solution with a layout 0- > 1 -> 2. However:

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

pass_ = CSPLayout(CouplingMap([(0, 1), (1, 2)]))
result = pass_(qc)
pass_.property_set["CSPLayout_stop_reason"]
'solution found'

Suggested solutions

There are two options. If CSPLayout encounters a 3-or-more-qubit gate, either assumes that this needs complete connection among the involved qubits, or just fails with reason 3-or-more-qubit gate found.

1ucian0 avatar Oct 18 '21 14:10 1ucian0

@1ucian0 I tried to add 3-or-more-qubit gates as constraints, and the pass generates this layout:

Layout({
1: Qubit(QuantumRegister(3, 'qr'), 0),
0: Qubit(QuantumRegister(3, 'qr'), 1),
2: Qubit(QuantumRegister(3, 'qr'), 2)
})

I guess maybe it is reasonable? It does not involve swaps. It simply suggests that mapping qr[0] to physical qubit 1. Such mapping is allowed, right? It is kind of the point of using CSP in this pass.

yjt98765 avatar Oct 28 '21 03:10 yjt98765

In the original example, CCX does not have a possible layout in the coupling map 0 - > 1 -> 2. No solution should be found or raise.

1ucian0 avatar Nov 29 '21 09:11 1ucian0

Can I work on this?

Silrem avatar Jan 28 '22 11:01 Silrem

Sure thing @Silrem. Assigning. let me know if I can help!

1ucian0 avatar Jan 31 '22 17:01 1ucian0

@1ucian0 Just created a PR (#7625). Not sure if I can/should add you as a reviewer. Anyway, my first draft is there =)

Silrem avatar Feb 05 '22 10:02 Silrem

un-assigning so that this issue is open for others to have a go. If anyone would like to pick this work up make sure to take a look at #7625 and go from there 😄

javabster avatar Dec 12 '22 19:12 javabster

I want to work on the issue if it still exists.

lmpawan10 avatar May 30 '23 08:05 lmpawan10

sorry for the slow reply @lmpawan10, I'll assign to you 😄 As this is an old issue the first step would be to check that the bug still exists

javabster avatar Jun 16 '23 18:06 javabster

Hello @lmpawan10 ! Are you still working on this one?

1ucian0 avatar Aug 14 '23 08:08 1ucian0

Sorry that I got busier with other tasks. I am planning to work on this issue this month. You can give it to others if they are interested, or I will deal with it.

lmpawan10 avatar Aug 15 '23 07:08 lmpawan10

Hi @lmpawan10 ! how is that going?

1ucian0 avatar Sep 16 '23 20:09 1ucian0

clearing assignee

1ucian0 avatar May 07 '24 14:05 1ucian0