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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions qiskit/pulse/channels.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ def __init__(self, index: int):
"""
self._validate_index(index)
self._index = index
self._hash = hash((self.__class__.__name__, self._index))

@property
def index(self) -> Union[int, ParameterExpression]:
Expand Down Expand Up @@ -156,7 +155,7 @@ def __eq__(self, other: "Channel") -> bool:
return type(self) is type(other) and self._index == other._index

def __hash__(self):
return self._hash
return hash((type(self), self._index))


class PulseChannel(Channel, metaclass=ABCMeta):
Expand Down
5 changes: 1 addition & 4 deletions qiskit/pulse/instructions/instruction.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ def __init__(
"""
self._operands = operands
self._name = name
self._hash = None
self._validate()

def _validate(self):
Expand Down Expand Up @@ -301,9 +300,7 @@ def __eq__(self, other: "Instruction") -> bool:
return isinstance(other, type(self)) and self.operands == other.operands

def __hash__(self) -> int:
if self._hash is None:
self._hash = hash((type(self), self.operands, self.name))
return self._hash
return hash((type(self), self.operands, self.name))

def __add__(self, other):
"""Return a new schedule with `other` inserted within `self` at `start_time`.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
fixes:
- |
Fixed the :func:`hash` of Qiskit Pulse ``Channel`` objects (such as :class:`.DriveChannel`) in
cases where the channel was transferred from one Python process to another that used a different
hash seed.