Skip to content

Commit 53032d6

Browse files
authored
Merge pull request #243 from ICB-DCM/feature_more_adjoint_options
Feature more adjoint options
2 parents a95a2d8 + 1ededdc commit 53032d6

File tree

8 files changed

+46
-11
lines changed

8 files changed

+46
-11
lines changed

@amioption/amioption.m

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@
1313
rtol = 1e-8;
1414
% maximum number of integration steps
1515
maxsteps = 1e4;
16+
% absolute integration tolerace
17+
quad_atol = 1e-12;
18+
% relative integration tolerace
19+
quad_rtol = 1e-8;
20+
% maximum number of integration steps
21+
maxstepsB = 0;
1622
% index of parameters for which the sensitivities are computed
1723
sens_ind = double.empty();
1824
% index of states for which positivity should be enforced

include/udata.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define AMICI_UDATA_H
33

44
#include "include/amici_defines.h"
5+
#include "include/symbolic_functions.h" //getNaN
56
#include <cmath>
67
#include <vector>
78

@@ -319,6 +320,15 @@ class UserData {
319320
/** maximum number of allowed integration steps */
320321
int maxsteps = 0;
321322

323+
/** absolute tolerances for backward quadratures */
324+
double quad_atol = 1e-12;
325+
326+
/** relative tolerances for backward quadratures */
327+
double quad_rtol = 1e-8;
328+
329+
/** maximum number of allowed integration steps for backward problem */
330+
int maxstepsB = 0;
331+
322332
/** flag indicating whether sensitivities are supposed to be computed */
323333
AMICI_sensi_order sensi = AMICI_SENSI_ORDER_NONE;
324334

src/amici_interface_matlab.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,9 @@ UserData *userDataFromMatlabCall(const mxArray *prhs[], int nrhs) {
124124
readOptionScalarDouble(atol);
125125
readOptionScalarDouble(rtol);
126126
readOptionScalarInt(maxsteps, int);
127+
readOptionScalarDouble(quad_atol);
128+
readOptionScalarDouble(quad_rtol);
129+
readOptionScalarInt(maxstepsB, int);
127130
readOptionScalarInt(lmm, LinearMultistepMethod);
128131
readOptionScalarInt(iter, NonlinearSolverIteration);
129132
readOptionScalarInt(interpType, InterpolationType);

src/amici_solver.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,18 +148,25 @@ void Solver::setupAMIB(BackwardProblem *bwd, const UserData *udata, Model *model
148148
AMISetUserDataB(bwd->getwhich(), model);
149149

150150
/* Number of maximal internal steps */
151-
AMISetMaxNumStepsB(bwd->getwhich(), 100 * udata->maxsteps);
151+
AMISetMaxNumStepsB(bwd->getwhich(), (udata->maxstepsB == 0) ? udata->maxsteps * 100 : udata->maxstepsB);
152152

153153
setLinearSolverB(udata, model, bwd->getwhich());
154154

155155
/* Initialise quadrature calculation */
156156
qbinit(bwd->getwhich(), bwd->getxQBptr());
157-
157+
158+
double quad_rtol = isNaN(udata->quad_rtol) ? udata->rtol : udata->quad_rtol;
159+
double quad_atol = isNaN(udata->quad_atol) ? udata->atol : udata->quad_atol;
160+
158161
/* Enable Quadrature Error Control */
159-
AMISetQuadErrConB(bwd->getwhich(), TRUE);
162+
if (std::isinf(quad_atol) || std::isinf(quad_rtol)) {
163+
AMISetQuadErrConB(bwd->getwhich(), FALSE);
164+
} else {
165+
AMISetQuadErrConB(bwd->getwhich(), TRUE);
166+
}
160167

161-
AMIQuadSStolerancesB(bwd->getwhich(), RCONST(udata->rtol),
162-
RCONST(udata->atol));
168+
AMIQuadSStolerancesB(bwd->getwhich(), RCONST(quad_rtol),
169+
RCONST(quad_atol));
163170

164171
AMISetStabLimDetB(bwd->getwhich(), udata->getStabilityLimitFlag());
165172
}

src/forwardproblem.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -610,9 +610,12 @@ void ForwardProblem::getDataSensisFSA(int it) {
610610
}
611611
}
612612
}
613-
model->fsy(it, rdata);
614-
if (edata) {
615-
model->fsJy(it, dJydx, rdata);
613+
614+
if (model->ny > 0) {
615+
model->fsy(it, rdata);
616+
if (edata) {
617+
model->fsJy(it, dJydx, rdata);
618+
}
616619
}
617620
}
618621

src/steadystateproblem.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,4 +294,4 @@ void SteadystateProblem::getNewtonSimulation(const UserData *udata,
294294
}
295295
}
296296

297-
} // namespace amici
297+
} // namespace amici

src/udata.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@ UserData::UserData(const UserData &other) : UserData(other.np(), other.nk(), oth
3737
sensi = other.sensi;
3838
atol = other.atol;
3939
rtol = other.rtol;
40+
quad_atol = other.quad_atol;
41+
quad_rtol = other.quad_rtol;
4042
maxsteps = other.maxsteps;
43+
maxstepsB = other.maxstepsB;
4144
newton_maxsteps = other.newton_maxsteps;
4245
newton_maxlinsteps = other.newton_maxlinsteps;
4346
newton_preeq = other.newton_preeq;
@@ -237,6 +240,9 @@ void UserData::print() const {
237240
printf("atol: %e\n", atol);
238241
printf("rtol: %e\n", rtol);
239242
printf("maxsteps: %d\n", maxsteps);
243+
printf("quad_atol: %e\n", quad_atol);
244+
printf("quad_rtol: %e\n", quad_rtol);
245+
printf("maxstepsB: %d\n", maxstepsB);
240246
printf("newton_maxsteps: %d\n", newton_maxsteps);
241247
printf("newton_maxlinsteps: %d\n", newton_maxlinsteps);
242248
printf("ism: %d\n", ism);

tests/cpputest/unittests/testsSerialization.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ void checkReturnDataEqual(amici::ReturnData const& r, amici::ReturnData const& s
9595
CHECK_EQUAL(*r.chi2, *s.chi2);
9696
CHECK_EQUAL(*r.status, *s.status);
9797

98-
checkEqualArray(r.sllh, s.sllh, r.nplist, 1e-16, 1e-16, "sllh");
99-
checkEqualArray(r.s2llh, s.s2llh, r.nplist * r.nplist, 1e-16, 1e-16, "s2llh");
98+
checkEqualArray(r.sllh, s.sllh, r.nplist, 1e-5, 1e-5, "sllh");
99+
checkEqualArray(r.s2llh, s.s2llh, r.nplist * r.nplist, 1e-5, 1e-5, "s2llh");
100100
}
101101

102102

0 commit comments

Comments
 (0)