-
Notifications
You must be signed in to change notification settings - Fork 34
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
mocpy probability calculation when using multiprocessing #132
Comments
Ah yes. Sorry it's a duplicate of #102. We have a vague idea about how to solve this. I'll have a try in the next days. Thanks for reporting |
Yes, this is why we put in place a |
@mcoughlin |
from mocpy import MOC
from pathos.multiprocessing import ProcessPool
pool = ProcessPool()
results = pool.map(lambda moc: MOC.from_string("0/0"), [j for j in range(32)], chunksize=16) |
Thanks! Looks like multiprocessing calls pickle behind the scene, the bug is narrowed down in issue #133 (traceback for the snippet above)
|
If we add a deep copy, this example now raises: |
@mcoughlin we merged a fix to the pickle issue. It works well with your minimal example with the multiprocessing library too. If you confirm that your more complex use case is also solved, we'll do a release. Thanks again for reporting the issue |
@ManonMarchand I now see: Exception ignored in: <function AbstractMOC.del at 0x308c39e40> |
@ManonMarchand I actually see both: Exception ignored in: <function AbstractMOC.del at 0x308839e40> |
Ok thanks. Still looking then ^^' |
@ManonMarchand Any chance we can do a release before this is completely solved? I see that pypi won't let me do a release just pinning main:
|
@mcoughlin |
@fxpineau multi-threading at the Rust level sounds exactly like the right thing to do. Right now I have been trying to thread also at the MOC creation level, it would also be really cool to be able to pass a bunch of polygons and get a bunch of MOCs back. |
We are giving a try in branch 'par'... |
@fxpineau awesome. For example, that will be a drop-in replacement for the code here: https://github.com/skyportal/gwemopt/blob/main/gwemopt/tiles.py#L1107 |
Hi! So, for future reference, we discovered that the multiprocessing module of python actually spawns new python instances in which the calculations are done. In terms of what happens on the rust side, it also means that different rust instances coexist. Our former way of pickling MOCs was to pickle the index of the MOC (which is a pointer). As such, the python side only manipulates an int while the rust part manages the real in-memory MOCs). This approach could not work when different instances of python/rust had to communicate between each other : the int in the python side does not represent a moc and it was the only thing that could be exchanged through pickle. So we made the choice to store the json serialization of the MOCs in the pickles. This means that now two independent instances of rust/python can communicate through pickles. It also means that we send big objects instead of just an int. Hence our doubts about performances. We also were blocked by a garbage collector issue. When executing your minimal reproducible example, the list of mocs in the This change of the pickle behavior is already merged in master. |
Well, Python users of mocpy would expect the library to work in multiprocessing context, thus this is not the best solution to me. |
@tboch : We'll go with both. The multiprocessing seems fixed by the switch in pickling recipe, and on top of this, some methods can be added to manage multi-threading on the rust side when they are especially critical. (thus the switch from bug to feature request: the bug seems fixed, the features are incomming) |
ok, I misunderstood, sorry, my bad. |
The new features are added. We'll do a release today. |
Thanks @ManonMarchand and @fxpineau for all your work. |
We have been putting moc. probability_in_multiordermap(skymap)
within a parallel loop using multiprocessing to parallelize across mocs, and see errors like the below:
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/hildafs/home/oconnorb/.conda/envs/gwemopt/lib/python3.11/site-packages/mocpy/moc/moc.py”, line 771, in probability_in_multiordermap
return mocpy.multiorder_probdens_map_sum_in_smoc(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
OSError: MOC at index ‘3’ not found
Exception ignored in: <function AbstractMOC.del at 0x14a65c27f9c0>
Traceback (most recent call last):
File “/hildafs/home/oconnorb/.conda/envs/gwemopt/lib/python3.11/site-packages/mocpy/abstract_moc.py”, line 24, in del
mocpy.drop(self.store_index)
OSError: MOC at index ‘3’ not found
Exception ignored in: <function AbstractMOC.del at 0x14a65c27f9c0>
Traceback (most recent call last):
File “/hildafs/home/oconnorb/.conda/envs/gwemopt/lib/python3.11/site-packages/mocpy/abstract_moc.py”, line 24, in del
mocpy.drop(self.store_index)
OSError: MOC at index ‘2’ not found
Do you have a sense why this might be? It seems deep within the package, so a bit hard to tell what might be the problem.
The text was updated successfully, but these errors were encountered: