Skip to content

Commit

Permalink
Merge pull request #24 from sandialabs/dev
Browse files Browse the repository at this point in the history
Preparing for 1.3.0 release
  • Loading branch information
whart222 authored Feb 10, 2023
2 parents 4e3052d + 4ddf6ba commit 9964f66
Show file tree
Hide file tree
Showing 123 changed files with 8,046 additions and 1,120 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,23 @@ jobs:
run: |
cd build
make test
coek-build-and-test-with-cpp14:
runs-on: ubuntu-latest
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v3
- name: run cmake
run: |
mkdir build
cd build
cmake -DCMAKE_CXX_STANDARD=14 -Dwith_python=OFF -Dwith_tests=ON -Dwith_debug=ON ..
- name: build
run: |
cd build
make install_tpls
make
- name: test
run: |
cd build
make test
4 changes: 0 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@
# -----------------------------------
# ignore top level build directory
/build/
# ignore Catch2 directory in top level third_party directory
/third_party/Catch2/
# ignore CppAD directory in top level third_party directory
/third_party/CppAD/

_build
/.vs
Expand Down
52 changes: 31 additions & 21 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.12)
cmake_minimum_required(VERSION 3.13)
project(CoekProject)

set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake;${CMAKE_MODULE_PATH})
Expand Down Expand Up @@ -39,11 +39,11 @@ add_subdirectory(tpl)

add_custom_target(install_tpls
DEPENDS _install_tpls
COMMAND ${CMAKE_COMMAND} -Dwith_pybind11=ON -Dwith_catch2=ON -Dwith_fmtlib=ON -Dwith_cppad=ON -Dwith_rapidjson=ON ${PROJECT_SOURCE_DIR}
COMMAND ${CMAKE_COMMAND} -Dwith_pybind11=ON -Dwith_catch2=ON -Dwith_fmtlib=ON -Dwith_cppad=ON -Dwith_rapidjson=ON -Dwith_asl=ON ${PROJECT_SOURCE_DIR}
)
add_custom_target(install_tpl
DEPENDS _install_tpls
COMMAND ${CMAKE_COMMAND} -Dwith_pybind11=ON -Dwith_catch2=ON -Dwith_fmtlib=ON -Dwith_cppad=ON -Dwith_rapidjson=ON ${PROJECT_SOURCE_DIR}
COMMAND ${CMAKE_COMMAND} -Dwith_pybind11=ON -Dwith_catch2=ON -Dwith_fmtlib=ON -Dwith_cppad=ON -Dwith_rapidjson=ON -Dwith_asl=ON ${PROJECT_SOURCE_DIR}
)

##################### Options #####################
Expand All @@ -61,24 +61,6 @@ option(with_tests "Build tests" OFF)
option(with_docs "Build documentation" OFF)
option(with_python "Build/Install Python libs" ${Python_FOUND})

message("Initial Configuration Options")
# Options defined here
message("-- with_debug: ${with_debug}")
message("-- with_verbose: ${with_verbose}")
message("-- with_gcov: ${with_gcov}")
message("-- with_gprof: ${with_gprof}")
message("-- with_caliper: ${with_caliper}")
message("-- with_tests: ${with_tests}")
message("-- with_docs: ${with_docs}")
message("-- with_python: ${with_python}")
# Options defined in tpl
message("-- with_catch2: ${with_catch2}")
message("-- with_cppad: ${with_cppad}")
message("-- with_pybind11: ${with_pybind11}")
message("-- with_cppyy: ${with_cppyy}")
message("-- with_rapidjson: ${with_rapidjson}")
message("-- with_fmtlib: ${with_fmtlib}")

##################### Checks for compiler #####################

message("Revised Configuration Options")
Expand Down Expand Up @@ -118,6 +100,34 @@ else()
MESSAGE("-- C++ version: C++${CMAKE_CXX_STANDARD}")
endif()

if (CMAKE_CXX_STANDARD LESS 17)
message("DISABLING FMTLIB")
set(with_fmtlib OFF)
endif()

##################### General Configuration Options #####################

message("Initial Configuration Options")
# Options defined here
message("-- with_debug: ${with_debug}")
message("-- with_verbose: ${with_verbose}")
message("-- with_gcov: ${with_gcov}")
message("-- with_gprof: ${with_gprof}")
message("-- with_caliper: ${with_caliper}")
message("-- with_tests: ${with_tests}")
message("-- with_docs: ${with_docs}")
message("-- with_python: ${with_python}")
# Options defined in tpl
message("-- with_asl: ${with_asl}")
message("-- with_catch2: ${with_catch2}")
message("-- with_cppad: ${with_cppad}")
message("-- with_cppyy: ${with_cppyy}")
message("-- with_fmtlib: ${with_fmtlib}")
message("-- with_pybind11: ${with_pybind11}")
message("-- with_rapidjson: ${with_rapidjson}")

##################### Other Configuraton Options #####################

if (with_gcov)
if (CMAKE_CXX_COMPILER_ID MATCHES GNU)
else()
Expand Down
10 changes: 10 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@
Here we list changes of Coek. More detailed information about incremental changes can be found in the
[commit history](https://github.com/sandialabs/coek/commits).

## 1.3

* Added ASL autograd functionality
* Various fixes in expression management logic.
* Improving support for C++14
* Updates to support Python 3.11
* Switch to use SHA256 hashes for third-party packages
* Adding expression simplifier logic
* Fixing many bugs with NL writer

## 1.2

* Added the SubExpression object, which is used to denote
Expand Down
2 changes: 1 addition & 1 deletion app/demos/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ PROJECT(demos)
#
# For now, let's just assume we have C++17
#
set(CMAKE_CXX_STANDARD 17)
#set(CMAKE_CXX_STANDARD 17)

MESSAGE("-- With Gurobi Solver: ${with_gurobi}")
if(with_gurobi)
Expand Down
2 changes: 2 additions & 0 deletions app/demos/demo1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ coek::Model knapsack(size_t N)

auto model = coek::Model();

#if __cpp_lib_variant
auto x = coek::variable(N).bounds(0, 1).value(0);
model.add(x);

Expand All @@ -36,6 +37,7 @@ coek::Model knapsack(size_t N)
auto con = coek::expression();
for (size_t n : coek::range(N)) con += w[n] * x(n);
model.add(con <= W);
#endif

return model;
}
Expand Down
29 changes: 16 additions & 13 deletions lib/coek/coek/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ SET(sources
ast/visitor_symdiff.cpp
ast/visitor_mutable_values.cpp
ast/visitor_variables.cpp
ast/visitor_simplify.cpp
ast/visitor_eval.cpp
ast/varray.cpp
#ast/varray.cpp
api/constants.cpp
api/expression.cpp
api/expression_visitor.cpp
Expand All @@ -34,7 +35,7 @@ SET(sources
autograd/autograd.cpp
abstract/expr_rule.cpp
)
if (CMAKE_CXX_STANDARD GREATER_EQUAL 14)
if (CMAKE_CXX_STANDARD GREATER_EQUAL 17)
list(APPEND sources
ast/compact_terms.cpp
api/parameter_assoc_array.cpp
Expand Down Expand Up @@ -104,9 +105,7 @@ endif()
# ADMODEL OPTIONS
#

#
# CppAD LIBRARY
#
if(with_cppad)
list(APPEND sources
autograd/cppad_repn.cpp)
Expand All @@ -115,11 +114,14 @@ if(with_cppad)
endif()

# ASL LIBRARY
# if(NOT with_cppad AND with_asl)
# MESSAGE("-- Building Source with AD: ASL")
# list(APPEND sources
# autograd/asl_model.cpp)
# endif()
if(with_asl)
list(APPEND sources
autograd/asl_repn.cpp)
list(APPEND coek_compile_options "-DWITH_ASL")
list(APPEND coek_include_directories ${CMAKE_INSTALL_PREFIX}/include/asl)
list(APPEND coek_link_directories ${CMAKE_INSTALL_PREFIX}/lib)
list(APPEND coek_link_libraries asl)
endif()

# Default AD LIBRARY
# if(NOT with_cppad AND NOT with_asl)
Expand Down Expand Up @@ -197,12 +199,13 @@ target_include_directories(coek
PUBLIC
${coek_include_directories})
target_link_libraries(coek PUBLIC ${coek_link_libraries})
target_link_directories(coek PUBLIC ${coek_link_directories})
set_property(TARGET coek PROPERTY INTERFACE_LINK_LIBRARIES ${coek_link_libraries})

if (WIN32)
target_link_libraries(coek ${coek_link_libraries})
target_link_directories(coek PRIVATE ${coek_link_directories})
endif()
#if (WIN32)
# target_link_libraries(coek ${coek_link_libraries})
# target_link_directories(coek PRIVATE ${coek_link_directories})
#endif()

#
# make install
Expand Down
33 changes: 10 additions & 23 deletions lib/coek/coek/api/expression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,18 +299,21 @@ Variable variable(const std::string& name)

Expression::Expression() : repn(ZEROCONST) {}

Expression::Expression(const ParameterRepn& _repn) : repn(_repn) {}
Expression::Expression(const IndexParameterRepn& _repn) : repn(_repn) {}
// Expression::Expression(const ParameterRepn& _repn) : repn(_repn) {}

// Expression::Expression(const IndexParameterRepn& _repn) : repn(_repn) {}

Expression::Expression(const VariableRepn& _repn) : repn(_repn) {}

Expression::Expression(const ExpressionRepn& _repn) : repn(_repn) {}

Expression::Expression(ExpressionRepn&& _repn) : repn(_repn) {}

Expression::Expression(ParameterRepn&& _repn) : repn(_repn) {}
// Expression::Expression(ParameterRepn&& _repn) : repn(_repn) {}

Expression::Expression(IndexParameterRepn&& _repn) : repn(_repn) {}
// Expression::Expression(IndexParameterRepn&& _repn) : repn(_repn) {}

Expression::Expression(VariableRepn&& _repn) : repn(_repn) {}
Expression::Expression(VariableRepn&& _repn) : repn(_repn) {} // TODO - why isn't this covered?

Expression::Expression(double value) { repn = CREATE_POINTER(ConstantTerm, value); }

Expand Down Expand Up @@ -541,6 +544,7 @@ Expression expression(const Variable& arg) { return coek::Expression(arg); }

SubExpression::SubExpression() { repn = CREATE_POINTER(SubExpressionTerm, ZEROCONST); }

/*
SubExpression::SubExpression(double value)
{
repn = CREATE_POINTER(SubExpressionTerm, CREATE_POINTER(ConstantTerm, value));
Expand All @@ -550,6 +554,7 @@ SubExpression::SubExpression(int value)
{
repn = CREATE_POINTER(SubExpressionTerm, CREATE_POINTER(ConstantTerm, value));
}
*/

SubExpression::SubExpression(const Parameter& arg)
{
Expand Down Expand Up @@ -602,24 +607,6 @@ std::list<std::string> SubExpression::to_list() const
return tmp;
}

Expression SubExpression::diff(const Variable& var) const
{
std::map<std::shared_ptr<VariableTerm>, expr_pointer_t> ans;
symbolic_diff_all(repn, ans);
Expression e;
if (ans.find(var.repn) != ans.end()) e = ans[var.repn];
return e;
}

Expression SubExpression::expand()
{
#ifdef COEK_WITH_COMPACT_MODEL
return convert_expr_template(repn);
#else
return *this;
#endif
}

SubExpression& SubExpression::operator+=(int arg)
{
Expression e(arg);
Expand Down
22 changes: 6 additions & 16 deletions lib/coek/coek/api/expression.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,12 +306,12 @@ class Expression {
/** Implicit construction of an Expression from a SubExpression */
Expression(const SubExpression& arg);

Expression(const ParameterRepn& _repn);
Expression(const IndexParameterRepn& _repn);
// Expression(const ParameterRepn& _repn);
// Expression(const IndexParameterRepn& _repn);
Expression(const VariableRepn& _repn);
Expression(const ExpressionRepn& _repn);
Expression(ParameterRepn&& _repn);
Expression(IndexParameterRepn&& _repn);
// Expression(ParameterRepn&& _repn);
// Expression(IndexParameterRepn&& _repn);
Expression(VariableRepn&& _repn);
Expression(ExpressionRepn&& _repn);

Expand Down Expand Up @@ -414,9 +414,9 @@ class SubExpression {
/** Constructs a SubExpression without defining its value */
SubExpression();
/** Explict construction of a SubExpression from a double */
explicit SubExpression(double value);
// explicit SubExpression(double value);
/** Explict construction of a SubExpression from an integer */
explicit SubExpression(int value);
// explicit SubExpression(int value);
/** Implicit construction of a SubExpression from a Parameter */
SubExpression(const Parameter& arg);
/** Implicit construction of a SubExpression from an IndexParameter */
Expand Down Expand Up @@ -449,13 +449,6 @@ class SubExpression {

/** \returns a list representation of the expression */
std::list<std::string> to_list() const;
/**
* Create an expression that computes the partial derivative relative to a specified variable.
*
* \param var - The variable that will be used to compute the partial derivative
* \returns an expression that computes the partial derivative
*/
Expression diff(const Variable& var) const;

/** Add an integer to the expression */
SubExpression& operator+=(int arg);
Expand Down Expand Up @@ -516,9 +509,6 @@ class SubExpression {
SubExpression& operator/=(const Expression& arg);
/** Divide the expression by a SubExpression */
SubExpression& operator/=(const SubExpression& arg);

/** \returns an expanded Expression */
Expression expand();
};

SubExpression subexpression();
Expand Down
Loading

0 comments on commit 9964f66

Please sign in to comment.