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

Add a CommTag class with a stable hash #319

Draft
wants to merge 15 commits into
base: main
Choose a base branch
from
Draft

Add a CommTag class with a stable hash #319

wants to merge 15 commits into from

Conversation

matthiasdiener
Copy link
Collaborator

@matthiasdiener matthiasdiener commented Sep 13, 2023

TODO:

  • add tests

@matthiasdiener matthiasdiener self-assigned this Sep 13, 2023
@matthiasdiener
Copy link
Collaborator Author

This is still a draft, but it's ready for a first look @inducer @majosm

def interior_trace_pairs(dcoll: DiscretizationCollection, vec, *,
comm_tag: Hashable = None, tag: Hashable = None,
comm_tag: CommTag = None, tag: Hashable = None,
Copy link
Owner

Choose a reason for hiding this comment

The 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 Hashables should not be accepted.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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:
Removed in 9454067

@@ -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:
Copy link
Owner

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 CommTags to be subclasses of this. Some may have data contained in them.

Copy link
Collaborator Author

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.

Copy link
Owner

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.

Copy link
Collaborator Author

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.

return hash(tuple(str(type(self)).encode("ascii")))

def __eq__(self, other):
return isinstance(other, type(self))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is incorrect: It accepts arbitrary subclasses for other, and violates the property of "__eq__ implies hash equality."

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is (hopefully) fixed in 6918c63

- don't use dataclass anymore, implement update_persistent_hash
- test _sym_tag_to_num_tag
- (hopefully) fix __eq__
@matthiasdiener matthiasdiener mentioned this pull request Nov 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants