Skip to content

Multiplatform builds #36

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 39 commits into from
Feb 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
9497d33
add builds for macOS and Windows, update actions versions tags to com…
Zeitsperre Jun 18, 2024
dec8068
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 18, 2024
1692dcd
trigger workflows
Zeitsperre Jun 18, 2024
4041ad8
Merge remote-tracking branch 'origin/multiplatform-builds' into multi…
Zeitsperre Jun 18, 2024
999d7e2
update actions and dependencies
Zeitsperre Jun 18, 2024
65ca748
typo fix
Zeitsperre Jun 18, 2024
add969e
do not use bash
Zeitsperre Jun 18, 2024
de0d487
try try try again
Zeitsperre Jun 18, 2024
39da365
remove unnecessary steps
Zeitsperre Jun 18, 2024
c92bcb1
final touches
Zeitsperre Jun 18, 2024
a46730e
testing
Zeitsperre Jun 18, 2024
16d42b3
ensure Raven is run on Windows
Zeitsperre Jun 25, 2024
f53b6b8
try again
Zeitsperre Jun 25, 2024
33ddc67
add url endpoints
Zeitsperre Jul 15, 2024
2dd4818
Merge branch 'main' into multiplatform-builds
Zeitsperre Jul 15, 2024
8ef0c09
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 15, 2024
883df24
simplify
Zeitsperre Jul 15, 2024
bad7352
Merge branch 'main' into multiplatform-builds
Zeitsperre Jul 25, 2024
85d154d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 25, 2024
861aa1d
Merge branch 'main' into multiplatform-builds
Zeitsperre Oct 7, 2024
e9fc8ef
Merge branch 'main' into multiplatform-builds
Zeitsperre Jan 21, 2025
fb122a1
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 21, 2025
ce714bd
Merge branch 'main' into multiplatform-builds
Zeitsperre Feb 10, 2025
17bef00
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 10, 2025
24d6be6
add JetBrains to .gitignore, install NetCDF
Zeitsperre Feb 10, 2025
ce57b93
allow sudo, use homebrew action
Zeitsperre Feb 10, 2025
4a49288
use proper images
Zeitsperre Feb 10, 2025
5980a90
fail-fast false
Zeitsperre Feb 10, 2025
6ceca25
fix Raven call
Zeitsperre Feb 10, 2025
209e8c1
fix tests
Zeitsperre Feb 10, 2025
c19b178
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 10, 2025
2edb855
use a build dir
Zeitsperre Feb 10, 2025
eb25aea
use a build dir
Zeitsperre Feb 10, 2025
f62bbdc
set standard for C++11
Zeitsperre Feb 10, 2025
55bcbf8
Merge branch 'main' into multiplatform-builds
Zeitsperre Feb 12, 2025
2ee6a79
disable standalone definition
Zeitsperre Feb 12, 2025
99edc91
find hdf5 explicitly, mute NetCDF5 find package warning
Zeitsperre Feb 12, 2025
6658965
mute deprecation warnings
Zeitsperre Feb 12, 2025
e4e34e1
only mute deprecation warnings for GCC
Zeitsperre Feb 12, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/first_pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
name: Welcome
runs-on: ubuntu-latest
steps:
- uses: actions/github-script@v6
- uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
with:
script: |
// Get a list of all issues created by the PR opener
Expand Down
162 changes: 130 additions & 32 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,48 +15,146 @@ jobs:
run:
shell: bash
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Harden Runner
uses: step-security/harden-runner@17d0e2bd7d51742c71671bd19fa12bdc9d40a3d6 # v2.8.1
with:
disable-sudo: false
egress-policy: block
allowed-endpoints: >
azure.archive.ubuntu.com:80
esm.ubuntu.com:443
files.pythonhosted.org:443
github.com:443
motd.ubuntu.com:443
packages.microsoft.com:443
pypi.org:443

- name: Checkout Repository
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
with:
persist-credentials: false

- name: Install linters
run: |
sudo apt-get update
sudo apt-get install uncrustify cppcheck iwyu
- uses: actions/setup-python@v4
- name: Install pre-commit

- name: Set up Python3
uses: actions/setup-python@82c7e631bb3cdc910f68e0081d67478d79c6982d # v5.1.0
with:
python-version: '3.x'

- name: Run pre-commit hooks
uses: pre-commit/action@2c7b3805fd2a0fd8c1884dcaebf91fc102a13ecd # v3.0.1

