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

Add flexible-layer mapper (FlexlayerSwap) pass #1803

Closed
wants to merge 46 commits into from
Closed

Add flexible-layer mapper (FlexlayerSwap) pass #1803

wants to merge 46 commits into from

Conversation

itoko
Copy link
Contributor

@itoko itoko commented Feb 13, 2019

Summary

  • Add FlexlayerSwap pass
  • Add undirected_neighbors() to CouplingMap

FlexlayerSwap pass implements the swap mapping heuristics proposed in [1].

Details and comments

The algorithm considers the dependency graph of a given circuit
with less dependencies by considering commutativity of consecutive gates,
and updates blocking gates in the dependency graph by changing qubit layout
(= adding SWAPs). The blocking gates are the leading unresolved gates for
a current layout, and they can be seen as a kind of flexible layer
in contrast to many other swap passes assumes fixed layers as their input.
That's why this pass is named FlexlayerSwap pass.

[1] T. Itoko, R. Raymond, T. Imamichi, A. Matsuo, and A. W. Cross.
Quantum circuit compilers using gate commutation rules.
In Proceedings of ASP-DAC, pp. 191--196. ACM, 2019.
See https://arxiv.org/abs/1907.02686 (extended version of [1]) for the details of the algorithm.

FlexlayerSwap pass has possibility to dramatically reduce CNOT counts in mapped circuits. For example, see CNOT counts below, obtained by running isometry.IsometryTranspileBench.track_cnot_counts_after_mapping_to_ibmq_16_melbourne in my local environment. They show that the replacement of StochasticSwap with FlexlayerSwap can improve the performance of level1 pass manager on CNOT counts.

[Before (current level1 pass manager)]
======================== ==== ===== ===== ======

--                       number of output qubits

------------------------ -----------------------

 number of input qubits   3     4     5     6   

======================== ==== ===== ===== ======

           0              7     26    86   192  

           1              25    76   206   473  

           2              57   177   428   951  

           3              80   383   931   1989 

======================== ==== ===== ===== ======

[After (replacing StochasticSwap with FlexlayerSwap)]
======================== ==== ===== ===== ======

--                       number of output qubits

------------------------ -----------------------

 number of input qubits   3     4     5     6   

======================== ==== ===== ===== ======

           0              7     23    62   147  

           1              22    67   158   353  

           2              48   141   344   779  

           3              80   302   717   1569 

======================== ==== ===== ===== ======

For example, 21% reduction in (3, 6) case.

@itoko itoko changed the title WIP: Add flexible-layer mapper (FlexlayerSwap) pass [WIP] Add flexible-layer mapper (FlexlayerSwap) pass Feb 13, 2019
@CLAassistant
Copy link

CLAassistant commented Feb 14, 2019

CLA assistant check
All committers have signed the CLA.

@1ucian0
Copy link
Member

1ucian0 commented Mar 25, 2019

@itoko any update here?

@itoko
Copy link
Contributor Author

itoko commented Apr 2, 2019

@1ucian0 I'm waiting the responses to the issue #2044. I personally think swap pass should return physical circuit. To complete this PR, I need the final decision on which (physical or virtual) circuit swap pass return.

@itoko
Copy link
Contributor Author

itoko commented Jul 25, 2019

@1ucian0 I'm not sure qiskit/transpiler/passes/mapping/algorithm is the right place or not, but I think it's not so bad to be there since modules under /algorithm (we may have better name than algorithm) are intended to be used only in some passes.

@1ucian0 1ucian0 self-assigned this Sep 24, 2019
circuit.cx(qr[1], qr[0])
circuit.measure(qr[0], cr[1])
dep_graph = DependencyGraph(circuit)
self.assertEqual(dep_graph.qargs(0), [(qr, 1), (qr, 0)])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
self.assertEqual(dep_graph.qargs(0), [(qr, 1), (qr, 0)])
self.assertEqual(dep_graph.qargs(0), [qr[1], qr[0]])

We are not using tuples anymore to refer to qubits.


# This code is part of Qiskit.
#
# (C) Copyright IBM 2017.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# (C) Copyright IBM 2017.
# (C) Copyright IBM 2019.

Copy link
Member

@1ucian0 1ucian0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be nice to extract the dependency graph construction as an analysis pass. What do you think @ajavadia

@1ucian0 1ucian0 added the status: needs information Further information is requested label Sep 30, 2019
@kdk
Copy link
Member

kdk commented Sep 30, 2019

I think it would be nice to extract the dependency graph construction as an analysis pass. What do you think @ajavadia

I agree this would be a good enhancement, but I think we can tackle this in a follow-up PR.

"""
self._qc = qc

if initial_layout is None:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a swapper should work with "physical circuits" and no layout should be interpreted at this point. This is something that was decided after this PR was initially submitted... sorry about that :(

features:
- |
Added a `FlexlayerSwap` pass, that implements a look-ahead heuristic
mapping algorithm. It can be used by replacing the `StochasticSwap`,
Copy link
Member

@1ucian0 1ucian0 Sep 30, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it could be better to have a standalone example, using a physical circuit (e.i written in terms of q qubits) and show how it works. Otherwise, after #3004 gets merged (it will soon), you can replace the swapper using the new API. The table from this PR might be handy to show the improvement. A link to the paper is could also be informative.

@lcapelluto lcapelluto removed their assignment Nov 12, 2019
@itoko itoko mentioned this pull request Jan 31, 2020
@ajavadia
Copy link
Member

The dependency graph portion of this has been implemented in #3581 - so this PR needs to be updated. @itoko can you do that? Otherwise I think we should close this.

@itoko
Copy link
Contributor Author

itoko commented Jun 25, 2020

@ajavadia I can do that, but it might be better to reimplement our Flexlayer pass on the basis of the Sabre routing pass merged recently (#4537).
This is because the Flexlayer pass is very similar to the Sabre routing pass, accidentally we (@itoko and @skywalker2012 ) think of very alike routing algorithm independently at the same time ([1] and [2]).

The improvement in the Flexlayer pass from Sabre routing pass would be:

  • Use of dependency graph
  • Small change in the decay weight W so that it depends on the step size from the current layer (e.g. 0.5 for gates in the next layer, 0.25 for gates in the next next layer, etc)
  • Use of bridge gates as well as swap gates (proposed in [3] = extended paper of [1])

I think I should close this PR and open a new PR that extends the Sabre routing pass (should I create a new subclass of Sabre routing pass?). What do you think? @ajavadia

I admit the Sabre layout pass, that implements Li's reverse traversal technique, is very cool and useful (That would be the main difference between [1] and [2] as I mentioned in [3]). I know I don't need to touch the layout pass.

[1] T. Itoko et al. Quantum circuit compilers using gate commutation rules. In Proceedings of the 24th Asia and South Pacific Design Automation Conference, pp. 191-196 (January, 2019).
[2] G. Li, Y. Ding, Y. Xie, Tackling the qubit mapping problem for nisq-era quantum devices, In Proceedings of the Twenty-Fourth International Conference on Architectural Support for Programming Languages and Operating Systems, ACM, April, 2019, pp. 1001-1014.
[3] T. Itoko et al. Optimization of quantum circuit mapping using gate transformation and commutation. Integration 70 (2020): 43-50.

@ajavadia
Copy link
Member

ajavadia commented Jun 25, 2020 via email

@mtreinish
Copy link
Member

@itoko since this has been stale without update for ~1 year and was initially proposed >2 yrs ago I'm going to close this. But please feel free to reopen this if you have the bandwidth to finish it and update this for current terra.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: needs information Further information is requested
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants