I’ve gotten Geant4Py working for my medical physics application on a single thread, but I am finding a problem in Python 3.X (3.8.8) running GEANT4.10.7 that I do not get on an older install running Python 2.7.1 with GEANT4.10.2. This problem is distributing the simulation over multiple threads with the python multiprocessing module.
Using multiprocessing.Pool.map I get the error:
multiprocessing.pool.MaybeEncodingError: Error sending result:
'<multiprocessing.pool.ExceptionWithTraceback object at 0x7ff19e308f40>'. Reason:
'PicklingError("Can't pickle <class 'Boost.Python.ArgumentError'>: import of module 'Boost.Python' failed")'
And if I try to use ray.util.multiprocessing import Pool I get the error:
RuntimeError: Pickling of "Geant4.G4run.G4RunManager" instances is not enabled (http://www.boost.org/libs/python/doc/v2/pickle.html)
Is this a problem with how I installed Geant4Py or is there some thing else going on?
There was a typo in my DGEANT4_BUILD_MULTITHREADED flag. I’ve updated it and am reinstalling Geant4. I’m attempting to do it using 8 threads. In the past, G4Py would only work if Geant4 proper was installed on a single thread. I assume that this has been updated since the two are now built together?
I want to comment that I have reinstalled Geant4 with the proper flags set to get Geant4Py working with the multiprocessing flag turned on. However, the base issues has not been resolved. I still get:
multiprocessing.pool.MaybeEncodingError: Error sending result:
'<multiprocessing.pool.ExceptionWithTraceback object at 0x7f096052df40>'.
Reason: 'PicklingError("Can't pickle <class 'Boost.Python.ArgumentError'>:
import of module 'Boost.Python' failed")'
I am not sure If I understand correctly what you are trying to achieve, and I am certainly not an expert in python, but as far as I understand, multiprocessing is sort of “built into” the RunManager.
In c++, it is more or less
auto runManager = G4RunManagerFactory::CreateRunManager(G4RunManagerType::MT);
runManager->SetNumberOfThreads(nThreads);
and there you go: computations are running parallel… there is no need to manually distribute/chunk particles/whatsoever…
Hence I would be very much surprised if the python interface would be much more complicated!?
Sorry I can’t be of more help here, and I don’t have gitlab access… let’s see what someone with proper knowledge can do for you
Thank you for your help @weller. Unfortunately, g4py does not have a G4RunManagerFactory class. However, I was able to figure it out. It turns out the way I was chunking the particles was making that term into a float object and it wanted an int. So I fixed that and the multiprocessing module is functioning now!