"WARNING: Could not locate the 'ipopt' executable" and Pyomo (OS: Windows) - anaconda

I have been trying to make ipopt work on pyomo. I've downloaded pyomo (version 5.7.3) and ipopt using Anaconda Navigator and I'm using Spyder to edit and run my .py codes. I've been using the following code from the pyomo tutorial in order to understand whether ipopt is successfully installed and works.
import pyomo.environ as pyo
from pyomo.opt import SolverFactory
model = pyo.ConcreteModel()
model.nVars = pyo.Param(initialize=4)
model.N = pyo.RangeSet(model.nVars)
model.x = pyo.Var(model.N, within=pyo.Binary)
model.obj = pyo.Objective(expr=pyo.summation(model.x))
model.cuts = pyo.ConstraintList()
opt = SolverFactory('ipopt')
opt.solve(model)
# Iterate, adding a cut to exclude the previously found solution
for i in range(5):
expr = 0
for j in model.x:
if pyo.value(model.x[j]) < 0.5:
expr += model.x[j]
else:
expr += (1 - model.x[j])
model.cuts.add( expr >= 1 )
results = opt.solve(model)
print ("\n===== iteration",i)
model.display()
When I set opt = SolverFactory('ipopt') and run the code, it gives me the following warning:
WARNING: Could not locate the 'ipopt' executable, which is required for solver ipopt
My first try to solve this problem by myself is to manually download the ipopt executable (ipopt 3.11.1-win64) from the link below:
https://www.coin-or.org/download/binary/Ipopt/
Afterwards, I extracted the files and placed them into the pyomo solver location:
C:\Anaconda\envs\myenv\Lib\site-packages\pyomo\solvers\plugins\solvers
This didn't work, so I also tried specifying the path to the ipopt executable using the code:
opt = pyo.SolverFactory("ipopt", executable="C:\Anaconda\envs\myenv\Lib\site-packages\pyomo\solvers\plugins\solvers\ipopt\bin\ipopt.exe")
However, doing this gives me the following warning:
WARNING: Failed to create solver with name 'ipopt': Failed to set executable
for solver ipopt. File with name=C:\Anaconda\envs\myenv\Lib\site-packages\
pyomo\solvers\plugins\solvers\ipopin\ipopt.exe
either does not exist or it is not executable. To skip this validation,
call set_executable with validate=False.
Reminder that the part ipopin\ipopt.exe was not a typo. I don't know why it happened. I also tried copy-pasting the executable outside the bin folder and placing it in the ipopt folder instead:
opt = pyo.SolverFactory("ipopt", executable="C:\Anaconda\envs\myenv\Lib\site-packages\pyomo\solvers\plugins\solvers\ipopt\ipopt.exe")
Unfortunately I still get the WARNING. Could not locate the 'ipopt' executable, which is required for solver ipopt in the end.
I also tried downloading the ipopt executable from the link below but ipopt.exe is eliminated by my virus scanner as it considers the downloaded file as a threat:
https://projects.coin-or.org/CoinBinary/browser/binary/Ipopt/Ipopt-3.13.2-win64-msvs2019-md.zip?rev=1072
Is there another way I can try to make IPOPT work in this case?

if you run your jupyter notebook from the anaconda then you should be able to see your solver in the installed list of anaconda

Related

METIS Installation on google colab

Following this source I would like to install METIS and the Python wrapper in colab:
https://github.com/james77777778/metis_python
The installation steps are listed as the following:
Download and extract metis-5.1.0.tar.gz from METIS - Serial Graph Partitioning and Fill-reducing Matrix Ordering
cd metis-5.1.0
make config shared=1 prefix=~/.local/
make install
export METIS_DLL=~/.local/lib/libmetis.so
pip3 install metis-python
However, I'm not sure how to do steps 2-4 in colab specifically and so I get the following error:
RuntimeError: Could not locate METIS dll. Please set the METIS_DLL environment variable to its full path.
Thanks!
The issue seems to be the location of the libmetis.so file. Copying the file to /usr/lib and updating the path for the environmental variable successfully completes the process:
import requests
import tarfile
# Download and extract the file
url = "http://glaros.dtc.umn.edu/gkhome/fetch/sw/metis/metis-5.1.0.tar.gz"
response = requests.get(url, stream=True)
file = tarfile.open(fileobj=response.raw, mode="r|gz")
file.extractall(path=".")
# Change working directory
%cd metis-5.1.0
# The remaining steps as you have shown in the question, with updated path
!make config shared=1 prefix=~/.local/
!make install
!cp ~/.local/lib/libmetis.so /usr/lib/libmetis.so
!export METIS_DLL=/usr/lib/libmetis.so
!pip3 install metis-python
import metispy as metis

Installing toolboxes in Octave

In order to realise some course's activity in Octave, found in the following site
https://nbviewer.org/github/gpeyre/numerical-tours/blob/master/matlab/audio_1_processing.ipynb#
I needed to install some toolboxes found in
http://www.numerical-tours.com/installation_matlab/
Two of them seems to be easily installed via pkg install -forge ... (I have Linux Mint 19), these toolboxes are 'general' and 'signal', but 'graph' and 'wavelet_meshes' seems not to be directly available for Octave.
1 - So, if I downloaded them manually.. how should I install these packages? I do not even find Octave directory using 'whereis' in order to localise a proper folder to throw toolboxes files (its path shown located in /app/share/octave when open).
2 - Another thing.. should I spect to use toolboxes automatically after toolbox is installed? or may I indicate its selection in some specific way? ..I ask this because after running the following script chunk
n = 1024*16;
options.n = n;
[x,fs] = load_sound('bird', n);
command window throws the following message
error: 'load_sound' undefined near line 3, column 4
so I understand Octave does not recognises 'load_sound' function, which is from 'signal' toolbox (that is already installed).
Any suggestions?

Installing IPOPT nonlinear solvers

I am trying to install ipopt with anaconda on Windows10 x64.
I already installed ipopt via "conda install -c conda-forge ipopt" in the anaconda prompt (version=3.13.4).
I built a small test-script in python to check my installation:
import pyomo.environ as pe
import pyomo.opt as po
M = pe.ConcreteModel()
M.x = pe.Var()
M.y = pe.Var(bounds=(0, None))
M.obj = pe.Objective(expr=M.x+M.y, sense=pe.minimize)
M.c1 = pe.Constraint(expr=(M.x >=4)) // this constraint expr will be replaced by M.x**2 >= 4 to test nonlinear problems
M.c2 = pe.Constraint(expr=(M.y >= M.x))
solver = po.SolverFactory('ipopt')
results = solver.solve(M, tee=True)
print(pe.value(M.x), pe.value(M.y))
Running the script, I received the following error message:
ApplicationError: No executable found for solver 'ipopt'
I could solve this problem downloading the zip-folder for 64-bit windows from https://ampl.com/products/solvers/open-source/ and extracting the files into the "Library"-folder of the anaconda environment I am working on.
Running the test script for the linear problem again, the problem is solved but I get the following information:
This is Ipopt version 3.12.13, running with linear solver mumps.
NOTE: Other linear solvers might be more efficient (see Ipopt documentation).
The nonlinear test problem, however, cannot be solved as still the linear mumps solver is applied.
EXIT: Maximum Number of Iterations Exceeded.
WARNING: Loading a SolverResults object with a warning status into
model.name="unknown";
- termination condition: maxIterations
- message from solver: Ipopt 3.12.13\x3a Maximum Number of Iterations
Exceeded.
M.x=-281240.49215541 M.y=13.01195537079578
How can I make sure that nonlinear problems are solved by ipopt as well? I am aware that there are a few similar questions on stackoverflow, but I wasn't able to solve my problem yet.
(I also tried to follow the installation guide from https://coin-or.github.io/Ipopt/INSTALL.html, but encountered the message "configure: error: no acceptable C compiler found in $PATH""" in the MSYS2 console when I tried to install ASL or HSL, even though I installed gcc as described and included the folder which contains gcc.exe into my PATH-variable.)
Probably the conda-forge package doesn't include the AMPL interface and the ipopt executable that is required by Pyomo (at least, that is the case for https://anaconda.org/conda-forge/ipopt/3.13.4/download/win-64/ipopt-3.13.4-hf6be2e5_0.tar.bz2).
MUMPS should not be the reason if Ipopt failed to solve min x+y s.t. x>=4, y>=x. One would need to inspect the Ipopt log to see what is going wrong.
If you feel that the executable from ampl.com is too old, you can try the ones that are attached to the Ipopt releases, e.g., https://github.com/coin-or/Ipopt/releases/download/releases%2F3.14.1/Ipopt-3.14.1-win64-msvs2019-md.zip for the latest.
They also include Pardiso from MKL in addition to MUMPS.
To check why the compiler check in configure failed under msys2, have a look into file config.log that is generated by configure.

cx_Freeze throws an error when building if packages are involved

cx_Freeze successfully converts a .py file to an .exe if no other packages are involved.
But when pandas is included, the setup fails with this message:
File "C:\Anaconda\lib\site-packages\cx_Freeze\hooks.py", line 1324, in load_zmq
libzmq = __import__("zmq", fromlist=["libzmq"]).libzmq
AttributeError: module 'zmq' has no attribute 'libzmq'
This is the contents of the setup.py:
import sys
from cx_Freeze import setup, Executable
build_exe_options = {"packages": ["pandas"]}
base = None
if sys.platform == "win32":
base = "Win32GUI"
setup( name = "test",
version = "0.1",
options = {"build_exe": build_exe_options},
executables = [Executable("test.py", base=base)])
So far I've tried creating a different environment in anaconda to run cx_freeze to see if the problem resolves itself that way.
Appreciate any help.
I've spent a long time trying to find an answer to this question, but luckily it can be found here. It seems it was a bug inherent to cx_freeze.
Although the link provided to download the wheels no longer works, the patch has been added to the latest development version (6.6.0 if I recall correctly). You can install it directly from github, as such:
python -m pip install git+https://github.com/marcelotduarte/cx_Freeze.git
Doing this fixed the error for me (and enabled me to discover other errors that I had to deal with!).

cx_freeze does not find python 3 path mac

I have this problem when I try to generate an app executable. I follow this example so the code for the setup would be
application_title = "app_name" #what you want to application to be called
main_python_file = "main.py" #the name of the python file you use to run the program
import sys
from cx_Freeze import setup, Executable
base = None
if sys.platform == "win32":
base = "Win32GUI"
includes = ["atexit","re"]
setup(
name = application_title,
version = "0.1",
description = "Sample cx_Freeze PyQt4 script",
options = {"build_exe" : {"includes" : includes }},
executables = [Executable(main_python_file, base = base)])
then I go to my terminal and press
python setup.py bdist_mac
for some reason that I do not know how to solve I get this output, and the file it is not generated
running bdist_mac
running build
running build_exe
copying /Applications/anaconda/lib/python3.4/site-packages/cx_Freeze/bases/Console -> build/exe.macosx-10.5-x86_64-3.4/main
copying /opt/local/Library/Frameworks/Python.framework/Versions/3.4/Python -> build/exe.macosx-10.5-x86_64-3.4/Python
error: [Errno 2] No such file or directory: '/opt/local/Library/Frameworks/Python.framework/Versions/3.4/Python'
I have installed anaconda with Python 3.4 and cx_freeze. Any suggestions?
I met the same problem and it is fixed by installing a separated python besides anaconda. It seems to be similar with the problem here
py2app is not copying the Python.framework to the new app while using virutalenv

Resources