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

Fix instruction durations in transpile() with BackendV2 #8001

Merged
merged 4 commits into from
May 2, 2022

Conversation

mtreinish
Copy link
Member

Summary

When running transpile() with BackendV2 based backends the instruction
durations property from the backend would not be processed correctly
resulting in the absence of the default durations for instructions
supported on the target backend. This commit fixes this by correctly
handling BackendV2 based backends and using those instruction durations
by default for transpile().

Details and comments

When running transpile() with BackendV2 based backends the instruction
durations property from the backend would not be processed correctly
resulting in the absence of the default durations for instructions
supported on the target backend. This commit fixes this by correctly
handling BackendV2 based backends and using those instruction durations
by default for transpile().
@mtreinish mtreinish added stable backport potential The bug might be minimal and/or import enough to be port to stable Changelog: Bugfix Include in the "Fixed" section of the changelog labels Apr 29, 2022
@mtreinish mtreinish added this to the 0.20.2 milestone Apr 29, 2022
@mtreinish mtreinish requested a review from kevinhartman April 29, 2022 21:31
@mtreinish mtreinish requested a review from a team as a code owner April 29, 2022 21:31
@qiskit-bot
Copy link
Collaborator

Thank you for opening a new pull request.

Before your PR can be merged it will first need to pass continuous integration tests and be reviewed. Sometimes the review process can be slow, so please be patient.

While you're waiting, please feel free to review other open PRs. While only a subset of people are authorized to approve pull requests for merging, everyone is encouraged to review open pull requests. Doing reviews helps reduce the burden on the core team and helps make the project's code better for everyone.

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

  • @Qiskit/terra-core

kevinhartman
kevinhartman previously approved these changes Apr 29, 2022
Copy link
Contributor

@kevinhartman kevinhartman left a comment

Choose a reason for hiding this comment

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

LGTM

test/python/compiler/test_transpiler.py Outdated Show resolved Hide resolved
@coveralls
Copy link

coveralls commented Apr 29, 2022

Pull Request Test Coverage Report for Build 2258271688

  • 8 of 8 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.004%) to 84.327%

Totals Coverage Status
Change from base Build 2257981816: 0.004%
Covered Lines: 54523
Relevant Lines: 64657

💛 - Coveralls

except AttributeError:
pass
backend_version = getattr(backend, "version", 0)
if backend_version <= 1:
Copy link
Collaborator

Choose a reason for hiding this comment

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

We have added a lot of these in different places. I wonder if there is a better way to handle the versions better than if-else statements. I imagine it would be very tedious to update these code (and may miss some) when we have a newer version of backend.

Copy link
Member Author

Choose a reason for hiding this comment

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

The way the transpile function is structured right now there isn't really a better way to handle this. I think in the near term I'm going to look at rewriting how we pass backend information to the pass managers here and use a Target as the single object we pass to the pass manager constructor. As I agree this code is super hard to deal with (not just for this reason, but also because it makes things like #7789 hard too) and very error prone.

@mergify mergify bot merged commit 49f39e3 into Qiskit:main May 2, 2022
mergify bot pushed a commit that referenced this pull request May 2, 2022
* Fix instruction durations in transpile() with BackendV2

When running transpile() with BackendV2 based backends the instruction
durations property from the backend would not be processed correctly
resulting in the absence of the default durations for instructions
supported on the target backend. This commit fixes this by correctly
handling BackendV2 based backends and using those instruction durations
by default for transpile().

* Update test/python/compiler/test_transpiler.py

Co-authored-by: Kevin Hartman <[email protected]>

Co-authored-by: Kevin Hartman <[email protected]>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
(cherry picked from commit 49f39e3)
@mtreinish mtreinish deleted the fix-inst-dur-v2-transpile branch May 2, 2022 15:24
mergify bot added a commit that referenced this pull request May 4, 2022
…) (#8010)

* Fix instruction durations in transpile() with BackendV2 (#8001)

* Fix instruction durations in transpile() with BackendV2

When running transpile() with BackendV2 based backends the instruction
durations property from the backend would not be processed correctly
resulting in the absence of the default durations for instructions
supported on the target backend. This commit fixes this by correctly
handling BackendV2 based backends and using those instruction durations
by default for transpile().

* Update test/python/compiler/test_transpiler.py

Co-authored-by: Kevin Hartman <[email protected]>

Co-authored-by: Kevin Hartman <[email protected]>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
(cherry picked from commit 49f39e3)

* Handle still-supported BaseBackend for 0.20

* Fix handling of legacy base backend version

Co-authored-by: Matthew Treinish <[email protected]>
Co-authored-by: Jake Lishman <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelog: Bugfix Include in the "Fixed" section of the changelog stable backport potential The bug might be minimal and/or import enough to be port to stable
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants