-
Notifications
You must be signed in to change notification settings - Fork 17
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
Add a CommTag class with a stable hash #319
Changes from 4 commits
a3745bd
44d0696
f45e5cd
35183b2
9b2ced4
9a63df4
6918c63
e7f9239
e815ab4
82e1933
6c4b64d
758d48d
9454067
8d5ce27
aa966ac
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
------------------------------------------- | ||
|
||
.. autoclass:: TracePair | ||
.. autoclass:: CommTag | ||
|
||
.. currentmodule:: grudge.op | ||
|
||
|
@@ -70,7 +71,7 @@ | |
|
||
from numbers import Number | ||
|
||
from pytools import memoize_on_first_arg | ||
from pytools import memoize_on_first_arg, memoize_method | ||
|
||
from grudge.discretization import DiscretizationCollection | ||
from grudge.projection import project | ||
|
@@ -318,8 +319,20 @@ def interior_trace_pair(dcoll: DiscretizationCollection, vec) -> TracePair: | |
return local_interior_trace_pair(dcoll, vec) | ||
|
||
|
||
@dataclass(frozen=True) # for KeyBuilder support | ||
class CommTag: | ||
"""A communication tag with a hash value that is stable across | ||
runs, even without setting ``PYTHONHASHSEED``.""" | ||
@memoize_method | ||
def __hash__(self): | ||
return hash(tuple(str(type(self)).encode("ascii"))) | ||
|
||
def __eq__(self, other): | ||
return isinstance(other, type(self)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is incorrect: It accepts arbitrary subclasses for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is (hopefully) fixed in 6918c63 |
||
|
||
|
||
def interior_trace_pairs(dcoll: DiscretizationCollection, vec, *, | ||
comm_tag: Hashable = None, tag: Hashable = None, | ||
comm_tag: CommTag = None, tag: Hashable = None, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't agree with this change. There's no good reason why other There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I undid this change in 9b2ced4. I left the warning in https://github.com/inducer/grudge/pull/319/files#diff-5fa6e6b713d37028c16f1bbc5a6d0b4547ecba0f86c8a52eb30e1ba1dc2614e4R518 in place for now, would you like me to remove it? Edit: |
||
volume_dd: Optional[DOFDesc] = None) -> List[TracePair]: | ||
r"""Return a :class:`list` of :class:`TracePair` objects | ||
defined on the interior faces of *dcoll* and any faces connected to a | ||
|
@@ -331,10 +344,11 @@ def interior_trace_pairs(dcoll: DiscretizationCollection, vec, *, | |
|
||
:arg vec: a :class:`~meshmode.dof_array.DOFArray` or an | ||
:class:`~arraycontext.ArrayContainer` of them. | ||
:arg comm_tag: a hashable object used to match sent and received data | ||
across ranks. Communication will only match if both endpoints specify | ||
objects that compare equal. A generalization of MPI communication | ||
tags to arbitary, potentially composite objects. | ||
:arg comm_tag: a :class:`~grudge.trace_pair.CommTag` used to match | ||
sent and received data across ranks. Communication will only match | ||
if both endpoints specify objects that compare equal. A | ||
generalization of MPI communication tags to arbitrary, potentially | ||
composite objects. | ||
:returns: a :class:`list` of :class:`TracePair` objects. | ||
""" | ||
|
||
|
@@ -379,7 +393,7 @@ def connected_ranks( | |
dcoll._volume_discrs[volume_dd.domain_tag.tag].mesh) | ||
|
||
|
||
def _sym_tag_to_num_tag(comm_tag: Optional[Hashable]) -> Optional[int]: | ||
def _sym_tag_to_num_tag(comm_tag: Optional[CommTag]) -> Optional[int]: | ||
if comm_tag is None: | ||
return comm_tag | ||
|
||
|
@@ -498,10 +512,14 @@ class _RankBoundaryCommunicationLazy: | |
def __init__(self, | ||
dcoll: DiscretizationCollection, | ||
array_container: ArrayOrContainer, | ||
remote_rank: int, comm_tag: Hashable, | ||
remote_rank: int, comm_tag: Optional[CommTag], | ||
volume_dd=DD_VOLUME_ALL): | ||
if comm_tag is None: | ||
raise ValueError("lazy communication requires 'tag' to be supplied") | ||
raise ValueError("lazy communication requires 'comm_tag' to be supplied") | ||
|
||
if not isinstance(comm_tag, CommTag): | ||
from warnings import warn | ||
warn(f"comm_tag {comm_tag} should be an instance of CommTag") | ||
|
||
bdry_dd = volume_dd.trace(BTAG_PARTITION(remote_rank)) | ||
|
||
|
@@ -544,7 +562,7 @@ def finish(self): | |
def cross_rank_trace_pairs( | ||
dcoll: DiscretizationCollection, ary: ArrayOrContainer, | ||
tag: Hashable = None, | ||
*, comm_tag: Hashable = None, | ||
*, comm_tag: CommTag = None, | ||
volume_dd: Optional[DOFDesc] = None) -> List[TracePair]: | ||
r"""Get a :class:`list` of *ary* trace pairs for each partition boundary. | ||
|
||
|
@@ -570,7 +588,7 @@ def cross_rank_trace_pairs( | |
:arg comm_tag: a hashable object used to match sent and received data | ||
across ranks. Communication will only match if both endpoints specify | ||
objects that compare equal. A generalization of MPI communication | ||
tags to arbitary, potentially composite objects. | ||
tags to arbitrary, potentially composite objects. | ||
|
||
:returns: a :class:`list` of :class:`TracePair` objects. | ||
""" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't really make sense for all
CommTag
s to be subclasses of this. Some may have data contained in them.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a small test in 9a63df4 with subclassed dataclasses, is that what you had in mind?
Edit: I may have misunderstood your comment; I removed dataclasses in 6918c63. Currently, all (hashable) classes are accepted, not just CommTag subclasses.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should stick to arbitrary-data-with-certain-requirements as tags. I mostly don't want to restrict to just subclasses of something specific.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, would you like to keep the
CommTag
class as an optional way to construct the comm tags? I removed the warning in 9454067.