eepeterson / pleiades

PLasma Experiment Iteratively Advanced DEsign and Simulation
https://pleiades.readthedocs.io/en/latest/
MIT License
5 stars 6 forks source link

calculating greens functions breaks pipes #2

Open jboguski opened 4 years ago

jboguski commented 4 years ago

Using Windows 10, python 3.7.6, running the juypter notebook pleiades_intro.ipynb works great, but running the same code in a .py file in ipython causes the following error:

File "C:\Users\l284987\Documents\Python Scripts\pleiades-develop\temp.py", line 40, in brb.grid = RZgrid

File "C:\Users\l284987\Documents\Python Scripts\pleiades-develop\pleiades\core.py", line 1751, in grid comp.grid = grid

File "C:\Users\l284987\Documents\Python Scripts\pleiades-develop\pleiades\core.py", line 944, in grid self.compute_greens()

File "C:\Users\l284987\Documents\Python Scripts\pleiades-develop\pleiades\core.py", line 885, in compute_greens p.start()

File "C:\Users\l284987\anaconda3\lib\multiprocessing\process.py", line 112, in start self._popen = self._Popen(self)

File "C:\Users\l284987\anaconda3\lib\multiprocessing\context.py", line 223, in _Popen return _default_context.get_context().Process._Popen(process_obj)

File "C:\Users\l284987\anaconda3\lib\multiprocessing\context.py", line 322, in _Popen return Popen(process_obj)

File "C:\Users\l284987\anaconda3\lib\multiprocessing\popen_spawn_win32.py", line 89, in init reduction.dump(process_obj, to_child)

File "C:\Users\l284987\anaconda3\lib\multiprocessing\reduction.py", line 60, in dump ForkingPickler(file, protocol).dump(obj)

BrokenPipeError: [Errno 32] Broken pipe

I tried inserting:

for c in brb.components: c.nprocs=1

right before: brb.grid = RZgrid

but it failed to set the number of processors used to 1, it gave the following error:

File "C:\Users\l284987\Documents\Python Scripts\pleiades-develop\temp.py", line 40, in c.nprocs=1

File "C:\Users\l284987\Documents\Python Scripts\pleiades-develop\pleiades\core.py", line 963, in nprocs if len(new_nprocs) != self._num_groups:

TypeError: object of type 'int' has no len()

eepeterson commented 4 years ago

Oh the type error at the end is because nprocs has to be iterable and be the same length as the number of groups in the component so replace c.nprocs = 1 with something like c.nprocs = [1]*c.num_groups. That should get rid of the TypeError.

As for the broken pipe, are you running the .py file in IPython itself or are you just running python test_pipe_error.py? where test_pipe_error.py is the name of your python file

eepeterson commented 4 years ago

So after a little digging I found this thread that describes that using the multiprocessing module in interactive Python especially on windows has a lot of problems associated with it. The way the multiprocessing is handled now in the code is not how I'd like it done so I may rewrite it and I'll keep this in mind when doing that, but I believe the solution to this for now is to use Jupyter notebooks if you want an interactive environment. Or simply execute a standard .py file using the non-interactive interpreter.

eepeterson commented 4 years ago

If you care to read a little about why this doesn't work, you can check out the links here, here, and here. If you try putting all the code you're trying to execute inside an if __name__ == '__main__': clause as shown in this post I believe it should work for you as a python script on windows.