17zuoye / pyirt

A python library of IRT algorithm
MIT License
99 stars 54 forks source link

Switch from multiprocessing to multiprocess #25

Open Sessa93 opened 2 years ago

Sessa93 commented 2 years ago

Starting from python 3.8 the library, and tests seems to fail with the following error:

Traceback` (most recent call last):
  File "/Users/andrea/repos/pyirt/tests/test_model_wrapper.py", line 39, in test_2pl_solver
    item_param, user_param = irt(self.data,
  File "/Users/andrea/repos/pyirt/pyirt/_pyirt.py", line 46, in irt
    mod.solve_EM()
  File "/Users/andrea/repos/pyirt/pyirt/solver/model.py", line 102, in solve_EM
    self._exp_step()
  File "/Users/andrea/repos/pyirt/pyirt/solver/model.py", line 157, in _exp_step
    self.__update_theta_distr()
  File "/Users/andrea/repos/pyirt/pyirt/solver/model.py", line 342, in __update_theta_distr
    procs = procs_operator(procs, 3600 * 24, 0.1)
  File "/Users/andrea/repos/pyirt/pyirt/solver/model.py", line 28, in procs_operator
    p.start()
  File "/Users/andrea/.pyenv/versions/3.8.13/lib/python3.8/multiprocessing/process.py", line 121, in start
    self._popen = self._Popen(self)
  File "/Users/andrea/.pyenv/versions/3.8.13/lib/python3.8/multiprocessing/context.py", line 224, in _Popen
    return _default_context.get_context().Process._Popen(process_obj)
  File "/Users/andrea/.pyenv/versions/3.8.13/lib/python3.8/multiprocessing/context.py", line 284, in _Popen
    return Popen(process_obj)
  File "/Users/andrea/.pyenv/versions/3.8.13/lib/python3.8/multiprocessing/popen_spawn_posix.py", line 32, in __init__
    super().__init__(process_obj)
  File "/Users/andrea/.pyenv/versions/3.8.13/lib/python3.8/multiprocessing/popen_fork.py", line 19, in __init__
    self._launch(process_obj)
  File "/Users/andrea/.pyenv/versions/3.8.13/lib/python3.8/multiprocessing/popen_spawn_posix.py", line 47, in _launch
    reduction.dump(process_obj, fp)
  File "/Users/andrea/.pyenv/versions/3.8.13/lib/python3.8/multiprocessing/reduction.py", line 60, in dump
    ForkingPickler(file, protocol).dump(obj)
AttributeError: Can't pickle local object 'IRT_MMLE_2PL.__update_theta_distr.<locals>.update'

The idea is to switch from multiprocessing to multiprocess which uses dill in place of pickle for object pickling