build-netcdf:
name: Build (${{ matrix.build_type }}; ${{ matrix.os }}; NetCDF=True)
needs: lint
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ "ubuntu-latest", "macos-latest" ]
build_type: [ "Debug", "Release" ]
steps:
- name: Harden Runner
uses: step-security/harden-runner@17d0e2bd7d51742c71671bd19fa12bdc9d40a3d6 # v2.8.1
with:
disable-sudo: false
egress-policy: block
allowed-endpoints: >
azure.archive.ubuntu.com:80
esm.ubuntu.com:443
github.com:443
motd.ubuntu.com:443
packages.microsoft.com:443
raw.githubusercontent.com:443

- name: Checkout Repository
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
with:
persist-credentials: false

- name: Install NetCDF (Ubuntu/apt)
if: matrix.os == 'ubuntu-latest'
run: |
python -m pip install --upgrade pip
python -m pip install pre-commit
- name: Run pre-commit
sudo apt-get update
sudo apt-get install -y libnetcdf-dev
- name: Install NetCDF4 (macOS/homebrew)
if: (matrix.os == 'macos-latest') && (!matrix.conda)
uses: tecolicom/actions-use-homebrew-tools@b9c066b79607fa3d71e0be05d7003bb75fd9ff34 # v1.3.0
with:
tools: netcdf
cache: "yes"

- name: Fetch NetCDF CMake script
run: |
pre-commit run --all-files
wget https://raw.githubusercontent.com/Kitware/VTK/master/CMake/FindNetCDF.cmake -P cmake

- name: Build
id: build
run: |
mkdir build
cd build
cmake ..
cmake --build . --config ${{ matrix.build_type }} -j 3 --verbose

- name: Run tests
if: steps.build.outcome == 'success'
run: |
./build/Raven
./build/Raven -v

build:
name: Build RavenHydroFramework binary (${{ matrix.build_type }})
runs-on: ubuntu-latest
name: Build (${{ matrix.build_type }}; ${{ matrix.os }}; NetCDF=False)
needs: lint
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
build_type: [Debug, Release]
os: [ ubuntu-latest, macos-latest, windows-latest ]
build_type: [ Debug, Release ]
defaults:
run:
shell: bash
shell: bash -l {0}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install libnetcdf-dev build-essential cmake
- name: Fetch NetCDF CMake script
run: |
wget https://raw.githubusercontent.com/Kitware/VTK/master/CMake/FindNetCDF.cmake -P cmake
- name: Build
id: build
continue-on-error: true
run: |
cmake . -DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
make -j4
- name: Run tests
if: steps.build.outcome == 'success'
run: |
./Raven
./Raven -v
- name: Harden Runner
uses: step-security/harden-runner@17d0e2bd7d51742c71671bd19fa12bdc9d40a3d6 # v2.8.1
with:
disable-sudo: true
egress-policy: block
allowed-endpoints: >
azure.archive.ubuntu.com:80
esm.ubuntu.com:443
github.com:443
motd.ubuntu.com:443
objects.githubusercontent.com:443
packages.microsoft.com:443

- name: Checkout Repository
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
with:
persist-credentials: false

- name: Install dependencies (Windows)
if: matrix.os == 'windows-latest'
uses: lukka/get-cmake@2bcb1a4c14ab154443cc740dced0f9b6a8fb2b59 # v3.29.6

- name: Build
id: build
run: |
mkdir build
cd build
cmake ..
cmake --build . --config ${{ matrix.build_type }} -j 3 --verbose

- name: Run tests (Windows)
if: ${{ matrix.os == 'windows-latest' && steps.build.outcome == 'success' }}
run: |
./build/${{ matrix.build_type }}/Raven.exe
./build/${{ matrix.build_type }}/Raven.exe -v
- name: Run tests (Ubuntu/macOS)
if: ${{ matrix.os != 'windows-latest' && steps.build.outcome == 'success' }}
run: |
./build/Raven
./build/Raven -v
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,6 @@ Makefile
# Runtime artifacts
Raven
Raven_errors.txt

# JetBrains
.idea
32 changes: 25 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
cmake_minimum_required(VERSION 3.20)
# made with help from Zhu Liang-Jun of IGSNRR in Beijing
# modified for GitHub by Trevor James Smith of Ouranos in Montreal
# modified for GitHub and C++11 by Trevor James Smith of Ouranos in Montreal
# modified for lpsolve support by Maxim Krassovski of DFO

# Set the C++ standard to C++11
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
SET(CMAKE_CXX_EXTENSIONS OFF)

# optional cmake command line arguments (e.g, "cmake -D COMPILE_LIB=ON" .)
option(COMPILE_LIB "If ON, will create a dynamic lib file (default: OFF)" OFF)
option(COMPILE_EXE "If ON, will create a executable file (default: ON)" ON)
option(PYTHON, "If ON, will create a share library for python (default: OFF)" OFF)
option(LPSOLVE,"If ON, will link to lp_solve optimization library (default: OFF)" OFF)
option(LPSOLVE, "If ON, will link to lp_solve optimization library (default: OFF)" OFF)

# Setup Project
PROJECT(Raven CXX)
Expand All @@ -17,7 +22,14 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")

# Find NetCDF
find_package(NetCDF) #may also be 'netCDF'
find_package(netCDF)
if (NOT NetCDF_FOUND)
message(STATUS "NetCDF not found, trying netCDF")
find_package(netCDF)
endif()

# Find HDF5
find_package(HDF5)

# find header & source
file(GLOB HEADER "src/*.h")
file(GLOB SOURCE "src/*.cpp")
Expand Down Expand Up @@ -45,18 +57,21 @@ if(COMPILE_EXE)
${SOURCE}
${HEADER}
)
target_compile_definitions(Raven PUBLIC STANDALONE)
set_target_properties(Raven PROPERTIES LINKER_LANGUAGE CXX)

