diff --git a/pyomo/contrib/pynumero/README.md b/pyomo/contrib/pynumero/README.md index 593d4dc947b..28845d628e4 100644 --- a/pyomo/contrib/pynumero/README.md +++ b/pyomo/contrib/pynumero/README.md @@ -14,7 +14,7 @@ PyNumero libraries PyNumero relies on C/C++ extensions for expensive computing operations. -If you installed Pyomo using Anaconda (from conda-forge), then you can +If you installed Pyomo using conda (from conda-forge), then you can obtain precompiled versions of the redistributable interfaces (pynumero_ASL) using conda. Through Pyomo 5.6.9 these libraries are available by installing the `pynumero_libraries` package from @@ -27,7 +27,20 @@ interfaces, you can build the extensions locally one of three ways: 1. By running the `build.py` Python script in this directory. This script will automatically drive the `cmake` build harness to compile the libraries and install them into your local Pyomo configuration -directory. +directory. Cmake options may be specified in the command. For example, + + python build.py -DBUILD_ASL=ON + +If you have compiled Ipopt, and you would like to link against the +libraries built with Ipopt, you can. For example, + + python build.py -DBUILD_ASL=ON -DBUILD_MA27=ON -DIPOPT_DIR=/lib/ + +If you do so, you will likely need to update an environment variable +for the path to shared libraries. For example, on Linux, + + export LD_LIBRARY_PATH=/lib/ + 2. By running `pyomo build-extensions`. This will build all registered Pyomo binary extensions, including PyNumero (using the `build.py` script from option 1). @@ -48,4 +61,6 @@ Prerequisites this library) 2. `pynumero_MA27`: - - *TODO* + - cmake + - a C/C++ compiler + - MA27 library diff --git a/pyomo/contrib/pynumero/extensions/tests/test_ma27_interface.py b/pyomo/contrib/pynumero/extensions/tests/test_ma27_interface.py index 335e03de0f0..495c463023d 100644 --- a/pyomo/contrib/pynumero/extensions/tests/test_ma27_interface.py +++ b/pyomo/contrib/pynumero/extensions/tests/test_ma27_interface.py @@ -10,7 +10,9 @@ import sys import os import ctypes -import numpy as np +from pyomo.contrib.pynumero.dependencies import numpy as np, numpy_available +if not numpy_available: + raise unittest.SkipTest('pynumero MA27 tests require numpy') import numpy.ctypeslib as npct import pyutilib.th as unittest from pyomo.contrib.pynumero.extensions.ma27_interface import * diff --git a/pyomo/contrib/pynumero/extensions/tests/test_ma57_interface.py b/pyomo/contrib/pynumero/extensions/tests/test_ma57_interface.py index 12d8cb0fe7a..869d69e07b5 100644 --- a/pyomo/contrib/pynumero/extensions/tests/test_ma57_interface.py +++ b/pyomo/contrib/pynumero/extensions/tests/test_ma57_interface.py @@ -10,7 +10,9 @@ import sys import os import ctypes -import numpy as np +from pyomo.contrib.pynumero.dependencies import numpy as np, numpy_available +if not numpy_available: + raise unittest.SkipTest('pynumero MA27 tests require numpy') import numpy.ctypeslib as npct import pyutilib.th as unittest from pyomo.contrib.pynumero.extensions.ma57_interface import * diff --git a/pyomo/contrib/pynumero/src/CMakeLists.txt b/pyomo/contrib/pynumero/src/CMakeLists.txt index 22c65b86e54..cf246d2e6f3 100644 --- a/pyomo/contrib/pynumero/src/CMakeLists.txt +++ b/pyomo/contrib/pynumero/src/CMakeLists.txt @@ -139,9 +139,11 @@ IF( BUILD_ASL ) ENDIF() ENDIF() +# +# build hsl interfaces +# set(PYNUMERO_MA27_SOURCES - "ma27Interface.cpp" - "ma27Interface.hpp" + "ma27Interface.c" ) IF( BUILD_MA27 ) @@ -153,8 +155,7 @@ IF( BUILD_MA27 ) ENDIF() set(PYNUMERO_MA57_SOURCES - "ma57Interface.cpp" - "ma57Interface.hpp" + "ma57Interface.c" ) IF( BUILD_MA57 ) diff --git a/pyomo/contrib/pynumero/src/hsl_interface/Makefile b/pyomo/contrib/pynumero/src/hsl_interface/Makefile deleted file mode 100644 index 85911018ca8..00000000000 --- a/pyomo/contrib/pynumero/src/hsl_interface/Makefile +++ /dev/null @@ -1,54 +0,0 @@ -rootdir:=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST)))) - -include $(rootdir)/Makefile.in - -all: libpynumero_MA27.so libpynumero_MA57.so - - -ifeq ($(strip $(COINHSLDIR)),) - -# If libcoinhsl is not available, link with the ma27d.o object one gets from -# compiling ma27, e.g. gfortran -O2 -fPIC -c -o ma27d.o ma27d.f -libpynumero_MA27.so: ma27Interface.o $(MA27DIR)/ma27d.o - $(CL) $(CLFLAGS) $(OPTCL) $(OUTC) $@ $^ $(LIBGFORTRAN) $(LIBBLAS) - -LIBMA57 = -L$(MA57DIR) -lma57 - -else - -# IF libcoinhsl is available, get ma27 by dynamically linking libcoinhsl -libpynumero_MA27.so: ma27Interface.o - $(CL) $(CLFLAGS) $(OPTCL) $(OUTC) $@ $^ $(LIBCOINHSL) $(LIBGFORTRAN) $(LIBBLAS) - -LIBMA57 = $(LIBCOINHSL) - -endif - -ifeq ($(strip $(METISDIR)),) - -LIBMETIS = - -else - -# This assumes metis is locally installed -# TODO: allow option to link metis installed to some system location -# (and option to link system-installed ma57, for that matter) -LIBMETIS = -L$(METISDIR) -lmetis -lm - -endif - -libpynumero_MA57.so: ma57Interface.o - $(CL) $(CLFLAGS) $(OPTCL) $(OUTC) $@ $^ $(LIBMA57) $(LIBGFORTRAN) $(LIBBLAS) $(LIBMETIS) - -ma27Interface.o: ma27Interface.c - $(CC) $(CCFLAGS) $(OPTCC) $(OUTC) $@ $^ - -ma57Interface.o: ma57Interface.c - $(CC) $(CCFLAGS) $(OPTCC) $(OUTC) $@ $^ - -install: libpynumero_MA27.so libpynumero_MA57.so - $(CP) $^ $(INSTALLDIR)/lib/ - -clean: - $(RM) *27*.o *27*.so *57*.o *57*.so - diff --git a/pyomo/contrib/pynumero/src/hsl_interface/Makefile.in b/pyomo/contrib/pynumero/src/hsl_interface/Makefile.in deleted file mode 100644 index 655dec5c834..00000000000 --- a/pyomo/contrib/pynumero/src/hsl_interface/Makefile.in +++ /dev/null @@ -1,32 +0,0 @@ -OUTC = -o -OUTF = -o -RM = /bin/rm -f -CP = /bin/cp -CC = gcc -CL = gcc -FC = gfortran -FL = gfortran -AR = ar vr -LIBLAPACK = -llapack -LIBBLAS = -lblas -LIBGFORTRAN = -lgfortran - -CCFLAGS = -Wall -g -c -fPIC -CLFLAGS = -Wall -g -shared -FCFLAGS = -FLFLAGS = - -OPTFC = -O2 -OPTFL = -O2 -OPTCC = -O2 -OPTCL = -O2 - -INSTALLDIR = $${HOME}/.pyomo - -METISDIR = -COINHSLDIR = -MA27DIR = -MA57DIR = -MA97DIR = - -LIBCOINHSL = -L$(COINHSLDIR) -lcoinhsl diff --git a/pyomo/contrib/pynumero/src/hsl_interface/ma27Interface.c b/pyomo/contrib/pynumero/src/ma27Interface.c similarity index 84% rename from pyomo/contrib/pynumero/src/hsl_interface/ma27Interface.c rename to pyomo/contrib/pynumero/src/ma27Interface.c index 0cf2b8a6a50..c45d1757d8a 100644 --- a/pyomo/contrib/pynumero/src/hsl_interface/ma27Interface.c +++ b/pyomo/contrib/pynumero/src/ma27Interface.c @@ -204,39 +204,3 @@ void free_memory(struct MA27_struct* ma27) { } free(ma27); } - -int main() { - - struct MA27_struct* ma27 = new_MA27_struct(); - - printf("ICNTL[1-1]: %i\n", get_icntl(ma27, 0)); - printf("ICNTL[2-1]: %i\n", get_icntl(ma27, 1)); - printf("ICNTL[3-1]: %i\n", get_icntl(ma27, 2)); - printf("ICNTL[4-1]: %i\n", get_icntl(ma27, 3)); - - // Set print level - set_icntl(ma27, 2, 2); - printf("ICNTL[3-1]: %i\n", get_icntl(ma27, 2)); - - int N = 5, NZ = 7; - int IRN[7] = { 1, 1, 2, 2, 3, 3, 5 }; - int ICN[7] = { 1, 2, 3, 5, 3, 4, 5 }; - double* A = malloc(NZ*sizeof(double)); - if (A == NULL) { abort_bad_memory(1); } -// A = { 2., 3., 4., 6., 1., 5., 1. }; - A[0] = 2.; - A[1] = 3.; - A[2] = 4.; - A[3] = 6.; - A[4] = 1.; - A[5] = 5.; - A[6] = 1.; - double RHS[5] = { 8., 45., 31., 15., 17. }; - - do_symbolic_factorization(ma27, N, NZ, IRN, ICN); - do_numeric_factorization(ma27, N, NZ, IRN, ICN, A); - do_backsolve(ma27, N, RHS); - free_memory(ma27); - free(A); -} - diff --git a/pyomo/contrib/pynumero/src/hsl_interface/ma57Interface.c b/pyomo/contrib/pynumero/src/ma57Interface.c similarity index 91% rename from pyomo/contrib/pynumero/src/hsl_interface/ma57Interface.c rename to pyomo/contrib/pynumero/src/ma57Interface.c index 8882baaf78a..830cf817e8a 100644 --- a/pyomo/contrib/pynumero/src/hsl_interface/ma57Interface.c +++ b/pyomo/contrib/pynumero/src/ma57Interface.c @@ -315,29 +315,3 @@ void free_memory(struct MA57_struct* ma57) { } free(ma57); } - -int main() { - - struct MA57_struct* ma57 = new_MA57_struct(); - - printf("ICNTL[0]: %i\n", get_icntl(ma57, 0)); - printf("ICNTL[1]: %i\n", get_icntl(ma57, 1)); - printf("ICNTL[2]: %i\n", get_icntl(ma57, 2)); - printf("ICNTL[3]: %i\n", get_icntl(ma57, 3)); - - // Set print level - set_icntl(ma57, 4, 3); - printf("ICNTL[4]: %i\n", get_icntl(ma57, 4)); - - int N = 5, NE = 7; - int IRN[7] = { 1, 1, 2, 2, 3, 3, 5 }; - int JCN[7] = { 1, 2, 3, 5, 3, 4, 5 }; - double A[7] = { 2., 3., 4., 6., 1., 5., 1. }; - double RHS[5] = { 8., 45., 31., 15., 17. }; - - do_symbolic_factorization(ma57, N, NE, IRN, JCN); - do_numeric_factorization(ma57, N, NE, A); - do_backsolve(ma57, N, RHS); - free_memory(ma57); -} -