usuaero / Optix

Python Gradient-Based Optimization Tool
MIT License
9 stars 3 forks source link

Problem with multiprocessing in Windows 11 #4

Open kwahcarioca opened 12 months ago

kwahcarioca commented 12 months ago

I ve had a problem running optix in Windows 11 which occurs either inside or outside of Pycharm IDE. It ssems to be related to multiprocessing. Nothing is said in the Readme file about the running environment, I ve assumed it runs correctly in any Environment (Windows or Linux). I may have an installation problem.

import optix as opt

Define the objective function

def objective_function(x): return (x[0]-5) * 2+4(x[1]-2) ** 2

if name == 'main':

# Initial guess
xo =[-2.0, -2.0]

optimum = opt.minimize(objective_function, xo, file_tag='_test', n_search = 8, max_processors = 1, line_search = "quadratic", termination_tol = 1e-6, verbose = True)

Running trace as follows:

C:\Documentos\Artificial Inteligence\Optimization\Optix-master\Optix-master>python myptix.py Traceback (most recent call last): File "", line 1, in File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.11_3.11.1264.0_x64qbz5n2kfra8p0\Lib\multiprocessing\spawn.py", line 120, in spawn_main exitcode = _main(fd, parent_sentinel) ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.11_3.11.1264.0_x64qbz5n2kfra8p0\Lib\multiprocessing\spawn.py", line 133, in _main return self._bootstrap(parent_sentinel) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TypeError: BaseProcess._bootstrap() takes 1 positional argument but 2 were given Traceback (most recent call last): File "", line 1, in File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.11_3.11.1264.0_x64qbz5n2kfra8p0\Lib\multiprocessing\spawn.py", line 120, in spawn_main exitcode = _main(fd, parent_sentinel) ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.11_3.11.1264.0_x64qbz5n2kfra8p0\Lib\multiprocessing\spawn.py", line 133, in _main return self._bootstrap(parent_sentinel) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TypeError: BaseProcess._bootstrap() takes 1 positional argument but 2 were given Traceback (most recent call last): File "C:\Users\mvgfa\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\multiprocessing_on_dill\connection.py", line 312, in _recv_bytes nread, err = ov.GetOverlappedResult(True) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ BrokenPipeError: [WinError 109] O pipe foi finalizado

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "C:\Documentos\Artificial Inteligence\Optimization\Optix-master\Optix-master\myptix.py", line 12, in optimum = opt.minimize(objective_function, xo, file_tag='_test', n_search = 8, max_processors = 1, line_search = "quadratic", termination_tol = 1e-6, verbose = True) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Documentos\Artificial Inteligence\Optimization\Optix-master\Optix-master\optix\optix.py", line 212, in minimize manager = mp.Manager() ^^^^^^^^^^^^ File "C:\Users\mvgfa\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\multiprocessing_on_dill\context.py", line 55, in Manager m.start() File "C:\Users\mvgfa\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\multiprocessing_on_dill\managers.py", line 483, in start self._address = reader.recv() ^^^^^^^^^^^^^ File "C:\Users\mvgfa\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\multiprocessing_on_dill\connection.py", line 250, in recv buf = self._recv_bytes() ^^^^^^^^^^^^^^^^^^ File "C:\Users\mvgfa\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\multiprocessing_on_dill\connection.py", line 321, in _recv_bytes raise EOFError EOFError

Thanks for making this software available to test!

kwahcarioca commented 12 months ago

Asked ChatGPT about this problem. Answer, as follows:

The error message you encountered is indicating that the method _bootstrap() in the class BaseProcess is defined to accept only one positional argument, but it is receiving two arguments instead. This error typically occurs when using the multiprocessing module in Python.

The most likely reason for this error is that you are trying to start a new process using multiprocessing in Windows, and when you pass the parent_sentinel argument, it is being treated as two separate integers instead of a single argument.

In Windows, the multiprocessing module uses a method called "spawn" to create new processes, which can lead to this issue due to the way it handles arguments passing between processes.

To resolve this issue, you should ensure that you are passing the parent_sentinel argument correctly when starting the new process. If you are using the multiprocessing.Process class to create the new process, make sure to pass the arguments as a tuple. For example:

from multiprocessing import Process

def my_function(parent_sentinel):

Your code here

if name == "main": parent_sentinel = (320, 318) p = Process(target=my_function, args=(parent_sentinel,)) p.start() p.join()

By placing the parent_sentinel values in a tuple and passing it as the args parameter when creating the Process, you should avoid the TypeError and properly pass the argument to the new process.

kwahcarioca commented 12 months ago

Not solved untill now

kwahcarioca commented 12 months ago

I couldnt solve the problem but it seems to be a conflict between multiprocessing_on_dill and multiprocessing packages. spawn.py of the first calls _Booststrap with one parameter parameter_sentinel but spawn.py of multiprocessing_on_dill calls _Booststrap with no parameter. If self is considered as one parameter so he could expect one or two parameters in accordance with the specific spawn.py version.