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

TypeError: unhashable type: 'State' #3

Open
sasforce opened this issue Mar 23, 2018 · 7 comments
Open

TypeError: unhashable type: 'State' #3

sasforce opened this issue Mar 23, 2018 · 7 comments

Comments

@sasforce
Copy link

Dear Mr/Miss:
I have implemented your code, and something wrong happened:
TypeError: unhashable type: 'State'
Could you please tell me how does this happen and how can I fix it?
Thank you.
Sincerely Luo

@tobegit3hub
Copy link
Owner

Thanks for your response.

Can you show which script causes this error? How can we re-produce this problem? @sasforce

@guanzeying
Copy link

I have the same problem. my os: win7+python3.6, no cuda.

@YOUNG34
Copy link

YOUNG34 commented Jun 3, 2018

Dear Mr/Miss:

I have the same problem, the inform shown in the terminal is as follows:

Play round: 1
Traceback (most recent call last):
File "mcst_example.py", line 296, in
main()
File "mcst_example.py", line 291, in main
current_node = monte_carlo_tree_search(current_node)
File "mcst_example.py", line 267, in monte_carlo_tree_search
expand_node = tree_policy(node)
File "mcst_example.py", line 153, in tree_policy
sub_node = expand(node)
File "mcst_example.py", line 192, in expand
while new_state in tried_sub_node_states:
File "mcst_example.py", line 67, in eq
if hash(self) == hash(other):
TypeError: unhashable type: 'State'

@YOUNG34
Copy link

YOUNG34 commented Jun 3, 2018

Well, after I deleted the "def eq(self, other):" function at 66th line, and the "def repr(self):" at 72th line, this code worked.

@tobegit3hub
Copy link
Owner

Thanks for your response @guanzeying @YOUNG34 .
It would be the issue of compatibility of Python 2.7 and Python 3.0. I will have a look later or just remove the incompatible code.

@YOUNG34
Copy link

YOUNG34 commented Jun 4, 2018 via email

@charleschen6
Copy link

charleschen6 commented Dec 31, 2019

#6 (comment)
add below codes will correct the error.

class State(object):
  .....
  def __eq__(self, other):
    if isinstance(other, self.__class__):
      return (self.current_value, self.current_round_index, self.cumulative_choices) == \
             (other.current_value, other.current_round_index, other.cumulative_choices)
    else:
      return False

  def __hash__(self):
    return hash('{},{},{}'.format(self.current_value, self.current_round_index, self.cumulative_choices))

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

No branches or pull requests

5 participants