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

Why not Swap passes return circuit with physical qubits #2044

Closed
itoko opened this issue Mar 29, 2019 · 4 comments
Closed

Why not Swap passes return circuit with physical qubits #2044

itoko opened this issue Mar 29, 2019 · 4 comments
Assignees

Comments

@itoko
Copy link
Contributor

itoko commented Mar 29, 2019

Users are likely to expect Swap passes return physical circuit (circuit with physical qubits) as the original swap mapper was doing so. However current Swap passes [<-This was not correct. BasicSwap and LookaheadSwap return physical circuit. Only the StochasticSwap doesn't return physical circuit] return logical circuit (circuit with virtual qubits) + initial layout. Not only it different from users' expectation, but also it means users must apply the initial layout to the logical circuit in order to get physical circuit (using another pass, say ApplyLayout pass).
The problem is it must be done "before" applying Decompose(SwapGate) pass because ApplyLayout pass need to track layout change relying on swap gates. Once swap gates are decomposed, users no longer produce physical circuit. Can PassManager handle this dependency? I think manual management of this kind of dependency is not a good solution. (Note that I don't argue if ApplyLayout pass is necessary or not). This issue is created for discussing what SwapPasses should return.
Isn't "SwapPasses return physical circuit" the simplest solution?

Simple example:

CouplingMap map: [1]--[0]--[2]

[Original circuit]

 v0:-------M(v0->c0)

 v1:---.---M(v1->c1)
       |
 v2:--(+)--M(v2->c2)

CNOT(v1, v2)
Measure(v1, c1)
Measure(v2, c2)


[Current output (StochasticSwap)]

 v0:--X---.---M(v1->c1)
      |   |
 v1:--X---|---M(v0->c0)
          |
 v2:-----(+)--M(v2->c2)

SWAP(v0, v1)
CNOT(v1, v2)
Measure(v1, c1)
Measure(v2, c2)
+
Initial layout: {v0: q0, v1: q1, v2: q2}


[Proposed output (LookaheadSwap)]

 q0:--X---.---M(q0->c1)
      |   |
 q1:--X---|---M(q1->c0)
          |
 q2:-----(+)--M(q2->c2)

SWAP(q0, q1)
CNOT(q0, q2)
Measure(q0, c1)
Measure(q2, c2)
+
Initial layout: {v0: q0, v1: q1, v2: q2}


[After Decompose(SwapGate)]

 v0:--.-(+)-.--.---M(v1->c1)
      |  |  |  |
 v1:-(+)-.-(+)-|---M(v0->c0)
               |
 v2:----------(+)--M(v2->c2)

No general means to detect layout change:
{v0: q0, v1: q1, v2: q2} -> {v0: q1, v1: q0, v2: q2}
@itoko
Copy link
Contributor Author

itoko commented Apr 3, 2019

I found I misunderstood output of current swap passes, pointed out by @1ucian0 .
BasicSwap and LookaheadSwap return "semantically" physical circuit. So I have no issue on those two swap passes. This issue only goes for StochasticSwap.

@ajavadia
Copy link
Member

ajavadia commented Apr 4, 2019

The problem is it must be done "before" applying Decompose(SwapGate) pass because ApplyLayout pass need to track layout change relying on swap gates.

I don't agree with this. ApplyLayout should not care about the contents of the circuit. The circuit is what it is, it could have any gates. The ApplyLayout pass will only relabel and permute qubits (how can it even know which swaps were introduced by the swapper and which swaps were part of the original circuit?)

@itoko
Copy link
Contributor Author

itoko commented Apr 5, 2019

@ajavadia Oh, I understand your definition of ApplyLayout (what I thought may be too much). It is just a rename of qubits from virtual ones to physical ones (a special case of RenameQubits), right? For example,

[In (like current output of BasicSwap)]
Initial layout: {v0: q0, v1: q1, v2: q2}
 v0:--X---.---M(v0->c1)
      |   |
 v1:--X---|---M(v1->c0)
          |
 v2:-----(+)--M(v2->c2)
SWAP(v0, v1)
CNOT(v0, v2)
Measure(v0, c1)
Measure(v2, c2)

[Out (like current output of LookaheadSwap)]
 q0:--X---.---M(q0->c1)
      |   |
 q1:--X---|---M(q1->c0)
          |
 q2:-----(+)--M(q2->c2)
SWAP(q0, q1)
CNOT(q0, q2)
Measure(q0, c1)
Measure(q2, c2)
# q0, q1, q2 must be said just 0, 1, 2 formally

According to your comments on #2066, I think you agreed that Swap passes should return circuit with physical qubits. So I think we can close this issue and continue discussion on how and when (your definition of) ApplyLayout should be used at #2066.

@ajavadia
Copy link
Member

ajavadia commented Apr 6, 2019

Ok so let's continue the discussion in #2066

@ajavadia ajavadia closed this as completed Apr 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants