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 Channel.__hash__ in multiprocessing contexts (backport #11251) #11255

Merged
merged 1 commit into from
Nov 16, 2023

Conversation

mergify[bot]
Copy link
Contributor

@mergify mergify bot commented Nov 15, 2023

This is an automatic backport of pull request #11251 done by Mergify.
Cherry-pick of 3c1a87c has failed:

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

You are currently cherry-picking commit 3c1a87c48.
  (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:
	modified:   qiskit/pulse/channels.py
	modified:   qiskit/pulse/instructions/instruction.py
	new file:   releasenotes/notes/fix-pulse-channel-hash-549a8fb5d8738c4d.yaml

Unmerged paths:
  (use "git add/rm <file>..." as appropriate to mark resolution)
	deleted by us:   qiskit/pulse/model/frames.py
	deleted by us:   qiskit/pulse/model/mixed_frames.py
	deleted by us:   qiskit/pulse/model/pulse_target.py

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


Mergify commands and options

More conditions and actions can be found in the documentation.

You can also trigger Mergify actions by commenting on this pull request:

  • @Mergifyio refresh will re-evaluate the rules
  • @Mergifyio rebase will rebase this PR on its base branch
  • @Mergifyio update will merge the base branch into this PR
  • @Mergifyio backport <destination> will backport this PR on <destination> branch

Additionally, on Mergify dashboard you can:

  • look at your merge queues
  • generate the Mergify configuration with the config editor.

Finally, you can contact us on https://mergify.com

@mergify mergify bot requested review from eggerdj, wshanks and a team as code owners November 15, 2023 21:35
@mergify mergify bot added the conflicts used by mergify when there are conflicts in a port label Nov 15, 2023
@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
  • @nkanazawa1989

@github-actions github-actions bot added Changelog: Bugfix Include in the "Fixed" section of the changelog mod: pulse Related to the Pulse module labels Nov 15, 2023
@coveralls
Copy link

coveralls commented Nov 15, 2023

Pull Request Test Coverage Report for Build 6888643838

  • 2 of 2 (100.0%) changed or added relevant lines in 2 files are covered.
  • 15 unchanged lines in 2 files lost coverage.
  • Overall coverage increased (+0.001%) to 86.951%

Files with Coverage Reduction New Missed Lines %
crates/qasm2/src/lex.rs 3 91.67%
crates/qasm2/src/parse.rs 12 96.67%
Totals Coverage Status
Change from base Build 6881567138: 0.001%
Covered Lines: 74207
Relevant Lines: 85343

💛 - Coveralls

* Fix `Channel.__hash__` in multiprocessing contexts

Storing an explicit hash key is fragile in cases that a channel might be
created in a different process to where it might be compared or the hash
used, because the hash seeding can vary depending on how the new
interpreter process was created, especially if it's not done by `fork`.

In this case, transmitting the stored `_hash` over pickle meant that a
`DriveChannel(0)` created in the main process of a macOS runner could
compare equal to a `DriveChannel(0)` created in a separate process
(standard start method `spawn`) and pickled over the wire to the main
process, but have different hashes, violating the Python data model.

Instead, we can just use the standard Python behaviour of creating the
hash on demand when requested; this should typically be preferred unless
absolutely necessary for critical performance reasons, because it will
generally fail safe.

* Fix `hash` and equality in other pulse objects

This removes all caching of items' `hash`es.  This practice is quite
fraught in multiprocessing contexts, and should only be done when it is
absolutely performance critical.

In a couple of cases, the pulse objects were using the cached `hash` as
the main component of their `__eq__` methods, which is not correct; it's
totally valid to have hash collisions without implying that two objects
are equal.

(cherry picked from commit 3c1a87c)
@jakelishman jakelishman force-pushed the mergify/bp/stable/0.45/pr-11251 branch from 3747119 to 4938b50 Compare November 16, 2023 09:15
@jakelishman jakelishman removed the conflicts used by mergify when there are conflicts in a port label Nov 16, 2023
@jakelishman jakelishman added this to the 0.45.1 milestone Nov 16, 2023
@jakelishman jakelishman added this pull request to the merge queue Nov 16, 2023
Merged via the queue into stable/0.45 with commit ff85be7 Nov 16, 2023
15 checks passed
@mergify mergify bot deleted the mergify/bp/stable/0.45/pr-11251 branch November 16, 2023 11:49
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 mod: pulse Related to the Pulse module
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants