Using IPOPT with Openmdao (or pyoptsparse) in python - python-2.7

Hello everyone. I have a little problem : I am working with openmdao and pyOptSparseDriver. It is working for some solvers (SLSQP, PSQP for instance) so there is no problem about that installation.
Now i'd like to try the same with IPOPT, but the code is not given with pyoptsparse. I followed the COIN-OR documentation to install IPOPT (http://www.coin-or.org/Ipopt/documentation/node10.html), and everything SEEMS ok (i don't know how to check it). Now i have a COIN-OR folder on my desk and i don't know how to make pyoptsparse take IPOPT from it (it is the line "from . import pyoptcore" that crashes), from pyIPOPT/pyIPOPT.py.
Can anyone help me ?
Thank you by advance

we're using IPOPT with OpenMDAO through the pytoptsparse package, and installed it as a standalone library, like you've done. To get that to work you need to set the IPOPT_DIR environment variable pointing to the location you installed IPOPT before running the install of pyoptsparse.
So assuming you installed IPOPT in e.g. /usr/local/IPOPT:
$ export IPOPT_DIR=/usr/local/IPOPT
$ cd /path/to/pyoptsparse/
$ python setup.py install
this should result in pyoptsparse compiling the python wrapper for IPOPT and produce the file pyoptcore.so that will be placed in Python's site-packages/pyoptsparse/pyIPOPT.
On our cluster we had to modify the pyoptsparse/pyIPOPT/setup.py file slightly since we compiled everything with Intel, but if you compile with gfortran the official version of pyoptsparse should work for you.
Alternatively, you can do like Justin suggests, which is essentially the instructions you find in the pyoptsparse docs.

you have to put the ipopt source code into the src folder of pyopt-sparse and then recompile the package.

Related

Pyomo 6.0 on WinPython 3940: best way to install Ipopt?

There is no "pip install ipopt".
What is the best way to proceed then, once I installed Pyomo?
I dropped a copy of Ipopt.exe in the "python-3.9.4.amd64" forlder, and it works.
But it looks a bit dirty to me!
I use Pyomo since a long time, and installing Ipopt or Glpk has always been an uncertainty.
On colab, azure notebooks, and now winpython.
Thanks
Michel
Place the .exe somewhere and make sure to add the directory to the PATH. The same goes for glpk.
The python folder you mentioned is probably on the system's path and that’s why it works.

How to find the correct version of PyBindGen for Python Bindings

Currently, I am working on the Ns3 simulator and now trying to enable the pyviz visualizer. According to the doc, I have downloaded the three dependencies which are
py27-pygtk
py27-pygoocanvas
py27-pygraphviz
Now in order to use this, I still need to enable the python bindings which I used /usr/bin/python2.7 ./waf configure wanna to check what needs for enabling python bindings. The result shows that
Python Bindings : not enabled (PyBindGen version not correct and newer version could not be retrieved)
So I checked the Doc and downloaded PyBindGen (version 0.18.0). The output shows
Installed /Library/Python/2.7/site-packages/PyBindGen-0.18.0-py2.7.egg
Processing dependencies for PyBindGen==0.18.0
Finished processing dependencies for PyBindGen==0.18.0
After I ran the configuration check the results still showed that PyBindGen version not correct and newer version could not be retrieved
So I presume that is that because I installed the wrong version of PyBindGen? If so how can I get the suitable version for enabling Python Binding?
I would appreciate if there is someone who can help me figure it out. Many thanks.
S.
According to the Google Group
Here is the resolution(tested it worked):
follow the instruction
hg clone http://code.nsnam.org/ns-3-allinone
cd ns-3-allinone && ./download.py
This will solve the Python Binding problem
Updated: after downloading this version of ns3. Solving the python binding problem. Then there will be another problem after running
./waf configure
it will show the result like this:
PyViz visualizer: not enabled (Missing python modules: gtk, goocanvas, pygraphviz)
Even though I have installed all of the three dependencies. So after some researches I found that there has another questions post So there is a guy gave the guessing that
" Waf found the standard Python here (/usr/bin/python is the Apple path), and you installed the python libraries using MacPorts.
Most probably you'll need to configure Python to point to the MacPort-based Python, or it will not see what you installed."
So according to How to: Macports select python
here is the solution:
port select --list python
sudo port select --set python python27
Hope it will help anyone come afterwards to use this.
S.

Pyomo can't locate GLPK solver

