Skip to content

Commit

Permalink
Fix capturing SUNDIALS warnings after 7.1.1 upgrade (#2551)
Browse files Browse the repository at this point in the history
Disable SUNDIALS's warning-handling through `SUNLogger`. Instead pipe everything both errors and warnings through the provided`SUNErrHandlerFn`.

For details, see #2550.

Fixes #2550.

This also corrects the error message formatting - file path and line numbers for debug builds, but omitted in release builds - which was inverted before.
  • Loading branch information
dweindl authored Oct 18, 2024
1 parent c8778e5 commit 8253a97
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 1 deletion.
3 changes: 3 additions & 0 deletions ThirdParty/sundials/src/cvodes/cvodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -9930,6 +9930,8 @@ void cvProcessError(CVodeMem cv_mem, int error_code, int line, const char* func,
break;
}

/* AMICI: https://github.com/AMICI-dev/AMICI/issues/2550 */
#ifdef AMICI_SUNLOGGER_WARNINGS
if (error_code == CV_WARNING)
{
#if SUNDIALS_LOGGING_LEVEL >= SUNDIALS_LOGGING_WARNING
Expand All @@ -9940,6 +9942,7 @@ void cvProcessError(CVodeMem cv_mem, int error_code, int line, const char* func,
#endif
break;
}
#endif

/* Call the SUNDIALS main error handler */
SUNHandleErrWithMsg(line, func, file, msg, error_code, cv_mem->cv_sunctx);
Expand Down
3 changes: 3 additions & 0 deletions ThirdParty/sundials/src/idas/idas.c
Original file line number Diff line number Diff line change
Expand Up @@ -8779,6 +8779,8 @@ void IDAProcessError(IDAMem IDA_mem, int error_code, int line, const char* func,
break;
}

/* AMICI: https://github.com/AMICI-dev/AMICI/issues/2550 */
#ifdef AMICI_SUNLOGGER_WARNINGS
if (error_code == IDA_WARNING)
{
#if SUNDIALS_LOGGING_LEVEL >= SUNDIALS_LOGGING_WARNING
Expand All @@ -8789,6 +8791,7 @@ void IDAProcessError(IDAMem IDA_mem, int error_code, int line, const char* func,
#endif
break;
}
#endif

/* Call the SUNDIALS main error handler */
SUNHandleErrWithMsg(line, func, file, msg, error_code, IDA_mem->ida_sunctx);
Expand Down
1 change: 1 addition & 0 deletions include/amici/defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ constexpr double pi = M_PI;
//
// NOTE: When adding / removing / renaming return codes,
// please update simulation_status_to_str_map in amici.h
constexpr int AMICI_WARNING= 99;
constexpr int AMICI_RECOVERABLE_ERROR= 1;
constexpr int AMICI_UNRECOVERABLE_ERROR= -10;
constexpr int AMICI_TOO_MUCH_WORK= -1;
Expand Down
1 change: 1 addition & 0 deletions src/amici.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ std::map<int, std::string> simulation_status_to_str_map = {
{AMICI_NOT_RUN, "AMICI_NOT_RUN"},
{AMICI_LSETUP_FAIL, "AMICI_LSETUP_FAIL"},
{AMICI_FIRST_QRHSFUNC_ERR, "AMICI_FIRST_QRHSFUNC_ERR"},
{AMICI_WARNING, "AMICI_WARNING"},
};

std::unique_ptr<ReturnData> runAmiciSimulation(
Expand Down
2 changes: 1 addition & 1 deletion src/solver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ void wrapErrHandlerFn(
std::is_same<SUNErrCode, int>::value, "Must update format string"
);
// for debug builds, include full file path and line numbers
#ifdef NDEBUG
#ifndef NDEBUG
snprintf(msg_buffer, BUF_SIZE, "%s:%d: %s (%d)", file, line, msg, err_code);
#else
snprintf(msg_buffer, BUF_SIZE, "%s", msg);
Expand Down
4 changes: 4 additions & 0 deletions src/solver_cvodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ static_assert(
amici::AMICI_FIRST_QRHSFUNC_ERR == CV_FIRST_QRHSFUNC_ERR,
"AMICI_FIRST_QRHSFUNC_ERR != CV_FIRST_QRHSFUNC_ERR"
);
static_assert(
amici::AMICI_WARNING == CV_WARNING,
"AMICI_WARNING != CV_WARNING"
);

/*
* The following static members are callback function to CVODES.
Expand Down
4 changes: 4 additions & 0 deletions src/solver_idas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ static_assert(
amici::AMICI_IDAS_CONSTR_FAIL == IDA_CONSTR_FAIL,
"AMICI_IDAS_CONSTR_FAIL != IDA_CONSTR_FAIL"
);
static_assert(
amici::AMICI_WARNING == IDA_WARNING,
"AMICI_WARNING != IDA_WARNING"
);

/*
* The following static members are callback function to IDAS.
Expand Down

0 comments on commit 8253a97

Please sign in to comment.