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

Migrate layout stage to plugins #10622

Merged
merged 6 commits into from
Aug 22, 2023
Merged

Conversation

mtreinish
Copy link
Member

Summary

This commit updates the preset pass manager construction to only use plugins for the layout stage. To accomplish this the previously hard coded built-in layout methods, trivial, dense, noise adaptive, and sabre are migrated to be exposed as built-in plugins. Additionally, the special case of layout_method=None has been centralized into a standard default method plugin, as the pass construction in this case involved extra steps for each optimization level. This simplifies the preset pass manager construction as now the layout stage is solely built via plugins.

Details and comments

Fixes #9455

This commit updates the preset pass manager construction to only use
plugins for the layout stage. To accomplish this the previously hard
coded built-in layout methods, trivial, dense, noise adpative, and
sabre are migrated to be exposed as built-in plugins. Additionally, the
special case of layout_method=None has been centralized into a standard
default method plugin, as the pass construction in this case involved
extra steps for each optimization level. This simplifies the preset pass
manager construction as now the layout stage is solely built via
plugins.

Fixes Qiskit#9455
@mtreinish mtreinish added Changelog: API Change Include in the "Changed" section of the changelog mod: transpiler Issues and PRs related to Transpiler labels Aug 14, 2023
@mtreinish mtreinish added this to the 0.45.0 milestone Aug 14, 2023
@mtreinish mtreinish requested a review from a team as a code owner August 14, 2023 16:44
@qiskit-bot
Copy link
Collaborator

One or more of the the following people are requested to review this:

  • @Qiskit/terra-core

@coveralls
Copy link

Pull Request Test Coverage Report for Build 5858335590

  • 123 of 130 (94.62%) changed or added relevant lines in 5 files are covered.
  • 25 unchanged lines in 2 files lost coverage.
  • Overall coverage decreased (-0.03%) to 87.244%

Changes Missing Coverage Covered Lines Changed/Added Lines %
qiskit/transpiler/preset_passmanagers/builtin_plugins.py 115 122 94.26%
Files with Coverage Reduction New Missed Lines %
crates/qasm2/src/lex.rs 7 90.63%
crates/qasm2/src/parse.rs 18 96.67%
Totals Coverage Status
Change from base Build 5857364416: -0.03%
Covered Lines: 74250
Relevant Lines: 85106

💛 - Coveralls

Copy link
Member

@jakelishman jakelishman left a comment

Choose a reason for hiding this comment

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

This one's a bit more involved than the translations step haha.

Comment on lines +384 to +393
def pass_manager(self, pass_manager_config, optimization_level=None) -> PassManager:
_given_layout = SetLayout(pass_manager_config.initial_layout)

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

def _layout_not_perfect(property_set):
"""Return ``True`` if the first attempt at layout has been checked and found to be
imperfect. In this case, perfection means "does not require any swap routing"."""
return property_set["is_swap_mapped"] is not None and not property_set["is_swap_mapped"]
Copy link
Member

Choose a reason for hiding this comment

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

Are there any concerns about pickle-ability of the resulting pass manager now we're retuning method-local functions as part of the conditions?

(also, lol at using explicitly private names when defining method-internal functions - a clear copy-paste sign haha)

Copy link
Member Author

Choose a reason for hiding this comment

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

There shouldn't be as it's passing the parallel transpiler tests which should be testing this.

qiskit/transpiler/preset_passmanagers/builtin_plugins.py Outdated Show resolved Hide resolved
qiskit/transpiler/preset_passmanagers/builtin_plugins.py Outdated Show resolved Hide resolved
layout.append(
NoiseAdaptiveLayout(pass_manager_config.target), condition=_choose_layout_condition
)
layout += common.generate_embed_passmanager(coupling_map)
Copy link
Member

Choose a reason for hiding this comment

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

With how we use this, I wonder a little if embed should be a separate stage in the transpiler pipeline. There's only ever a single version of it that would make sense, I guess, which reduces its importance, but it's a common usage pitfall to forget to run an embed step after what most people consider to be a complete "layout" stage, and it might be a clearer separation of concerns if "embed" is a separate stage.

That said, it'd probably play even weirder with the hybrid layout+routing manager we do in the defaults.

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, it potentially would have made sense when we originally did the stages. I was thinking also as a post-layout stage it would work instead of doing an explicit embed stage. But that layout ensure it is embedded is baked into the plugin interface now: https://qiskit.org/documentation/apidoc/transpiler_plugins.html#plugin-stages (under expectations for layouts). If we wanted to split it out now we'd have to condition the stage to only run if it's not already been embedded.

Copy link
Member

@jakelishman jakelishman left a comment

Choose a reason for hiding this comment

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

This looks fine to me now, thanks. I guess my main problem with the optimization_level argument to PassManagerStagePlugin.pass_manager is that it's given a default of None by the interface, but it's actually required to be given and be an integer. That's beyond the scope of implementing plugins here, but imo it should either have not had a default value at all, or had a default of 1.

@jakelishman jakelishman added this pull request to the merge queue Aug 22, 2023
Merged via the queue into Qiskit:main with commit b039687 Aug 22, 2023
SamD-1998 pushed a commit to SamD-1998/qiskit-terra that referenced this pull request Sep 7, 2023
* Migrate layout stage to plugins

This commit updates the preset pass manager construction to only use
plugins for the layout stage. To accomplish this the previously hard
coded built-in layout methods, trivial, dense, noise adpative, and
sabre are migrated to be exposed as built-in plugins. Additionally, the
special case of layout_method=None has been centralized into a standard
default method plugin, as the pass construction in this case involved
extra steps for each optimization level. This simplifies the preset pass
manager construction as now the layout stage is solely built via
plugins.

Fixes Qiskit#9455

* Remove unnecessary if statement

* Handle invalid optimization levels in plugins

* Remove unused variable post-rebase
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 mod: transpiler Issues and PRs related to Transpiler
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create layout stage (trivial, dense, sabre, noise_adaptive) plugin
4 participants