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

q1 == q1 but hash(q1) != hash(q2) #3777

Closed
mpharrigan opened this issue Feb 10, 2021 · 2 comments · Fixed by #3791
Closed

q1 == q1 but hash(q1) != hash(q2) #3777

mpharrigan opened this issue Feb 10, 2021 · 2 comments · Fixed by #3791
Labels
kind/bug-report Something doesn't seem to work.

Comments

@mpharrigan
Copy link
Collaborator

I'm having trouble reproducing this, but I'm in a situation where the thing in the title is happening with GridQubit. I've narrowed it down to the fact that the cached cirq.GridQubit._hash values are different and recomputing them with cirq.Qid.__hash__(q1) gives correct, identical hash functions.

My leading theory is that I'm loading a previously-pickled gridqubit, a copy is being made somewhere and the hash is recomputed. The hash value of Qid (the class) is part of the hash input, which could differ over python instantiations

@mpharrigan mpharrigan added the kind/bug-report Something doesn't seem to work. label Feb 10, 2021
@mpharrigan
Copy link
Collaborator Author

@maffoo
Copy link
Contributor

maffoo commented Feb 10, 2021

We should probably make the hash deterministic, e.g.

self._hash = hash(self.row) ^ hash(self.col)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug-report Something doesn't seem to work.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants