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

Expose Sabre heuristic configuration to Python (backport #12171) #12856

Merged
merged 1 commit into from
Jul 30, 2024

Conversation

mergify[bot]
Copy link
Contributor

@mergify mergify bot commented Jul 30, 2024

Summary

This exposes the entirety of the configuration of the Sabre heuristic to Python space, making it modifiable without recompilation. This includes some additional configuration options that were not previously easily modifiable, even with recompilation:

  • the base weight of the "basic" component can be adjusted
  • the weight of the "basic" and "lookahead" components can be adjusted to either use a constant weight (previously not a thing) or use a weight that scales with the size of the set (previously the only option).
  • the "decay" component is now entirely separated from the "lookahead" component, so in theory you can now have a decay without a lookahead.

This introduces a tracking Vec that stores the scores of all the swaps encountered, rather than just dynamically keeping hold of the best swaps. This has a couple of benefits:

  • with the new dynamic structure for heuristics, this is rather more efficient because each heuristic component can be calculated in separate loops over the swaps, and we don't have to branch within the innermost loop.
  • it makes it possible in the future to try things like assigning probabilities to each swap and randomly choosing from all of them, not just the best swaps. This is something I've actively wanted to try for quite some time.

The default heuristics in the transpiler-pass creators for the basic, lookahead and decay strings are set to represent the same heuristics as before, and this commit is entirely RNG compatible with its predecessor (technically for huge problems there's a possiblity that pulling out some divisions into multiplications by reciprocals will affect the floating-point maths enough to modify the swap selection).

Details and comments

I need to run more formal benchmarks on this to verify the claims in the commit message - it's possible I didn't do it sufficiently well earlier, and at any rate I no longer have the data to hand. (edit: come to think of it, I'm not even sure I ran the tests...)

I so far have not documented the newly available API stuff from Rust-space here, because I didn't necessarily want to commit to it as public interface, but did want to make it available for research - certainly I found this very useful in investigating Sabre, even if I haven't had time to turn that research into a full set of tweaked heuristics yet or anything. Happy to discuss whether we should commit to this as public API - there's probably not too much risk.


This is an automatic backport of pull request #12171 done by Mergify.

* Expose Sabre heuristic configuration to Python

This exposes the entirety of the configuration of the Sabre heuristic to
Python space, making it modifiable without recompilation.  This includes
some additional configuration options that were not previously easily
modifiable, even with recompilation:

- the base weight of the "basic" component can be adjusted
- the weight of the "basic" and "lookahead" components can be adjusted
  to _either_ use a constant weight (previously not a thing) or use a
  weight that scales with the size of the set (previously the only
  option).
- the "decay" component is now entirely separated from the "lookahead"
  component, so in theory you can now have a decay without a lookahead.

This introduces a tracking `Vec` that stores the scores of _all_ the
swaps encountered, rather than just dynamically keeping hold of the best
swaps.  This has a couple of benefits:

- with the new dynamic structure for heuristics, this is rather more
  efficient because each heuristic component can be calculated in
  separate loops over the swaps, and we don't have to branch within the
  innermost loop.
- it makes it possible in the future to try things like assigning
  probabilities to each swap and randomly choosing from _all_ of them,
  not just the best swaps.  This is something I've actively wanted to
  try for quite some time.

The default heuristics in the transpiler-pass creators for the `basic`,
`lookahead` and `decay` strings are set to represent the same heuristics
as before, and this commit is entirely RNG compatible with its
predecessor (_technically_ for huge problems there's a possiblity that
pulling out some divisions into multiplications by reciprocals will
affect the floating-point maths enough to modify the swap selection).

* Update for PyO3 0.21

* Increase documentation of heuristic components

(cherry picked from commit 43d8372)
@mergify mergify bot requested a review from a team as a code owner July 30, 2024 15:26
@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 following people are relevant to this code:

  • @Qiskit/terra-core
  • @kevinhartman
  • @mtreinish

@github-actions github-actions bot added Rust This PR or issue is related to Rust code in the repository mod: transpiler Issues and PRs related to Transpiler labels Jul 30, 2024
@github-actions github-actions bot added this to the 1.2.0 milestone Jul 30, 2024
@ElePT ElePT enabled auto-merge July 30, 2024 15:29
@coveralls
Copy link

Pull Request Test Coverage Report for Build 10165244742

Details

  • 135 of 240 (56.25%) changed or added relevant lines in 7 files are covered.
  • 4 unchanged lines in 1 file lost coverage.
  • Overall coverage decreased (-0.1%) to 89.848%

Changes Missing Coverage Covered Lines Changed/Added Lines %
qiskit/transpiler/passes/routing/sabre_swap.py 6 7 85.71%
crates/accelerate/src/sabre/route.rs 70 74 94.59%
crates/accelerate/src/sabre/heuristic.rs 43 143 30.07%
Files with Coverage Reduction New Missed Lines %
crates/qasm2/src/lex.rs 4 92.62%
Totals Coverage Status
Change from base Build 10164847368: -0.1%
Covered Lines: 66404
Relevant Lines: 73907

💛 - Coveralls

@ElePT ElePT added this pull request to the merge queue Jul 30, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to no response for status checks Jul 30, 2024
@jakelishman jakelishman added this pull request to the merge queue Jul 30, 2024
Merged via the queue into stable/1.2 with commit 927d592 Jul 30, 2024
18 checks passed
@mergify mergify bot deleted the mergify/bp/stable/1.2/pr-12171 branch July 30, 2024 18:58
@ElePT ElePT added the Changelog: None Do not include in changelog label Jul 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelog: None Do not include in changelog mod: transpiler Issues and PRs related to Transpiler Rust This PR or issue is related to Rust code in the repository
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants