SpaceTeam / ortools

Tools and scripts for OpenRocket
MIT License
14 stars 4 forks source link

Add parallelization feature #4

Open christophfroehlich opened 2 years ago

christophfroehlich commented 2 years ago

The dispersion analysis, basically a monte-carlo simulation, is predestinated for parallelization.

How could one implement this within this python/java framework? Maybe https://docs.python.org/3/library/multiprocessing.html would do the job.

christophfroehlich commented 2 years ago

I played a little bit with Multiprocessingand concurrent.futures.

I got to the point

TypeError: cannot pickle '_jpype._JPackage' object

which means that I cannot run more than one simulation with the same orh instance. There is a pickle support of jpype, but I've no glue how to start with it.. https://github.com/jpype-project/jpype/issues/533

Trying to create more than one instance of orhelper.OpenRocketInstance() gives

File "....\ortools\lib\site-packages\orhelper_orhelper.py", line 50, in enter jpype.startJVM(jvm_path, "-ea", f"-Djava.class.path={self.jar_path}") File "....\ortools\lib\site-packages\jpype_core.py", line 177, in startJVM raise OSError('JVM cannot be restarted')

It seems to be impossible to launch the JVM (i.e., orhelper.OpenRocketInstance()) more than once within the same python script: https://github.com/jpype-project/jpype/issues/959

@PatrickKa Any ideas how to overcome this?

Maybe we can duplicate the jar file and load two orhelper for different files. But for creating more than one OR-jar file we would have to adapt orhelper, because the jar file is hardcoded: https://github.com/SilentSys/orhelper/blob/bc240170b8fde9077c7e4ab6cd2aa01ace142a36/orhelper/_orhelper.py#L14