Skip to content

Commit cc44423

Browse files
authored
Merge pull request #92 from sandialabs/dev-weh
Several changes
2 parents 5b22416 + f641b4e commit cc44423

File tree

6 files changed

+119
-22
lines changed

6 files changed

+119
-22
lines changed

Diff for: build.sh

+32-15
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,19 @@
55
#
66
# This uses Spack to install third-party dependencies in the `_spack` directory.
77
#
8-
with_python="OFF"
9-
python_exe=""
10-
spack_reinstall=0
11-
spack_dev=0
128
clang=0
139
debug="OFF"
10+
python_exe=""
11+
spack_dev=0
12+
spack_env="coekenv"
1413
spack_home=`pwd`/_spack
14+
spack_reinstall=0
15+
with_python="OFF"
1516
with_valgrind=""
1617
while [[ $# -gt 0 ]]; do
1718
case $1 in
1819
--help)
19-
echo "build.sh [--help] [--clang] [--debug] [--python] [--python-exe <file>] [--spack-dev] [--spack-home <dir>] [--spack-reinstall] [--valgrind]"
20+
echo "build.sh [--help] [--clang] [--debug] [--python] [--python-exe <file>] [--spack-dev] [--spack-env <env>] [--spack-home <dir>] [--spack-reinstall] [--valgrind]"
2021
exit
2122
;;
2223
--clang)
@@ -27,6 +28,11 @@ while [[ $# -gt 0 ]]; do
2728
debug="ON"
2829
shift
2930
;;
31+
--spack-env)
32+
spack_env="$2"
33+
shift
34+
shift
35+
;;
3036
--python)
3137
with_python="ON"
3238
shift
@@ -67,15 +73,21 @@ echo "SPACK_HOME=${SPACK_HOME}"
6773
if [[ "${spack_reinstall}" -eq 1 ]]; then
6874
\rm -Rf ${SPACK_HOME}
6975
fi
70-
if [[ "$spack_dev" -eq 0 ]]; then
71-
\rm -Rf _spack_tpls
72-
git clone https://github.com/or-fusion/or-fusion-spack-repo.git _spack_tpls
73-
else
74-
git clone [email protected]:or-fusion/or-fusion-spack-repo.git _spack_tpls
76+
if test -d _spack_tpls; then
7577
cd _spack_tpls
76-
git checkout dev
7778
git pull
7879
cd ..
80+
else
81+
if [[ "$spack_dev" -eq 0 ]]; then
82+
\rm -Rf _spack_tpls
83+
git clone https://github.com/or-fusion/or-fusion-spack-repo.git _spack_tpls
84+
else
85+
git clone [email protected]:or-fusion/or-fusion-spack-repo.git _spack_tpls
86+
cd _spack_tpls
87+
git checkout dev
88+
git pull
89+
cd ..
90+
fi
7991
fi
8092
\rm -Rf _build
8193
#
@@ -106,11 +118,14 @@ else
106118
echo ""
107119
git clone https://github.com/spack/spack.git ${SPACK_HOME}
108120
. ${SPACK_HOME}/share/spack/setup-env.sh
121+
echo "Adding _spack_tpls"
122+
spack repo remove _spack_tpls/repo | true
109123
spack repo add _spack_tpls/repo
110124
spack repo list
111-
spack env create coekenv
112-
spack env activate coekenv
113-
spack add asl cppad fmt rapidjson catch2 highs $with_valgrind
125+
spack env create $spack_env
126+
spack env activate $spack_env
127+
spack compiler find
128+
spack add asl fmt rapidjson catch2 highs $with_valgrind
114129
spack install
115130
spack env deactivate
116131
spack repo remove _spack_tpls/repo
@@ -126,5 +141,7 @@ echo "Building Coek"
126141
echo ""
127142
mkdir _build
128143
cd _build
129-
cmake -DCMAKE_PREFIX_PATH=${SPACK_HOME}/var/spack/environments/coekenv/.spack-env/view -Dwith_debug=${debug} -Dwith_python=${with_python} $python_exe -Dwith_gurobi=$with_gurobi -Dwith_highs=ON -Dwith_cppad=ON -Dwith_fmtlib=ON -Dwith_rapidjson=ON -Dwith_catch2=ON -Dwith_tests=ON -Dwith_asl=ON -Dwith_openmp=OFF ..
144+
cmake -DCMAKE_PREFIX_PATH=${SPACK_HOME}/var/spack/environments/${spack_env}/.spack-env/view -Dwith_debug=${debug} -Dwith_python=${with_python} $python_exe -Dwith_gurobi=$with_gurobi -Dwith_highs=ON -Dwith_cppad=OFF -Dwith_fmtlib=ON -Dwith_rapidjson=ON -Dwith_catch2=ON -Dwith_tests=ON -Dwith_asl=ON -Dwith_openmp=OFF ..
130145
make -j20
146+
make install
147+

Diff for: cmake/FindGUROBI.cmake

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ find_library(
4040
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
4141
find_library(
4242
GUROBI_CXX_LIBRARY
43-
NAMES gurobi_g++5.2
43+
NAMES gurobi_g++5.2 gurobi_g++8.5
4444
HINTS ${GUROBI_DIR} $ENV{GUROBI_HOME}
4545
PATH_SUFFIXES lib)
4646
else()

Diff for: lib/coek/coek/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ endif()
153153
# GUROBI LIBRARY
154154
#
155155
if(with_gurobi)
156+
find_package(GUROBI REQUIRED)
156157
list(APPEND sources
157158
solvers/gurobi/gurobi.cpp)
158159
list(APPEND coek_compile_options -DWITH_GUROBI)

Diff for: lib/pyomo_coek/pyomo_coek/components_only/__init__.py

+19-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,25 @@
77
from .linear_expression import LinearExpression
88
from pyomo.core.base.block import Block
99
from pyomo.core.base.PyomoModel import ConcreteModel
10-
from pyomo.core.base.set import RangeSet, Binary, Set, Reals, NonNegativeReals, Any
10+
from pyomo.core.base.set import RangeSet, \
11+
Reals, \
12+
PositiveReals, \
13+
NonPositiveReals, \
14+
NegativeReals, \
15+
NonNegativeReals, \
16+
Integers, \
17+
PositiveIntegers, \
18+
NonPositiveIntegers, \
19+
NegativeIntegers, \
20+
NonNegativeIntegers, \
21+
Boolean, \
22+
Binary, \
23+
Any, \
24+
AnyWithNone, \
25+
EmptySet, \
26+
UnitInterval, \
27+
PercentFraction
28+
1129
from pyomo.core.base.objective import minimize, maximize
1230
from pyomo.opt.base.solvers import SolverFactory
1331
from pyomo.opt import SolutionStatus, TerminationCondition

Diff for: lib/pyomo_coek/pyomo_coek/components_only/solvers.py

+10-3
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
SolutionLoader,
88
Results,
99
Solver,
10-
SolverFactory,
1110
)
11+
from pyomo.opt import SolverFactory
1212
from munch import Munch
1313
import poek as pk
1414
from typing import Tuple, Dict
@@ -157,7 +157,9 @@ def resolve(self, timer: HierarchicalTimer = None):
157157
res.best_feasible_objective = self._poek_nlp_model.get_objective().value
158158
return res
159159

160-
def solve(self, model: _BlockData, timer: HierarchicalTimer = None) -> Results:
160+
def solve(self, model: _BlockData, options=None, timer: HierarchicalTimer = None) -> Results:
161+
if options is None:
162+
options = {}
161163
if timer is None:
162164
timer = HierarchicalTimer()
163165

@@ -179,10 +181,14 @@ def solve(self, model: _BlockData, timer: HierarchicalTimer = None) -> Results:
179181
nlp = pk.nlp_model(pm, "cppad")
180182
self._poek_nlp_model = nlp
181183
self._set_options()
184+
for key, option in options.items():
185+
self._opt.set_option(key, option)
182186
_res = self._opt.solve(nlp)
183187
else:
184188
self._opt = pk.solver(self._solver_name)
185189
self._set_options()
190+
for key, option in options.items():
191+
self._opt.set_option(key, option)
186192
_res = self._opt.solve(pm)
187193
timer.stop("coek solve")
188194

@@ -201,6 +207,7 @@ def solve(self, model: _BlockData, timer: HierarchicalTimer = None) -> Results:
201207
res = Results()
202208
res.solution_loader = self.solution_loader
203209
res.termination_condition = poek2pyomo_termination_condition[_res.termination_condition]
210+
res.message = _res.error_message
204211
res.solution_status = poek2pyomo_solution_status[_res.solution_status]
205212
if pk.check_optimal_termination(_res):
206213
res.best_feasible_objective = _res.objective_value
@@ -220,7 +227,7 @@ def write(self, model: _BlockData, filename, timer: HierarchicalTimer = None):
220227

221228

222229
class Gurobi(HybridSolver):
223-
name = "appsi_coek_gurobi"
230+
name = "coek_gurobi"
224231

225232
def __init__(self):
226233
super().__init__("gurobi")

Diff for: lib/pyomo_coek/pyomo_coek/components_only/variable.py

+56-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,29 @@
1717
from pyomo.common.timing import ConstructionTimer
1818
from pyomo.common.log import is_debug_set
1919
import sys
20-
from pyomo.core.base.set import Binary, Reals, Integers, Any, GlobalSetBase
20+
21+
from pyomo.core.base.set import GlobalSetBase
22+
from pyomo.core.base.set_types import \
23+
Reals, \
24+
PositiveReals, \
25+
NonPositiveReals, \
26+
NegativeReals, \
27+
NonNegativeReals, \
28+
Integers, \
29+
PositiveIntegers, \
30+
NonPositiveIntegers, \
31+
NegativeIntegers, \
32+
NonNegativeIntegers, \
33+
Boolean, \
34+
Binary, \
35+
Any, \
36+
AnyWithNone, \
37+
EmptySet, \
38+
UnitInterval, \
39+
PercentFraction, \
40+
RealInterval, \
41+
IntegerInterval
42+
2143
from pyomo.common.collections import ComponentMap
2244
from weakref import ref as weakref_ref
2345
from pyomo.common.deprecation import deprecation_warning
@@ -33,9 +55,20 @@
3355

3456

3557
_domain_map = ComponentMap()
36-
_domain_map[Binary] = pk.VariableTypes.Binary
3758
_domain_map[Reals] = pk.VariableTypes.Reals
59+
_domain_map[PositiveReals] = pk.VariableTypes.Reals
60+
_domain_map[NonPositiveReals] = pk.VariableTypes.Reals
61+
_domain_map[NegativeReals] = pk.VariableTypes.Reals
62+
_domain_map[NonNegativeReals] = pk.VariableTypes.Reals
3863
_domain_map[Integers] = pk.VariableTypes.Integers
64+
_domain_map[PositiveIntegers] = pk.VariableTypes.Integers
65+
_domain_map[NonPositiveIntegers] = pk.VariableTypes.Integers
66+
_domain_map[NegativeIntegers] = pk.VariableTypes.Integers
67+
_domain_map[NonNegativeIntegers] = pk.VariableTypes.Integers
68+
_domain_map[Binary] = pk.VariableTypes.Binary
69+
_domain_map[Boolean] = pk.VariableTypes.Binary
70+
_domain_map[UnitInterval] = pk.VariableTypes.Reals
71+
_domain_map[PercentFraction] = pk.VariableTypes.Reals
3972

4073
_rev_domain_map = dict()
4174
_rev_domain_map[pk.VariableTypes.Binary] = Binary
@@ -185,6 +218,26 @@ def domain(self):
185218
@domain.setter
186219
def domain(self, val):
187220
self._pe.within = _domain_map[val]
221+
if val == PositiveReals:
222+
self.bounds = (0,None)
223+
elif val == NonPositiveReals:
224+
self.bounds = (None,0)
225+
elif val == NegativeReals:
226+
self.bounds = (None,0)
227+
elif val == NonNegativeReals:
228+
self.bounds = (0,None)
229+
elif val == PositiveIntegers:
230+
self.bounds = (1,None)
231+
elif val == NonPositiveIntegers:
232+
self.bounds = (None,0)
233+
elif val == NegativeIntegers:
234+
self.bounds = (None,-1)
235+
elif val == NonNegativeIntegers:
236+
self.bounds = (0,None)
237+
elif val == UnitInterval:
238+
self.bounds = (0,1)
239+
elif val == PercentFraction:
240+
self.bounds = (0,1)
188241

189242
@property
190243
def lower(self):
@@ -420,6 +473,7 @@ def construct(self, data=None):
420473
# (constant portions of) every VarData so as to not
421474
# repeat all the domain/bounds validation.
422475
try:
476+
self.index_set().construct()
423477
ref = self._getitem_when_not_present(next(iter(self.index_set())))
424478
except StopIteration:
425479
# Empty index!

0 commit comments

Comments
 (0)