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

layout_method and routing_method selectors in transpile() #3999

Merged
merged 7 commits into from
Mar 30, 2020

Conversation

ajavadia
Copy link
Member

Adding the ability to quickly select layout_method and routing_method from the top-level transpile() call. This configures the level 0-3 passmanagers to use the given methods for layout and routing.

Something like this using passmanager.replace() is also doable but not as convenient due to the issue of conditions, control-flow, etc. surrounding the passes.

Generally I think there are a few basic & key steps to the compilation flow, each of which have several possible methods: optimization, placement, routing, scheduling, pulse selection.
With optimization_level, layout_method, routing_method we cover the first 3. The 4th is in the form of schedule(circuit, method) right now.

Building a passmanager gives you ultimate control over how passes get chained, repeated until convergence, etc. but high-level options are still very useful in allowing the user to quickly explore alternatives. For example right now I don't think the "lookahead swap" is used anywhere or anyone knows how to invoke it.

@ajavadia
Copy link
Member Author

depends on #3992 adn #3996

@ajavadia ajavadia force-pushed the transpile-method-selectors branch from ee86ad6 to 137b3f2 Compare March 25, 2020 09:09
@ajavadia ajavadia removed the on hold Can not fix yet label Mar 25, 2020
Copy link
Member

@kdk kdk left a comment

Choose a reason for hiding this comment

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

Looks good so far. Can you add a release note?

Right now, these don't completely override layout selection . E.g. for level2, if a user requests 'noise_adaptive', we'll still run csp_layout -> _choose_layout_condition -> noise_adaptive. This is reasonable behavior, but might not be what the user expects, so we should point it out in the docstring.

qiskit/compiler/transpile.py Show resolved Hide resolved
qiskit/compiler/transpile.py Show resolved Hide resolved
_given_layout = SetLayout(initial_layout)

def _choose_layout_condition(property_set):
return not property_set['layout']

_choose_layout = TrivialLayout(coupling_map)
if layout_method == 'trivial':
Copy link
Member

Choose a reason for hiding this comment

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

Can this be consolidated in e.g. _parse_layout_method (and pass the selected class or None in the passmanagerconfig?)

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah that would be good to avoid repetition but right now the layout passes don't have the same signature, so I can't just pass the class here.

    if layout_method == 'trivial':
        _choose_layout = TrivialLayout(coupling_map)
    elif layout_method == 'dense':
        _choose_layout = DenseLayout(coupling_map, backend_properties)
    elif layout_method == 'noise_adaptive':
        _choose_layout = NoiseAdaptiveLayout(backend_properties)

It would be ideal to provide a unified interface though. I think in general there is too much repetition between the preset passmanagers, so a refactoring that makes them derive the same base and tweak would be great.

qiskit/transpiler/preset_passmanagers/level0.py Outdated Show resolved Hide resolved
@ajavadia ajavadia force-pushed the transpile-method-selectors branch from 137b3f2 to ebd290b Compare March 27, 2020 02:10
@ajavadia ajavadia force-pushed the transpile-method-selectors branch from a02e9c1 to e88c19f Compare March 28, 2020 00:35
@kdk kdk added the Changelog: API Change Include in the "Changed" section of the changelog label Mar 30, 2020
@kdk kdk added this to the 0.13 milestone Mar 30, 2020
@kdk kdk added the automerge label Mar 30, 2020
@mergify mergify bot merged commit a8dcbe1 into Qiskit:master Mar 30, 2020
mtreinish added a commit to mtreinish/qiskit-core that referenced this pull request Apr 7, 2020
In Qiskit#3999 we increased the number of trials, but the global benefit from
doing this isn't clear. With the pending release weighing the increased
run time for more trials against this, this commit temporarily reverts
the number of trials for level 1 and level 2 back to their previous
setting of 20. When we get to the bottom of Qiskit#4094 and have a fix or
change for that we can increase the number of trials again.

Related Qiskit#4094
ajavadia pushed a commit that referenced this pull request Apr 7, 2020
In #3999 we increased the number of trials, but the global benefit from
doing this isn't clear. With the pending release weighing the increased
run time for more trials against this, this commit temporarily reverts
the number of trials for level 1 and level 2 back to their previous
setting of 20. When we get to the bottom of #4094 and have a fix or
change for that we can increase the number of trials again.

Related #4094
faisaldebouni pushed a commit to faisaldebouni/qiskit-terra that referenced this pull request Aug 5, 2020
* add ability to select layout and routing method from top transpile function

* set lookahead width/depth in increasing order

* releasenote

* review comments

* lint

* lint

Co-authored-by: Kevin Krsulich <[email protected]>
faisaldebouni pushed a commit to faisaldebouni/qiskit-terra that referenced this pull request Aug 5, 2020
…4099)

In Qiskit#3999 we increased the number of trials, but the global benefit from
doing this isn't clear. With the pending release weighing the increased
run time for more trials against this, this commit temporarily reverts
the number of trials for level 1 and level 2 back to their previous
setting of 20. When we get to the bottom of Qiskit#4094 and have a fix or
change for that we can increase the number of trials again.

Related Qiskit#4094
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelog: API Change Include in the "Changed" section of the changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants