ml_implementation icon indicating copy to clipboard operation
ml_implementation copied to clipboard

TypeError: unhashable type: 'State'

Open sasforce opened this issue 7 years ago • 7 comments

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

sasforce avatar Mar 23 '18 07:03 sasforce

Thanks for your response.

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

tobegit3hub avatar Mar 24 '18 14:03 tobegit3hub

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

guanzeying avatar Apr 08 '18 13:04 guanzeying

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 avatar Jun 03 '18 12:06 YOUNG34

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

YOUNG34 avatar Jun 03 '18 13:06 YOUNG34

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.

tobegit3hub avatar Jun 04 '18 01:06 tobegit3hub

Just removing the "eq" function is enough, I made a stupid mistake to remove the "repr" function yesterday.

Have a nice day. ?? Outlook for Androidhttps://aka.ms/ghei36


From: tobe [email protected] Sent: Monday, June 4, 2018 2:35:10 AM To: tobegit3hub/ml_implementation Cc: Yang, Ze; Mention Subject: Re: [tobegit3hub/ml_implementation] TypeError: unhashable type: 'State' (#3)

Thanks for your response @guanzeyinghttps://emea01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fguanzeying&data=01%7C01%7Cze.yang%40kcl.ac.uk%7Cf0449a27c71a46a5522b08d5c9bb69ee%7C8370cf1416f34c16b83c724071654356%7C0&sdata=Kr3XG%2FgoAg1%2BBQyR4mdVT6iLhwTXudtXXnLlH0nTcos%3D&reserved=0 @YOUNG34https://emea01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2FYOUNG34&data=01%7C01%7Cze.yang%40kcl.ac.uk%7Cf0449a27c71a46a5522b08d5c9bb69ee%7C8370cf1416f34c16b83c724071654356%7C0&sdata=eEj%2F65xB00K7QZPrqgtE7eL2Z08UtMauYhTe73cmcs0%3D&reserved=0 . 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.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://emea01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Ftobegit3hub%2Fml_implementation%2Fissues%2F3%23issuecomment-394211894&data=01%7C01%7Cze.yang%40kcl.ac.uk%7Cf0449a27c71a46a5522b08d5c9bb69ee%7C8370cf1416f34c16b83c724071654356%7C0&sdata=WbnayGT%2FzTziAM98yZQMMsTNOLX17t7aZj9%2FQw0VAC8%3D&reserved=0, or mute the threadhttps://emea01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAfIEo1iEhwXEkpepVQc4EryLqRC9Q6Oeks5t5I7OgaJpZM4S4TYm&data=01%7C01%7Cze.yang%40kcl.ac.uk%7Cf0449a27c71a46a5522b08d5c9bb69ee%7C8370cf1416f34c16b83c724071654356%7C0&sdata=De4B0EMEpTEL68ik0m5Ofu%2BsBpBm9RRfGagnlhSLcFU%3D&reserved=0.

YOUNG34 avatar Jun 04 '18 23:06 YOUNG34

https://github.com/tobegit3hub/ml_implementation/issues/6#issue-544077431 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))

charleschen6 avatar Dec 31 '19 08:12 charleschen6