Skip to content

Commit 8e08b31

Browse files
authored
Merge pull request #96 from sandialabs/dev-weh
Updates to compact modeling logic
2 parents d763c57 + b0cf288 commit 8e08b31

File tree

91 files changed

+4330
-1068
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+4330
-1068
lines changed

Diff for: .github/workflows/linux.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131
- uses: actions/checkout@v3
3232
- name: build tpls with Spack and then Coek
3333
run: |
34-
./build.sh
34+
./build.sh --with-spack
3535
- name: test
3636
run: |
3737
cd _build

Diff for: build.sh

+98-66
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,25 @@ clang=0
99
compact="OFF"
1010
debug="OFF"
1111
python_exe=""
12+
scip_config="OFF"
1213
spack_dev=0
1314
spack_env="coekenv"
1415
spack_home=`pwd`/_spack
1516
spack_reinstall=0
17+
18+
with_asl="ON"
19+
with_catch="ON"
20+
with_fmtlib="ON"
21+
with_highs="ON"
1622
with_python="OFF"
23+
with_rapidjson="ON"
1724
with_scip=""
18-
scip_config="OFF"
25+
with_spack=0
1926
with_valgrind=""
2027
while [[ $# -gt 0 ]]; do
2128
case $1 in
2229
--help)
23-
echo "build.sh [--help] [--clang] [--compact] [--debug] [--python] [--python-exe <file>] [--scip] [--spack-dev] [--spack-env <env>] [--spack-home <dir>] [--spack-reinstall] [--valgrind]"
30+
echo "build.sh [--help] [--clang] [--compact] [--debug] [--python] [--python-exe <file>] [--scip] [--spack-dev] [--spack-env <env>] [--spack-home <dir>] [--spack-reinstall] [--valgrind] [--with-spack]"
2431
exit
2532
;;
2633
--clang)
@@ -70,90 +77,115 @@ while [[ $# -gt 0 ]]; do
7077
with_valgrind="valgrind"
7178
shift
7279
;;
80+
--with-spack)
81+
with_spack=1
82+
shift
83+
;;
7384
*)
7485
echo "unknown option: $1"
7586
exit
7687
;;
7788
esac
7889
done
7990

80-
#
81-
# Setup directories
82-
#
83-
export SPACK_HOME=${spack_home}
84-
echo "SPACK_HOME=${SPACK_HOME}"
85-
if [[ "${spack_reinstall}" -eq 1 ]]; then
86-
\rm -Rf ${SPACK_HOME}
87-
fi
88-
if test -d _spack_tpls; then
89-
cd _spack_tpls
90-
git pull
91-
cd ..
92-
else
93-
if [[ "$spack_dev" -eq 0 ]]; then
94-
\rm -Rf _spack_tpls
95-
git clone https://github.com/or-fusion/or-fusion-spack-repo.git _spack_tpls
96-
else
97-
git clone [email protected]:or-fusion/or-fusion-spack-repo.git _spack_tpls
91+
if [[ "$with_spack" -eq 1 ]]; then
92+
#
93+
# Setup directories
94+
#
95+
export SPACK_HOME=${spack_home}
96+
echo "SPACK_HOME=${SPACK_HOME}"
97+
if [[ "${spack_reinstall}" -eq 1 ]]; then
98+
\rm -Rf ${SPACK_HOME}
99+
fi
100+
if test -d _spack_tpls; then
98101
cd _spack_tpls
99-
git checkout dev
100102
git pull
101103
cd ..
104+
else
105+
if [[ "$spack_dev" -eq 0 ]]; then
106+
\rm -Rf _spack_tpls
107+
git clone --depth 1 https://github.com/or-fusion/or-fusion-spack-repo.git _spack_tpls
108+
else
109+
git clone [email protected]:or-fusion/or-fusion-spack-repo.git _spack_tpls
110+
cd _spack_tpls
111+
git checkout dev
112+
git pull
113+
cd ..
114+
fi
102115
fi
103-
fi
104-
\rm -Rf _build
105-
#
106-
# Configure gurobi
107-
#
108-
if [[ -z "${GUROBI_HOME}" ]]; then
109-
with_gurobi="OFF"
110-
else
111-
with_gurobi="ON"
112-
fi
113-
#
114-
# Configure clang
115-
#
116-
if [[ $clang -eq 1 ]]; then
117-
export CXX=clang++
118-
export CC=clang
119-
fi
120-
#
121-
# Install spack
122-
#
123-
if test -d ${SPACK_HOME}; then
124-
echo ""
125-
echo "WARNING: Spack directory exists."
126-
echo ""
116+
#
117+
# Configure gurobi
118+
#
119+
if [[ -z "${GUROBI_HOME}" ]]; then
120+
with_gurobi="OFF"
121+
else
122+
with_gurobi="ON"
123+
fi
124+
#
125+
# Configure clang
126+
#
127+
if [[ $clang -eq 1 ]]; then
128+
export CXX=clang++
129+
export CC=clang
130+
fi
131+
#
132+
# Install spack
133+
#
134+
if test -d ${SPACK_HOME}; then
135+
echo ""
136+
echo "WARNING: Spack directory exists."
137+
echo ""
138+
else
139+
echo ""
140+
echo "Installing Coek dependencies using Spack"
141+
echo ""
142+
git clone --depth 1 https://github.com/spack/spack.git ${SPACK_HOME}
143+
. ${SPACK_HOME}/share/spack/setup-env.sh
144+
echo ""
145+
echo "Removing _spack_tpls"
146+
echo ""
147+
spack repo remove `pwd`/_spack_tpls/repo | true
148+
echo ""
149+
echo "Adding _spack_tpls"
150+
echo ""
151+
spack repo add `pwd`/_spack_tpls/repo
152+
spack repo list
153+
spack external find
154+
spack compiler find
155+
spack env create $spack_env
156+
spack env activate $spack_env
157+
spack add asl [email protected] rapidjson catch2 highs $with_valgrind $with_scip
158+
spack install
159+
spack env deactivate
160+
spack repo remove `pwd`/_spack_tpls/repo
161+
fi
162+
if test -d ${SPACK_HOME}; then
163+
export SPACK_HOME=$(cd ${SPACK_HOME}; pwd)
164+
echo ""
165+
echo "SPACK_HOME=${SPACK_HOME}"
166+
echo ""
167+
fi
168+
spack_cmake_options="-DCMAKE_PREFIX_PATH=${SPACK_HOME}/var/spack/environments/${spack_env}/.spack-env/view"
127169
else
128-
echo ""
129-
echo "Installing Coek dependencies using Spack"
130-
echo ""
131-
git clone https://github.com/spack/spack.git ${SPACK_HOME}
132-
. ${SPACK_HOME}/share/spack/setup-env.sh
133-
echo "Adding _spack_tpls"
134-
spack repo remove `pwd`/_spack_tpls/repo | true
135-
spack repo add `pwd`/_spack_tpls/repo
136-
spack repo list
137-
spack env create $spack_env
138-
spack env activate $spack_env
139-
spack compiler find
140-
spack add asl [email protected] rapidjson catch2 highs $with_valgrind $with_scip
141-
spack install
142-
spack env deactivate
143-
spack repo remove `pwd`/_spack_tpls/repo
144-
fi
145-
if test -d ${SPACK_HOME}; then
146-
export SPACK_HOME=$(cd ${SPACK_HOME}; pwd)
147-
echo "SPACK_HOME=${SPACK_HOME}"
170+
spack_cmake_options=""
171+
with_python="OFF"
172+
python_exe=""
173+
with_gurobi="OFF"
174+
with_highs="OFF"
175+
with_fmtlib="OFF"
176+
with_rapidjson="OFF"
177+
with_catch="OFF"
178+
with_asl="OFF"
148179
fi
149180
#
150181
# Install coek
151182
#
152183
echo "Building Coek"
153184
echo ""
185+
\rm -Rf _build
154186
mkdir _build
155187
cd _build
156-
cmake -DCMAKE_PREFIX_PATH=${SPACK_HOME}/var/spack/environments/${spack_env}/.spack-env/view -Dwith_debug=${debug} -Dwith_python=${with_python} -Dwith_pybind11=${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 -Dwith_compact=${compact} ..
188+
cmake $spack_cmake_options -Dwith_debug=${debug} -Dwith_python=${with_python} -Dwith_pybind11=${with_python} $python_exe -Dwith_gurobi=$with_gurobi -Dwith_highs=$with_highs -Dwith_cppad=OFF -Dwith_fmtlib=$with_fmtlib -Dwith_rapidjson=$with_rapidjson -Dwith_catch2=$with_catch -Dwith_tests=$with_catch -Dwith_asl=$with_asl -Dwith_openmp=OFF -Dwith_compact=${compact} ..
157189
make -j20
158190
make install
159191

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

+49-12
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,19 @@ SET(sources
66
util/option_cache.cpp
77
util/tictoc.cpp
88
util/string_utils.cpp
9+
)
10+
if (CMAKE_CXX_STANDARD GREATER_EQUAL 17)
11+
list(APPEND sources
12+
util/DataPortal.cpp
13+
)
14+
endif()
15+
16+
list(APPEND sources
917
ast/base_terms.cpp
1018
ast/constraint_terms.cpp
1119
ast/value_terms.cpp
1220
ast/expr_terms.cpp
21+
ast/visitor_expand.cpp
1322
ast/visitor_to_list.cpp
1423
ast/visitor_write_expr.cpp
1524
ast/visitor_to_MutableNLPExpr.cpp
@@ -20,18 +29,47 @@ SET(sources
2029
ast/visitor_simplify.cpp
2130
ast/visitor_eval.cpp
2231
#ast/varray.cpp
32+
)
33+
if (CMAKE_CXX_STANDARD GREATER_EQUAL 17)
34+
list(APPEND sources
35+
ast/compact_terms.cpp
36+
)
37+
endif()
38+
39+
list(APPEND sources
2340
api/constants.cpp
2441
api/expression.cpp
2542
api/expression_visitor.cpp
2643
api/objective.cpp
2744
api/constraint.cpp
2845
api/intrinsic_fn.cpp
46+
)
47+
if (CMAKE_CXX_STANDARD GREATER_EQUAL 17)
48+
list(APPEND sources
49+
api/data_assoc_array_repn.cpp
50+
api/data_assoc_array.cpp
51+
api/data_array.cpp
52+
api/parameter_assoc_array_repn.cpp
53+
api/parameter_assoc_array.cpp
54+
api/parameter_array.cpp
55+
api/variable_assoc_array_repn.cpp
56+
api/variable_assoc_array.cpp
57+
api/variable_array.cpp
58+
api/constraint_map.cpp
59+
api/subexpression_map.cpp
60+
)
61+
endif()
62+
63+
list(APPEND sources
2964
model/model.cpp
3065
model/compact_model.cpp
3166
model/nlp_model.cpp
3267
model/writer_lp.cpp
3368
model/writer_nl.cpp
3469
model/reader_jpof.cpp
70+
)
71+
72+
list(APPEND sources
3573
solvers/solver_results.cpp
3674
solvers/solver.cpp
3775
solvers/solver_repn.cpp
@@ -40,29 +78,19 @@ SET(sources
4078
autograd/autograd.cpp
4179
abstract/expr_rule.cpp
4280
)
43-
if (CMAKE_CXX_STANDARD GREATER_EQUAL 17)
44-
list(APPEND sources
45-
ast/compact_terms.cpp
46-
api/parameter_assoc_array.cpp
47-
api/parameter_array.cpp
48-
api/variable_assoc_array.cpp
49-
api/variable_array.cpp
50-
api/constraint_map.cpp
51-
api/subexpression_map.cpp
52-
util/DataPortal.cpp
53-
)
54-
endif()
5581

5682
if(with_compact)
5783
list(APPEND sources
5884
compact/sequence_context.cpp
5985
compact/expression_sequence.cpp
86+
compact/index_sequence.cpp
6087
compact/variable_sequence.cpp
6188
compact/objective_sequence.cpp
6289
compact/constraint_sequence.cpp
6390
compact/ast_set.cpp
6491
compact/coek_sets.cpp
6592
#compact/coek_indexed.cpp
93+
compact/data_map.cpp
6694
compact/parameter_map.cpp
6795
compact/variable_map.cpp
6896
compact/visitor_exprtemplate.cpp
@@ -246,8 +274,13 @@ install(FILES
246274
util/DataPortal.hpp
247275
util/tictoc.hpp
248276
util/io_utils.hpp
277+
util/tuple_utils.hpp
249278
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/coek/util
250279
)
280+
install(FILES
281+
ast/assoc_array_base.hpp
282+
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/coek/ast
283+
)
251284
install(FILES
252285
api/constraint_map.hpp
253286
api/subexpression_map.hpp
@@ -259,6 +292,9 @@ install(FILES
259292
api/intrinsic_fn.hpp
260293
api/indexed_container.hpp
261294
api/objective.hpp
295+
api/data_array.hpp
296+
api/data_assoc_array.hpp
297+
api/data_assoc_array_repn.hpp
262298
api/parameter_array.hpp
263299
api/parameter_assoc_array.hpp
264300
api/parameter_assoc_array_repn.hpp
@@ -273,6 +309,7 @@ install(FILES
273309
compact/expression_sequence.hpp
274310
compact/objective_sequence.hpp
275311
compact/sequence_context.hpp
312+
compact/data_map.hpp
276313
compact/parameter_map.hpp
277314
compact/variable_map.hpp
278315
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/coek/compact

Diff for: lib/coek/coek/api/constraint.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ Constraint& Constraint::operator=(const Constraint& expr)
2929
return *this;
3030
}
3131

32+
Constraint& Constraint::expr(const Constraint& expr)
33+
{
34+
repn = expr.repn;
35+
return *this;
36+
}
37+
38+
Constraint Constraint::expr() const { return *this; }
39+
3240
bool Constraint::active() const { return repn->active; }
3341

3442
void Constraint::activate() { repn->active = true; }

Diff for: lib/coek/coek/api/constraint.hpp

+5
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ class Constraint {
3535

3636
Constraint& operator=(const Constraint& arg);
3737

38+
/** Set the constraint */
39+
Constraint& expr(const Constraint& body);
40+
/** \returns the constraint */
41+
Constraint expr() const;
42+
3843
/** \returns \c true if this is an inequality constraint */
3944
bool is_inequality() const;
4045
/** \returns \c true if this is an equality constraint */

0 commit comments

Comments
 (0)