Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
dweindl committed Jul 10, 2024
1 parent 64d2c59 commit 84a3eb9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
1 change: 1 addition & 0 deletions python/tests/test_swig_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,7 @@ def test_python_exceptions(sbml_example_presimulation_module):
rdata = amici.runAmiciSimulation(model, solver)
assert rdata.status == amici.AMICI_FIRST_RHSFUNC_ERR

edata = amici.ExpData(1, 1, 1, [1])
rdatas = amici.runAmiciSimulations(
model, solver, [edata, edata], failfast=True, num_threads=1
)
Expand Down
29 changes: 20 additions & 9 deletions src/amici.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,17 +282,28 @@ std::vector<std::unique_ptr<ReturnData>> runAmiciSimulations(
#pragma omp parallel for num_threads(num_threads)
#endif
for (int i = 0; i < (int)edatas.size(); ++i) {
auto mySolver = std::unique_ptr<Solver>(solver.clone());
auto myModel = std::unique_ptr<Model>(model.clone());

/* if we fail we need to write empty return datas for the python
interface */
if (skipThrough) {
ConditionContext conditionContext(myModel.get(), edatas[i]);
// must catch exceptions in parallel section to avoid termination
try {
auto mySolver = std::unique_ptr<Solver>(solver.clone());
auto myModel = std::unique_ptr<Model>(model.clone());

/* if we fail we need to write empty return datas for the python
interface */
if (skipThrough) {
ConditionContext conditionContext(myModel.get(), edatas[i]);
results[i]
= std::unique_ptr<ReturnData>(new ReturnData(solver, model)
);
} else {
results[i] = runAmiciSimulation(*mySolver, edatas[i], *myModel);
}
} catch (std::exception const& ex) {
results[i]
= std::unique_ptr<ReturnData>(new ReturnData(solver, model));
} else {
results[i] = runAmiciSimulation(*mySolver, edatas[i], *myModel);
results[i]->status = AMICI_ERROR;
results[i]->messages.push_back(
LogItem(LogSeverity::error, "OTHER", ex.what())
);
}

skipThrough |= failfast && results[i]->status < 0;
Expand Down

0 comments on commit 84a3eb9

Please sign in to comment.