Skip to content

Commit

Permalink
Merge pull request #87 from sandialabs/dev-weh
Browse files Browse the repository at this point in the history
Various performance improvements
  • Loading branch information
whart222 authored May 28, 2024
2 parents 7bd17b6 + 0730fd1 commit 73a70b9
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 23 deletions.
22 changes: 19 additions & 3 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,40 @@
# This uses Spack to install third-party dependencies in the `_spack` directory.
#
with_python="OFF"
python_exe=""
spack_reinstall=0
spack_dev=0
clang=0
debug="OFF"
spack_home=`pwd`/_spack
with_valgrind=""
while [[ $# -gt 0 ]]; do
case $1 in
--help)
echo "build.sh [--python] [--clang] [--spack-reinstall] [--spack-dev] [--spack-home <dir>] [--help]"
echo "build.sh [--help] [--clang] [--debug] [--python] [--python-exe <file>] [--spack-dev] [--spack-home <dir>] [--spack-reinstall] [--valgrind]"
exit
;;
--python)
with_python="ON"
shift
;;
--python-exe)
python_exe="-DPython_EXECUTABLE=$2"
shift
shift
;;
--clang)
clang=1
shift
;;
--debug)
debug="ON"
shift
;;
--valgrind)
with_valgrind="valgrind"
shift
;;
--spack-reinstall)
spack_reinstall=1
shift
Expand Down Expand Up @@ -87,7 +103,7 @@ else
. ${SPACK_HOME}/share/spack/setup-env.sh
spack env create coekenv
spack env activate coekenv
spack add asl cppad fmt rapidjson catch2 highs
spack add asl cppad fmt rapidjson catch2 highs $with_valgrind
spack install
spack env deactivate
fi
Expand All @@ -102,5 +118,5 @@ echo "Building Coek"
echo ""
mkdir _build
cd _build
cmake -DCMAKE_PREFIX_PATH=${SPACK_HOME}/var/spack/environments/coekenv/.spack-env/view -Dwith_python=${with_python} -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 ..
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 ..
make -j20
3 changes: 2 additions & 1 deletion lib/coek/coek/api/parameter_assoc_array.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ void ParameterAssocArrayRepn::value(double value)
{
parameter_template.value(value);
if (values.size() > 0) {
Expression e(value);
for (auto& var : values)
var.value(value);
var.value(e);
}
}

Expand Down
19 changes: 13 additions & 6 deletions lib/coek/coek/api/variable_assoc_array.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ void VariableAssocArrayRepn::value(double value)
{
variable_template.value(value);
if (values.size() > 0) {
coek::Expression e(value);
for (auto& var : values)
var.value(value);
var.value(e);
}
}

Expand All @@ -64,8 +65,9 @@ void VariableAssocArrayRepn::lower(double value)
{
variable_template.lower(value);
if (values.size() > 0) {
coek::Expression e(value);
for (auto& var : values)
var.lower(value);
var.lower(e);
}
}

Expand All @@ -82,8 +84,9 @@ void VariableAssocArrayRepn::upper(double value)
{
variable_template.upper(value);
if (values.size() > 0) {
coek::Expression e(value);
for (auto& var : values)
var.upper(value);
var.upper(e);
}
}

Expand All @@ -100,26 +103,30 @@ void VariableAssocArrayRepn::bounds(double lb, double ub)
{
variable_template.bounds(lb, ub);
if (values.size() > 0) {
coek::Expression lower(lb);
coek::Expression upper(ub);
for (auto& var : values)
var.bounds(lb, ub);
var.bounds(lower,upper);
}
}

void VariableAssocArrayRepn::bounds(const Expression& lb, double ub)
{
variable_template.bounds(lb, ub);
if (values.size() > 0) {
coek::Expression upper(ub);
for (auto& var : values)
var.bounds(lb, ub);
var.bounds(lb,upper);
}
}

void VariableAssocArrayRepn::bounds(double lb, const Expression& ub)
{
variable_template.bounds(lb, ub);
if (values.size() > 0) {
coek::Expression lower(lb);
for (auto& var : values)
var.bounds(lb, ub);
var.bounds(lower,ub);
}
}

Expand Down
14 changes: 7 additions & 7 deletions test/aml_comparisons/coek/models/jump/fac_array.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@ void fac_array(coek::Model& model, size_t F)
size_t G = F;

// Create variables
auto d = model.add(coek::variable("d")).bounds(0, COEK_INFINITY).value(1.0);
auto d = model.add(coek::variable("d").bounds(0, COEK_INFINITY).value(1.0));

auto y = model.add(coek::variable("y", {F, 2})).bounds(0, 1).value(1.0);
auto y = model.add(coek::variable("y", {F, 2}).bounds(0, 1).value(1.0));

auto z = model.add(coek::variable("z", {G + 1, G + 1, F}))
auto z = model.add(coek::variable("z", {G + 1, G + 1, F})
.bounds(0, 1)
.value(1.0)
.within(coek::VariableTypes::Boolean);
.within(coek::VariableTypes::Boolean));

auto s = model.add(coek::variable("s", {G + 1, G + 1, F})).bounds(0, COEK_INFINITY).value(0);
auto s = model.add(coek::variable("s", {G + 1, G + 1, F}).bounds(0, COEK_INFINITY).value(0));

auto r = model.add(coek::variable("r", {G + 1, G + 1, F, 2}))
auto r = model.add(coek::variable("r", {G + 1, G + 1, F, 2})
.bounds(-COEK_INFINITY, COEK_INFINITY)
.value(0);
.value(0));

// Add objective

Expand Down
4 changes: 2 additions & 2 deletions test/aml_comparisons/coek/models/jump/lqcp_array.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ void lqcp_array(coek::Model& model, size_t n)
// double h2 = dx*dx;
double a = 0.001;

auto y = model.add(coek::variable("y", {m + 1, n + 1})).bounds(0, 1).value(0);
auto u = model.add(coek::variable("u", m + 1)).bounds(-1, 1).value(0);
auto y = model.add(coek::variable("y", {m + 1, n + 1}).bounds(0, 1).value(0));
auto u = model.add(coek::variable("u", m + 1).bounds(-1, 1).value(0));

// OBJECTIVE
// First term
Expand Down
4 changes: 2 additions & 2 deletions test/aml_comparisons/coek/models/jump/lqcp_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ void lqcp_map(coek::Model& model, size_t n)

auto M = coek::RangeSet(0, m);
auto N = coek::RangeSet(0, n);
auto y = model.add(coek::variable("y", M * N)).bounds(0, 1).value(0);
auto u = model.add(coek::variable("u", coek::RangeSet(1, m))).bounds(-1, 1).value(0);
auto y = model.add(coek::variable("y", M * N).bounds(0, 1).value(0));
auto u = model.add(coek::variable("u", coek::RangeSet(1, m)).bounds(-1, 1).value(0));

// OBJECTIVE
// First term
Expand Down
4 changes: 2 additions & 2 deletions test/aml_comparisons/coek/models/misc/pmedian_array.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ void pmedian_array(coek::Model& model, size_t N, size_t P)
d[n][m] = 1.0 + 1.0 / (n + m + 1);
}

auto x = model.add(coek::variable("x", {N, M})).bounds(0, 1).value(0);
auto x = model.add(coek::variable("x", {N, M}).bounds(0, 1).value(0));

auto y = model.add(coek::variable("y", N)).bounds(0, 1).value(0);
auto y = model.add(coek::variable("y", N).bounds(0, 1).value(0));

// obj
auto obj = coek::expression();
Expand Down

0 comments on commit 73a70b9

Please sign in to comment.