I'm trying to use the GLPK solver with Pyomo. I have a working model that's been tested, but keep getting an error saying GLPK can't be found.
WARNING: Could not locate the 'glpsol' executable, which is required for solver 'glpk'
I've installed glpk sucessfully. I also added the directory to my path variable so the executed can be called globally. I tested this with glpsol --help from my command line, and see the help info printed.
The below thread says it should be working, but alas, it is not.
How do you install glpk-solver along with pyomo in Winpython
Any ideas?
This answer is late but I want to share the solution that worked for me.
solvername='glpk'
solverpath_folder='C:\\glpk\\w64' #does not need to be directly on c drive
solverpath_exe='C:\\glpk\\w64\\glpsol' #does not need to be directly on c drive
I used to do this:
sys.path.append(solverpath_folder)
solver=SolverFactory(solvername)
This works for the cbc solver in coin-or but it does not work for glpk. Then I tried something different:
solver=SolverFactory(solvername,executable=solverpath_exe)
This worked for both cbc and glpk. No idea why this works (I really didn't do anything else).
Version: Python 2.7 or Python 3.7 (tested both), glpk 4.65
You can install glpk solver using this command -
brew install glpk
Installing the glpk package worked for me. As I use Anaconda:
conda install -c conda-forge glpk
This was after already including the 'glpsol' exectuable's folder path in my PATH variables.
So it looks like the set path variable is not handled by your Python installation.
A normal Python installation is set up for a seperated "PYTHONPATH" environment variable to look up additional modules.
There is also the option to make an entry in the windows registry or (like you already mentioned) move the files to the Python home directory, which is recognized relative to your installation directory if "PYTHONHOME" is not set.
More information in the Python Documentary under 3.3.3.
https://docs.python.org/2/using/windows.html#finding-modules
I was having the same issue. I don't know if this is a solution but it definitely got the solver working.
After downloading the Windows installation. I copied all the files in the w64 folder and pasted them directly into my Python working directory.
After that my python code could locate the solver.
NOTE: this was for Python 3.4.3.4, Windows 8.1 64 bit
Reading the source code here suggests you try:
from pyutilib.services import register_executable, registered_executable
register_executable(name='glpsol')
maybe will it give a clue
I had the same issue on Windows 10 and it was down to glpk being installed in a different conda environment. Full steps for installing pyomo and glpk below.
Test the installation by running 'Repeated Solves' example from https://pyomo.readthedocs.io/en/latest/working_models.html
Instructions (run at an anaconda prompt)
conda create --name myenv
conda activate myenv
conda install -c conda-forge pyomo
conda install -c conda-forge pyomo.extras
conda install -c conda-forge glpk
Run spyder from myenv so that if finds everything
spyder activate myenv
Here is the relevant part where pyomo 6.2 searches for the glpsol executable
https://github.com/Pyomo/pyomo/blob/568c6595a56570c6ea69c3ae3198b73b9f473abd/pyomo/common/fileutils.py#L288
def _path():
return (os.environ.get('PATH','') or os.defpath).split(os.pathsep)
There are two options to solve the PATH problem:
Putting the executable in an available folder in PATH (recommended practice). The glpsol executable must be in one of the folders present in the PATH system environment variable. Use in your code print(os.environ['PATH']) to see the available folders and put it there.
Adding the folder to PATH at runtime. You can add it to the system PATH statically or use code to add it dynamically (only while your script is running):
GLPK_FOLDER_PATH = "path/to/glpk"
os.environ["PATH"] += os.pathsep + str(GLPK_FOLDER_PATH)
In my case, my Python project has a virtual environment .venv, and I have an installation process that pastes the files essential to the glpsol executable when I install the project inside the .venv/Scripts folder. Because that folder is added automatically to the system PATH when Python is called from the virtual environment, libraries like Pyomo can find it. And I don't have to remember to add the folder to PATH at runtime whenever I want to use Pyomo.
For anyone that has the same issue, I found a workaround (not a solution!). I copied all the glpk files into my C:/Python27 directory, and (Surprise!) Python can now find them.
I'll hold out for a real solution before accepting this one.

dicom3tools compiles with missing application pbmtoovl

I've downloaded dicom3tools in Ubuntu apt-get install dicom3tools, but certain apps are not present.
I've downloaded the source and compiled according to directions on Ubuntu without errors. I have access to most of the apps in the kit, but some just seem to be missing or not compiling.
I need a working binary copy of the pbmtoovl tool from this kit.
Can anyone help me?
Do you know why it is missing?
Do I need to compile differently?
Do you have a copy of the pbmtoovl app pre-compiled?
There is no info on this anywhere on the web, I have nowhere else to turn.
Thanks in advance for any info on this.
Please please help me with this.....
I edited the proper file with a uid.
I ran
imake -I./config -DInstallInTopDir -DUsemyID
and everything looked fine.
make World.
make install
make install.man,
but still no rawtodc or pbmtoovl or any of the dicom creation tools. I really need these tools. Please let me know what I'm doing wrong. On Ubuntu 14 –
I am the author of the dicom3tools debian package. The explanation is given online here.
When you install a debian package, you are required to read the documentation. In this case the documentation was available on your system from:
$ cat /usr/share/doc/dicom3tools/README.Debian
So you'll need to follow the build instructions yourself (see INSTALL):
Edit config/site.p-def to set your UID root (a la UseClunieID, to be
selected with a UseXXXXID define on the imake command line).
NB. Don't ever use any UseClunie*ID or your instances
will conflict with mine !
./Configure
setenv IMAKEINCLUDE -I./config # only needed for suns
imake -I./config -DInstallInTopDir -DUseXXXXID
make World
make install # into ./bin
make install.man # into ./man
I finally did a fresh Ubuntu install, installed xutils, g++, gcc and ran the compiling instructions. It did not install, again, but this time I did have a new directory in bin ending in 'unknown' that miraculously contained all of the compiled binaries. I added that dir to the PATH and VOILA I can access all the tools from the command line....
It's still a problem, but I can now use pbmtoovl

make boost python pick up the correct python version on osx

Im currently building a module with boost python and I cant get it to build against the correct version of python(I need it to build against 2.6). The first thing I tried was setting my PATH to that of the version of python I'd like to install, but that built a module that would only run on the default system version, 2.7. Next I tried adding --with-python-version=2.6 as an argument for bootstrap but that didnt work either.
I'm new to c++ and I'm building someone else's code so apologies if there is a blindingly obvious answer
I don't know if this is what solves your issue, but it sounds like something I had dealt with when building another boost project. It would constantly find the wrong python installation no matter what I do. Namely, it always wanted the system python. I addressed it by telling it to look at another INCLUDE location:
cmake -D PYTHON_INCLUDE_DIR=/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Headers