# Remove deprecation warnings for GCC
IF(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
target_compile_options(Raven PRIVATE "-Wno-deprecated")
message(STATUS "Modified compile flags with '-Wno-deprecated'")
ENDIF()

if(LPSOLVE)
target_link_directories(Raven PRIVATE lib/lp_solve) # where liblpsolve55.so is located
target_link_libraries(Raven lpsolve55)
add_definitions(-D_LPSOLVE_)
endif()
endif()

source_group("Header Files" FILES ${HEADER})
source_group("Source Files" FILES ${SOURCE})

if(NETCDF_FOUND)
add_definitions(-Dnetcdf)
include_directories(${NetCDF_INCLUDE_DIRS})
Expand All @@ -67,6 +82,9 @@ elseif(netCDF_FOUND)
target_link_libraries(Raven netcdf)
endif()

source_group("Header Files" FILES ${HEADER})
source_group("Source Files" FILES ${SOURCE})

# unset cmake variables to avoid polluting the cache
unset(COMPILE_LIB CACHE)
unset(COMPILE_EXE CACHE)
8 changes: 4 additions & 4 deletions src/Assimilate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ void CModel::PrepareAssimilation(const optStruct &Options,const time_struct &tt)
_aDAoverride [p]=true;
_aDAobsQ [p]=Qobs;
_aDADrainSum [p]=0.0; //??? maybe doesnt matter
if (pdown != DOESNT_EXIST) {
if (pdown != DOESNT_EXIST) {
_aDADrainSum [pdown]+=_pSubBasins[p]->GetDrainageArea(); //DOES THIS HANDLE NESTING RIGHT?
}
}
Expand All @@ -182,17 +182,17 @@ void CModel::PrepareAssimilation(const optStruct &Options,const time_struct &tt)
_aDAlength [p]=0.0;
_aDAoverride [p]=false;
_aDAobsQ [p]=0.0;
if (pdown != DOESNT_EXIST) {
if (pdown != DOESNT_EXIST) {
_aDADrainSum[pdown] += _aDADrainSum[p];
}
}
ObsExists=true;
break; //avoids duplicate observations
}
}
}
}
else {
if (pdown != DOESNT_EXIST) {
if (pdown != DOESNT_EXIST) {
_aDADrainSum[pdown] += _aDADrainSum[p];
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/DemandExpressionHandling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -958,13 +958,13 @@ expressionStruct *CDemandOptimizer::ParseExpression(const char **s,
return tmp;
}
//////////////////////////////////////////////////////////////////
/// \brief Parses :Condition within management goal or workflow variable definition
/// \brief Parses :Condition within management goal or workflow variable definition
/// \param s [in] - array of strings of [size: Len]
/// \param Len [in] - length of string array
/// \param lineno [in] - line number of original expression in input file filename, referenced in errors
/// \param filename [in] - name of input file, referenced in errors
/// \returns exp_condition: a pointer to an expression condition variable
///
///
/// \todo[funct]: Would it be better to support @date(), @between, @day_of_year() in general expression??
/// :Condition !Q32[0] < 300 + @ts(myTs,0)
/// :Condition DATE IS_BETWEEN 1975-01-02 and 2010-01-02
Expand All @@ -978,13 +978,13 @@ expressionStruct *CDemandOptimizer::ParseExpression(const char **s,
/// :Condition DAY_OF_YEAR IS_BETWEEN Apr-1 Aug-1 //\todo [NOT YET SUPPORTED]
/// :Condition @is_between(DAY_OF_YEAR,300,20) = 1 // \todo [NOT YET SUPPORTED]
//
exp_condition* CDemandOptimizer::ParseCondition(const char** s, const int Len, const int lineno, const string filename) const
exp_condition* CDemandOptimizer::ParseCondition(const char** s, const int Len, const int lineno, const string filename) const
{
bool badcond=false;
exp_condition *pCond = new exp_condition();
pCond->dv_name=s[1];
const optStruct *Options=_pModel->GetOptStruct();

bool is_exp=false;
for (int i = 2; i < Len; i++) {
if ((s[i][0]=='+') || (s[i][0]=='-') || (s[i][0]=='*') || (s[i][0]=='/') || (s[i][0]=='=') || (s[i][0]=='<') || (s[i][0]=='>')){
Expand Down Expand Up @@ -1021,7 +1021,7 @@ exp_condition* CDemandOptimizer::ParseCondition(const char** s, const int Len, c
char tmp =pCond->dv_name[1];
string tmp2=pCond->dv_name.substr(2);
char code=pCond->dv_name[1];
if ((code=='Q') || (code=='h') || (code=='I')) //subbasin state decision variable
if ((code=='Q') || (code=='h') || (code=='I')) //subbasin state decision variable
{
long long SBID=s_to_ll(tmp2.c_str());
if (_pModel->GetSubBasinByID(SBID) == NULL) {
Expand Down Expand Up @@ -1147,7 +1147,7 @@ bool CDemandOptimizer::CheckOpRegimeConditions(const op_regime *pOperRegime, con
}
else {//handle user specified DVs and workflow variables
int i=GetUserDVIndex(pCond->dv_name);
if (i != DOESNT_EXIST) //decision variable
if (i != DOESNT_EXIST) //decision variable
{
dv_value =_pDecisionVars[i]->value;
}
Expand Down
8 changes: 4 additions & 4 deletions src/DemandOptimization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ void CDemandOptimizer::AddUserDecisionVar(const decision_var* pDV)
//////////////////////////////////////////////////////////////////
/// \brief disables stage discharge curve handling for reservoir in subbasin p
//
void CDemandOptimizer::OverrideSDCurve(const int p)
void CDemandOptimizer::OverrideSDCurve(const int p)
{
_aDisableSDCurve[p]=true;
}
Expand Down Expand Up @@ -424,7 +424,7 @@ bool CDemandOptimizer::VariableNameExists(const string &name) const
for (int i = 0; i < _nUserConstants; i++) {
if (_aUserConstNames[i]==name){return true;}
}

if (GetUnitConversion(name)!=RAV_BLANK_DATA){return true;}

return false;
Expand Down Expand Up @@ -890,7 +890,7 @@ void CDemandOptimizer::InitializePostRVMRead(CModel* pModel, const optStruct& Op
cout<<" "<<i<<" [WORKFLOWVAR]: "<<_pWorkflowVars[i]->name<<endl;
for (int k=0; k<_pWorkflowVars[i]->nOperRegimes; k++)
{

cout<<" +oper regime: "<<_pWorkflowVars[i]->pOperRegimes[k]->reg_name<<endl;
cout<<" +expression: "<<_pWorkflowVars[i]->pOperRegimes[k]->pExpression->origexp<<endl;
comparison ctype=_pWorkflowVars[i]->pOperRegimes[k]->pExpression->compare;
Expand Down Expand Up @@ -1644,7 +1644,7 @@ void CDemandOptimizer::SolveDemandProblem(CModel *pModel, const optStruct &Optio
retval = lp_lib::add_constraintex(pLinProg,i,row_val,col_ind,ROWTYPE_EQ,RHS);
ExitGracefullyIf(retval==0,"SolveDemandProblem::Error adding mass balance constraint",RUNTIME_ERR);
IncrementAndSetRowName(pLinProg,rowcount,"reach_MB_"+to_string(pSB->GetID()));

lpsbrow[p]=lp_lib::get_Nrows(pLinProg);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/DemandOptimization.h
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ class CDemandOptimizer
void OverrideSDCurve (const int p);

void AddGoalOrConstraint (const managementGoal *pGoal);

void AddUserDecisionVar (const decision_var *pDV);
void SetUserDecisionVarBounds(const string name, const double &min, const double &max);
void AddUserConstant (const string name, const double &val);
Expand Down
Loading