8000 Fix ignored errors/durations in `generate_preset_pass_manager` if `dt` is set by ElePT · Pull Request #14065 · Qiskit/qiskit · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fix ignored errors/durations in generate_preset_pass_manager if dt is set #14065

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

Merged
merged 10 commits into from
Mar 25, 2025

Conversation

ElePT
Copy link
Contributor
@ElePT ElePT commented Mar 21, 2025

Summary

#14056 (comment) reported an unexpected behavior of generate_preset_pass_manager where setting a custom dt would invalidate the backend's gate durations and error rates. This was due to an oversight in #9256 , where a custom target would be built from scratch using Target.from_configuration whenever any loose constraint was set, and any information regarding instruction properties would be lost. This was intentional for coupling_map and basis_gates, as they modify the target gate map, but not necessary for dt, where the target could be kept and simply updated.

This PR fixes this use case, adds a test with vf2 + dt, and modifies the user warning to explicitly communicate what will happen with gate durations and errors if coupling_map or basis_gates are set with a backend.

Details and comments

The changelog is None as #9256 has not been released yet.

@ElePT ElePT requested a review from a team as a code owner March 21, 2025 08:31
@qiskit-bot
Copy link
Collaborator

One or more of the following people are relevant to this code:

  • @Qiskit/terra-core

@ElePT ElePT added bug Something isn't working Changelog: None Do not include in changelog stable backport potential The bug might be minimal and/or import enough to be port to stable labels Mar 21, 2025
@ElePT ElePT added this to the 2.0.0 milestone Mar 21, 2025
…er target to reset internal instruction_durations value so that new dt can be taken into account
Copy link
Member
@mtreinish mtreinish left a comment

Choose a reason for hiding this comment

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

Thanks for diving into the details on this and fixing it, I just have a few inline comments.

Comment on lines 2316 to 2320
tqc = transpile(
qc, backend=backend, seed_transpiler=4242, callback=callback, dt=backend.dt * 2
)
self.assertTrue(vf2_post_layout_called)
self.assertEqual([2, 1, 0], _get_index_layout(tqc, qubits))
Copy link
Member

Choose a reason for hiding this comment

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

I think to test this we either should run transpile twice once with a custom dt once with out and assert the layouts are the same providing indication that we've got the same error rates for both runs.

Or alternatively we could probably test this more directly by building a preset pass manager and poking the internals of one of the passes to assert the target has the expected error rates.

Co-authored-by: Matthew Treinish <mtreinish@kortar.org>
@coveralls
Copy link
coveralls commented Mar 21, 2025

Pull Request Test Coverage Report for Build 13995670918

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 18 of 18 (100.0%) changed or added relevant lines in 3 files are covered.
  • 33 unchanged lines in 5 files lost coverage.
  • Overall coverage increased (+0.006%) to 88.087%

Files with Coverage Reduction New Missed Lines %
qiskit/circuit/library/standard_gates/u1.py 3 94.57%
crates/qasm2/src/lex.rs 5 92.23%
crates/qasm2/src/parse.rs 6 97.61%
crates/circuit/src/packed_instruction.rs 8 94.23%
crates/circuit/src/operations.rs 11 91.0%
Totals Coverage Status
Change from base Build 13981819688: 0.006%
Covered Lines: 72636
Relevant Lines: 82459

💛 - Coveralls

@ElePT ElePT added Changelog: Bugfix Include in the "Fixed" section of the changelog and removed bug Something isn't working labels Mar 21, 2025
Copy link
Member
@mtreinish mtreinish left a comment

Choose a reason for hiding this comment

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

Thanks for the update. I'm mildly concerned that the test will be fragile longer term because we're indirectly testing the root cause of the bug here. But at the end of the day I don't think it's likely to cause an issue and the test would catch the regression even if it's indirect.

@mtreinish mtreinish added this pull request to the merge queue Mar 25, 2025
Merged via the queue into Qiskit:main with commit 6ce7788 Mar 25, 2025
21 checks passed
mergify bot pushed a commit that referenced this pull request Mar 25, 2025
…` is set (#14065)

* Fix dt oversight in generate_preset_pass_manager

* Update warning to mention explicitly the invalidation of custom durations and error rates.

* Do not overwrite original backend values inside transpile, iterate over target to reset internal instruction_durations value so that new dt can be taken into account

* One iteration is enough to reset the value of self._instruction_durations

* Estimate duration instead of hardcoding it

* Apply suggestion from Matt's code review

Co-authored-by: Matthew Treinish <mtreinish@kortar.org>

* Fix example

* Move cache invalidation to target dt setter.

* Add reno

---------

Co-authored-by: Matthew Treinish <mtreinish@kortar.org>
(cherry picked from commit 6ce7788)
github-merge-queue bot pushed a commit that referenced this pull request Mar 25, 2025
…` is set (#14065) (#14098)

* Fix dt oversight in generate_preset_pass_manager

* Update warning to mention explicitly the invalidation of custom durations and error rates.

* Do not overwrite original backend values inside transpile, iterate over target to reset internal instruction_durations value so that new dt can be taken into account

* One iteration is enough to reset the value of self._instruction_durations

* Estimate duration instead of hardcoding it

* Apply suggestion from Matt's code review

Co-authored-by: Matthew Treinish <mtreinish@kortar.org>

* Fix example

* Move cache invalidation to target dt setter.

* Add reno

---------

Co-authored-by: Matthew Treinish <mtreinish@kortar.org>
(cherry picked from commit 6ce7788)

Co-authored-by: Elena Peña Tapia <57907331+ElePT@users.noreply.github.com>
@raynelfss raynelfss mentioned this pull request Mar 28, 2025
4 tasks
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 Changelog: None Do not include in 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
0