AB-CE / abce

Agent-based computational Economics, the Python library that makes AB modelling easier
http://abce.readthedocs.io
181 stars 62 forks source link

Problem with hashing #171

Open Sirorezka opened 5 years ago

Sirorezka commented 5 years ago

New version of 'hash' in python give different values during execution of each thread when doing multiprocessing. Following error will accure:

50000_firms/start.py return error when running in 2 or more processess: KeyError: ('myagent', 11980)

There is problem with three functions which use 'hash': multiprocessing.py -- def insert_or_append multiprocessing.py -- def do agent.py -- def _send_multiprocessing

my proposal - replace default hash function with:

import hashlib
def new_hash(agent_key):
    return int(hashlib.md5(str(agent_key).encode()).hexdigest()[:8],16)
rht commented 5 years ago

Would the variable address of the string become unambiguous across processes with id(agent_name)? Perhaps a different hashing scheme is used when multiprocessing is on.