Pyomo / pyomo

An object-oriented algebraic modeling language in Python for structured optimization problems.
https://www.pyomo.org
Other
2.01k stars 518 forks source link

Fail to create solver in web app #1892

Closed bresait closed 3 years ago

bresait commented 3 years ago

Hello, I am trying to embed an optimization routine in a web app (Flask/Dash). Locally, everything works fine. On the deployment server (Ubuntu 20, with Apache2 server), the following warning and error are raised:

WARNING:pyomo.opt:Failed to create solver with name 'cbc':,
preexec_fn not supported within subinterpreters,
...
RuntimeError: Attempting to use an unavailable solver.,
The SolverFactory was unable to create the solver "cbc" and returned an UnknownSolver object.  
This error is raised at the point where the UnknownSolver object was used as if it were valid (by calling method "solve").

The original solver was created with the following parameters:
executable: /usr/bin/cbc,
type: cbc, 
\t_args: (), 
options: {}, 

I am under the impression that the problem may be related to this warning "preexec_fn not supported within subinterpreters,", but I do not know how to deal with it. Thank you for your help!

bresait commented 3 years ago

Hello, This was not really a Pyomo issue after all, even though the rest of the code was not affected. A few words before closing the issue, as it may help others running into similar issues: As explained under https://github.com/GrahamDumpleton/mod_wsgi/issues/614, the issue had to do with restrictions introduced by Python 3.8 on what you can do in Python sub interpreters, which caused my problem. Following the instructions there solved it for me.

VedranKapor commented 3 years ago

Hi, Is there simple solution? I run into same problem when calling python script (pyomo model with cbc solver which works fine as standalone) but returns error when calling it from PHP app that runs on Apache. "WARNING: Failed to create solver with name '_cbc_shell': Failed to set" " executable for solver cbc. File with" Thanks

bresait commented 3 years ago

I guess your problem is distinct from the one I had. For me it was enough to change the Apache config file as in the linked issue:

# Outside of VirtualHost. This disabled embedded mode to ensure you are using daemon mode.
WSGIRestrictEmbedded On

# Inside of VirtualHost (presuming you are using them).
WSGIDaemonProcess myapp
WSGIScriptAlias / /some/path/myapp.py process-group=myapp application-group=%{GLOBAL}
akhileshgarude commented 1 year ago

Hello, Could you hep on what were exactly the steps you followed. I have created a streamlit app using the SCIP solver. It is working perfectly on my local machine, but it is giving the following error that the exe cannot be found while deploying on cloud through GitHub. I have also added the solver exe file in the repository.

Failed to create solver with name 'scipampl': Failed to set executable for solver asl. File with name=scipampl either does not exist or it is not executable. To skip this validation, call set_executable with validate=False. Traceback (most recent call last): File "/home/appuser/venv/lib/python3.9/site-packages/pyomo/opt/base/solvers.py", line 166, in call opt = self._cls_implicit_solvers[mode] File "/home/appuser/venv/lib/python3.9/site-packages/pyomo/solvers/plugins/solvers/ASL.py", line 44, in init SystemCallSolver.init(self, **kwds) File "/home/appuser/venv/lib/python3.9/site-packages/pyomo/opt/solver/shellcmd.py", line 56, in init self.set_executable(name=executable, validate=validate) File "/home/appuser/venv/lib/python3.9/site-packages/pyomo/opt/solver/shellcmd.py", line 104, in set_executable raise ValueError( ValueError: Failed to set executable for solver asl. File with name=scipampl either does not exist or it is not executable. To skip this validation, call set_executable with validate=False. 2022-11-30 13:15:56.581 Uncaught app exception Traceback (most recent call last): File "/home/appuser/venv/lib/python3.9/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 564, in _run_script exec(code, module.dict) File "/app/temp2/dynamictest_streamlit_deploy.py", line 459, in res=opt.solve(m,tee=True) File "/home/appuser/venv/lib/python3.9/site-packages/pyomo/opt/base/solvers.py", line 106, in solve self._solver_error('solve') File "/home/appuser/venv/lib/python3.9/site-packages/pyomo/opt/base/solvers.py", line 123, in _solver_error raise RuntimeError("""Attempting to use an unavailable solver. RuntimeError: Attempting to use an unavailable solver.

The SolverFactory was unable to create the solver "scipampl" and returned an UnknownSolver object. This error is raised at the point where the UnknownSolver object was used as if it were valid (by calling method "solve").

The original solver was created with the following parameters: executable: scipampl type: scipampl _args: () options: {}