Tutorials › Physiologically-Based Pharmacokinetics (PBPK) › Setting Solver Tolerances for Unequal State Scales

Numerical Implementation and Stiff Solvers · Tutorial 682 of 799

Setting Solver Tolerances for Unequal State Scales

Choose component-specific absolute tolerances alongside a relative tolerance to control numerical error across PBPK states without overlooking small concentrations or amounts.

Intermediate 10 min read

What You'll Learn

  • Distinguish the roles and units of relative and absolute tolerances.
  • Interpret a solver’s scaled local-error estimate for states of unequal magnitude.
  • Set component-specific absolute tolerances using meaningful state scales.
  • Assess how a concentration-state tolerance translates to amount error.
  • Explain why acceptable errors in individual states do not guarantee a specified error in total drug amount.
  • Recognize failure modes such as using one absolute tolerance for every state.

Why Tolerances Need to Match the States

A PBPK model can track a large amount of drug in one compartment while another compartment contains only a trace concentration. A numerical solver must decide whether each integration step is accurate enough to accept. If its error control treats every state as though it had the same magnitude and units, it can be overly strict for one state and too permissive for another.

Solver tolerances set the scale for this decision. A relative tolerance controls error in proportion to a state’s size, while an absolute tolerance supplies a scale that remains meaningful when a state is near zero. In a model with states of unequal scale, one relative tolerance is commonly shared across components, but absolute tolerances should often be specified separately for each state.

Definition: A relative tolerance, often written \(rtol\), is a dimensionless control on error relative to the magnitude of a state. An absolute tolerance, written \(atol_i\) for state \(i\), is an error scale with the same units as that state. A solver combines them to scale its estimated local error; they are numerical controls, not direct guarantees about the error in the full simulated trajectory.

How Error Scaling Works

Suppose a PBPK model is represented by an ODE state vector \(y\), with component \(y_i\) for each amount or concentration. An adaptive solver estimates the local error \(e_i\) for a proposed step. A common component-wise scaling is

$$ s_i = atol_i + rtol \max\left(|y_{i,\mathrm{old}}|,\ |y_{i,\mathrm{new}}|\right), \qquad r_i = \frac{|e_i|}{s_i}. $$

Here \(s_i\) is the error scale and \(r_i\) is the scaled error for component \(i\). Solver implementations differ: some use the old state or another scale in place of the maximum shown. They may also combine scaled errors using a maximum norm or a root-mean-square norm. For the common root-mean-square rule with \(m\) states, the step passes this part of the error test when

$$ \sqrt{\frac{1}{m}\sum_{i=1}^{m}r_i^2} \leq 1. $$

This condition can allow one component’s \(r_i\) to exceed 1 if the other components’ scaled errors are sufficiently small. A maximum-norm rule instead requires every \(r_i\leq 1\). The solver’s documentation determines the precise convention. In either case, the tolerances set the scale for an estimated local error; they do not imply that every actual state error is bounded by \(s_i\) over an entire simulation.

The scale formula explains why both tolerances matter. When \(|y_i|\) is large relative to \(atol_i/rtol\), the relative term tends to dominate. Near zero, the absolute term matters more. If \(atol_i\) is too large for a small state, the solver can accept an error that is large relative to that state. If it is unnecessarily tiny, the solver may take excessive steps to resolve a state at a precision that is not meaningful for the model.

Choosing Absolute Tolerances by State

Begin by listing the states, their units, their typical magnitudes during the simulation, and the smallest values that matter to the intended interpretation. Then choose a relative tolerance for the desired fractional accuracy over the range where states are appreciably nonzero. Set each absolute tolerance using the units and an acceptable near-zero error for that particular state.

For example, an amount state measured in mg and a concentration state measured in mg/L cannot share a numerically identical absolute tolerance as though the values had the same units. Even among states with the same units, a single absolute tolerance may be inappropriate if one compartment typically contains orders of magnitude less drug than another. These choices should reflect the quantities the model needs to resolve, not simply the software’s default values.

1
Inventory the state vector.
Record each state’s meaning, units, and approximate range. Note whether it is an amount, concentration, or another quantity.
2
Set a relative accuracy target.
Choose \(rtol\) to express the desired scale of relative local error where states are large enough for relative error to be informative.
3
Choose component-specific absolute scales.
For each state, ask what near-zero absolute error is small enough for the scientific purpose, and set \(atol_i\) in that state’s units.
4
Check the implications.
Calculate \(atol_i+rtol|y_i|\) at representative state values. Confirm that the resulting error scale is sensible both near zero and at typical magnitudes.

Worked Example: A Large Amount and a Small Amount State

