Skip to content

Conversation

@mergify
Copy link
Contributor

@mergify mergify bot commented Dec 3, 2025

Summary

This commit switches the use of par_sort_by_unstable() to the serial sort_by_unstable() implementation in the disjoint layout module. While the parallel sort is faster and has some heuristics to limit the multithreaded usage when the overhead isn't worth the tradeoff, the use of multithreading from Python is potentially fraught when mixing with multiprocessing in Python. For this reason all of our multithreaded calls are supposed to guard against running in parallel based on env vars that indicate the rust code is being executed in a multiprocessing context. However the parallel sorts were missing this check and in this case the overhead of checking we can run in multiple threads will likely outweigh any speedup from a parallel sort. So this commit just opts to drop the parallel sort and avoid the potential complications.

Details and comments


This is an automatic backport of pull request #15410 done by [Mergify](https://mergify.com).

This commit switches the use of `par_sort_by_unstable()` to the serial
`sort_by_unstable()` implementation in the disjoint layout module. While
the parallel sort is faster and has some heuristics to limit the
multithreaded usage when the overhead isn't worth the tradeoff, the use
of multithreading from Python is potentially fraught when mixing with
multiprocessing in Python. For this reason all of our multithreaded
calls are supposed to guard against running in parallel based on env
vars that indicate the rust code is being executed in a multiprocessing
context. However the parallel sorts were missing this check and in this
case the overhead of checking we can run in multiple threads will likely
outweigh any speedup from a parallel sort. So this commit just opts to
drop the parallel sort and avoid the potential complications.

(cherry picked from commit cae0817)

# Conflicts:
#	crates/transpiler/src/passes/disjoint_layout.rs
@mergify mergify bot added the conflicts used by mergify when there are conflicts in a port label Dec 3, 2025
@mergify mergify bot requested a review from a team as a code owner December 3, 2025 00:03
@mergify
Copy link
Contributor Author

mergify bot commented Dec 3, 2025

Cherry-pick of cae0817 has failed:

On branch mergify/bp/stable/2.2/pr-15410
Your branch is up to date with 'origin/stable/2.2'.

You are currently cherry-picking commit cae0817b7.
  (fix conflicts and run "git cherry-pick --continue")
  (use "git cherry-pick --skip" to skip this patch)
  (use "git cherry-pick --abort" to cancel the cherry-pick operation)

Changes to be committed:
	new file:   releasenotes/notes/fix_multiprocessing_with_multithreading_bug-948c7ade10f66c60.yaml

Unmerged paths:
  (use "git add <file>..." to mark resolution)
	both modified:   crates/transpiler/src/passes/disjoint_layout.rs

To fix up this pull request, you can check it out locally. See documentation: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/checking-out-pull-requests-locally

@mergify mergify bot added the conflicts used by mergify when there are conflicts in a port label Dec 3, 2025
@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

@github-actions github-actions bot added Changelog: Bugfix Include in the "Fixed" section of the changelog Rust This PR or issue is related to Rust code in the repository labels Dec 3, 2025
@github-actions github-actions bot added this to the 2.2.4 milestone Dec 3, 2025
@coveralls
Copy link

Pull Request Test Coverage Report for Build 19878305745

Details

  • 2 of 2 (100.0%) changed or added relevant lines in 1 file are covered.
  • 13 unchanged lines in 4 files lost coverage.
  • Overall coverage increased (+0.02%) to 88.441%

Files with Coverage Reduction New Missed Lines %
crates/qasm2/src/expr.rs 1 93.63%
crates/circuit/src/parameter/symbol_expr.rs 2 73.19%
crates/qasm2/src/lex.rs 4 92.27%
crates/qasm2/src/parse.rs 6 97.56%
Totals Coverage Status
Change from base Build 19577979235: 0.02%
Covered Lines: 92414
Relevant Lines: 104492

💛 - Coveralls

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 conflicts used by mergify when there are conflicts in a port 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.

3 participants