Hypothetical model. Consider a central amount of about 100 mg and a peripheral amount of about 0.020 mg. Set \(rtol=1.0\times10^{-4}\), with \(atol=0.010\) mg for the central state and \(atol=1.0\times10^{-5}\) mg for the peripheral state. For illustration, suppose the estimated local errors are 0.010 mg and \(6.0\times10^{-6}\) mg, respectively.

For the central state, the error scale is

$$ s_{\mathrm{central}} =0.010\ \mathrm{mg}+(1.0\times10^{-4})(100\ \mathrm{mg}) =0.020\ \mathrm{mg}. $$

Its scaled error is \(0.010/0.020=0.500\). For the peripheral state,

$$ s_{\mathrm{peripheral}} =1.0\times10^{-5}\ \mathrm{mg} +(1.0\times10^{-4})(0.020\ \mathrm{mg}) =1.2\times10^{-5}\ \mathrm{mg}, \qquad r_{\mathrm{peripheral}}=\frac{6.0\times10^{-6}}{1.2\times10^{-5}}=0.500. $$

Both components have the same scaled error under these choices, even though their absolute errors differ greatly. If instead the peripheral state used the central state’s \(0.010\) mg absolute tolerance, its scale would be \(0.010002\) mg. An error of \(6.0\times10^{-6}\) mg would then have scaled error about \(0.000600\), and an error approaching \(0.010002\) mg could be allowed by a component-wise threshold. That would be roughly half the peripheral state’s magnitude. A shared absolute tolerance would therefore fail to protect this small amount from large relative error.

Concentrations and Total Drug Amount

A concentration-state tolerance has concentration units, not amount units. If a compartment has fixed volume \(V\) and concentration \(C\), its amount is \(A=VC\). A concentration error \(\delta C\) therefore corresponds to an amount error \(V\delta C\). This conversion is essential when interpreting tolerances for compartments represented by concentrations.

Likewise, controlling the scaled error of every state is not the same as directly controlling error in a derived quantity such as total drug amount. If total amount is computed by summing amount states, the component errors can contribute to that sum. If a concentration state contributes, its error must first be converted to amount using the appropriate volume. The local acceptance test does not, by itself, impose a chosen error bound on the total.

Worked Example: A Low Concentration’s Contribution to Amount

Hypothetical model. A compartment of volume \(0.500\) L has concentration \(C=2.0\times10^{-5}\) mg/L. Use \(rtol=1.0\times10^{-3}\) and \(atol_C=1.0\times10^{-7}\) mg/L. Suppose the estimated local concentration error is \(8.0\times10^{-8}\) mg/L. The state’s error scale and scaled error are

$$ s_C = 1.0\times10^{-7}+(1.0\times10^{-3})(2.0\times10^{-5}) =1.2\times10^{-7}\ \mathrm{mg/L}, \qquad r_C=\frac{8.0\times10^{-8}}{1.2\times10^{-7}}=0.667. $$

The amount in this compartment is

$$ A=VC=(0.500\ \mathrm{L})(2.0\times10^{-5}\ \mathrm{mg/L}) =1.0\times10^{-5}\ \mathrm{mg}. $$

The estimated local amount error corresponding to the concentration error is

$$ V|\delta C|=(0.500\ \mathrm{L})(8.0\times10^{-8}\ \mathrm{mg/L}) =4.0\times10^{-8}\ \mathrm{mg}. $$

Now suppose a separate amount state is 10.0 mg, with \(atol=0.010\) mg and the same \(rtol\). Its error scale is \(0.010+(0.001)(10.0)=0.020\) mg. An estimated error of 0.015 mg has scaled error \(0.015/0.020=0.750\). Under the two-component root-mean-square rule, the combined scaled error is

$$ \sqrt{\frac{0.750^2+0.667^2}{2}} \approx 0.710. $$

That illustrative norm is below 1. If the estimated errors contribute in the same direction to total amount, their combined local contribution is about \(0.015+0.000000040=0.01500004\) mg. This calculation is not a bound on the total trajectory error: it shows why the total’s sensitivity to individual state errors must be considered separately.

Justification: Why the Scale Combines Two Terms

The error scale is designed to behave sensibly in two limiting cases. If a state is large enough that \(rtol|y_i|\) dominates \(atol_i\), then \(s_i\) is approximately \(rtol|y_i|\). Requiring an estimated error to be small relative to that scale is approximately a relative-error requirement. If \(y_i\) is near zero, the relative term tends to zero and \(s_i\) approaches \(atol_i\), so error control does not become undefined or demand zero error.

The transition occurs around the state magnitude where the two terms are equal:

$$ atol_i=rtol|y_i| \quad\Longrightarrow\quad |y_i|=\frac{atol_i}{rtol}. $$

This value is a useful diagnostic. Below it, the absolute tolerance has greater influence; above it, the relative term has greater influence. Thus the choice of \(atol_i\) determines where a state moves from predominantly absolute to predominantly relative error control.

Worked Example: Checking a Near-Zero Tolerance Choice

Hypothetical model. A tissue concentration is measured in mg/L. The modeling purpose requires resolving concentrations around \(2.0\times10^{-6}\) mg/L, and the chosen relative tolerance is \(rtol=2.0\times10^{-3}\). Choose \(atol_C=1.0\times10^{-9}\) mg/L. At the concentration of interest, the relative term is

$$ rtol|C|=(2.0\times10^{-3})(2.0\times10^{-6}\ \mathrm{mg/L}) =4.0\times10^{-9}\ \mathrm{mg/L}. $$

The full scale is \(1.0\times10^{-9}+4.0\times10^{-9}=5.0\times10^{-9}\) mg/L, which is \(5.0\times10^{-9}/(2.0\times10^{-6})=0.0025\), or 0.25%, of the concentration. The transition magnitude is

$$ \frac{atol_C}{rtol} =\frac{1.0\times10^{-9}\ \mathrm{mg/L}}{2.0\times10^{-3}} =5.0\times10^{-7}\ \mathrm{mg/L}. $$

Because the concentration of interest is above this transition, the relative term is larger there. Near zero, the absolute term sets the scale. Whether \(1.0\times10^{-9}\) mg/L is suitable still depends on the model’s purpose; the arithmetic verifies what this choice means, not that it is universally appropriate.

Diagnostics, Alternatives, and Limitations

A tolerance choice is suspect when the solver’s permitted error scale is large relative to a small state that matters, when a state’s absolute tolerance has the wrong units, or when a derived total is important but its sensitivity to state errors has not been considered. Check the error scales at representative values, including near-zero values, and inspect whether meaningful low concentrations or amounts are being numerically obscured. A solver that takes many very small steps may also be responding to tolerances that are excessively tight for one component; that observation alone does not establish that the tolerances are the only cause.

Common alternatives are not interchangeable. One shared absolute tolerance is simple but can neglect low-magnitude states. Component-specific absolute tolerances make the error scales explicit. Nondimensionalizing states can put variables on more comparable scales, but it requires consistent scaling in the equations, initial conditions, and interpretation; it does not remove the need to decide what errors matter. In each approach, the solver’s actual error norm and scaling convention still matter.

Tolerances control estimated local integration error, not model misspecification, uncertainty in physiological inputs, or uncertainty in observations. They do not promise a fixed accuracy for every reported prediction or for a sum of states. In particular, errors in a derived total can depend on state volumes, signs, and how component contributions combine. Treating a solver tolerance as a biological precision claim is therefore a mistake.

Common pitfall: “The central amount and peripheral amount are both measured in mg, so they should use the same absolute tolerance.” Matching units does not mean matching scales or scientific importance. Choose each absolute tolerance according to the acceptable near-zero error for that state, and verify the resulting error scale against its typical and meaningful values.

Check Your Understanding

Answer each question, then compare your reasoning with the solutions below.

  1. A state is measured in mg/L. What units should its absolute tolerance have, and what are the units of its relative tolerance?
  2. For \(rtol=10^{-3}\) and \(atol_i=2.0\times10^{-6}\) mg, calculate the error scale at \(y_i=0.010\) mg.
  3. A concentration error is \(3.0\times10^{-7}\) mg/L in a \(0.20\) L compartment. What amount error does it correspond to?
  4. Why can one shared absolute tolerance be unsuitable for a 50 mg state and a \(0.005\) mg state?
  5. Does an accepted local error test guarantee a particular accuracy for total drug amount across the whole simulation? Explain.

Solutions. (1) The absolute tolerance has units mg/L, matching the concentration state; the relative tolerance is dimensionless. (2) \(s_i=2.0\times10^{-6}+(10^{-3})(0.010)=1.2\times10^{-5}\) mg. (3) \(V|\delta C|=(0.20\ \mathrm{L})(3.0\times10^{-7}\ \mathrm{mg/L})=6.0\times10^{-8}\) mg. (4) The same absolute tolerance can be negligible for the large state but comparable to, or larger than, the small state. A component-specific tolerance can reflect each state’s meaningful near-zero scale. (5) No. Acceptance concerns an estimated local error under the solver’s scaling rule; total amount is derived from one or more states, and the test does not directly bound its accumulated error over the simulation.