Python · chapter 11 of 13

Accuracy and validation

"Accurate generator" is a claim that should be backed by numbers. GRNLab is checked at three levels.

1. Unit tests

tests/ holds 50 pytest tests (pytest in the python folder). They cover analytic steady states of one- and two-stage models, finite-difference checks of every Jacobian, the textbook behaviour of the motifs (bistable toggle, oscillating repressilator and Goodwin loop, pulsing incoherent feed-forward loop, monotone coherent one), seeding, every noise model, perturbations, stimuli, steady states, screens, export round trips, and figure rendering.

2. The accuracy audit

python -m grnlab.audit exercises the public API end to end against closed-form results and writes AUDIT.md. It is independent of the unit tests and meant to be rerun after any change to the kinetics or integrators.

CheckAnalytic resultTolerance
Unregulated gene trajectoryx(t) = x* + (x0 - x*) e^{-gamma t}1e-6
Hill function at thresholdh(K) = 1/2, h'(K) = n / (4K)1e-14
Activation-edge steady stateclosed form from x1* = vmax/gamma1e-8 relative
Repressilator Hopf threshold (Hill 4)alpha_c = 2 (loop slope n x*^n / (1 + x*^n) = 2 at x* = 1)1e-6
Below/above thresholddecays / sustained oscillation
Toggle switch bistability threshold (Hill 2)alpha_c = 21e-6
Jacobian vs central differences01e-6
Euler–Maruyama convergenceerror ratio 2 when dt halves0.3
Additive noise, linear genestationary variance sigma^2 / (2 gamma), mean vmax/gamma10 %
Chemical Langevin, linear geneFano factor sigma^2 (linear-noise approximation)8 %
Two-stage protein levelq* = beta m* / gammaP1e-8
Fast-protein limittwo-stage steady state equals one-stage1e-5
Step stimulusexact exponential after the switch, exactly zero before1e-6
Knockout screenevery knockout with a resolvable effect (above 1e-3 log2 units) moves its target in the sign predicted by Sexact
Seedstwo runs are bit-identicalexact

The last run passed 19 of 19 checks; the measured values are in python/AUDIT.md. The MATLAB toolbox runs the same audit and passes it too.

python -m grnlab.audit
Output
check                                                           expected      measured       error       tol  pass
Unregulated gene x(t): max |ODE - analytic|                            0   1.01804e-07    1.02e-07     1e-06  True
Hill h(K) = 1/2                                                      0.5           0.5           0     1e-15  True
Hill dh/dx at K = n/(4K)                                        0.441176      0.441176    5.55e-17     1e-14  True
Activation edge x2* (additive)                                   1.70927       1.70927    2.22e-16  1.71e-08  True
Repressilator Hopf alpha_c (hill 4)                                    2             2    4.82e-14     1e-06  True
Repressilator amplitude at alpha = 1.8 (below threshold)               0   1.97282e-07    1.97e-07     1e-06  True
Repressilator oscillates at alpha = 2.4 (above threshold)              1             1           0         0  True
Toggle switch bistability alpha_c (hill 2)                             2             2    8.88e-16     1e-06  True
Jacobian vs central differences (max abs)                              0   2.58534e-10    2.59e-10     1e-06  True
Euler error ratio for dt halved (expect 2)                             2       2.00065    0.000655       0.3  True
OU stationary variance sigma^2/(2 gamma)                           0.125      0.128342     0.00334     0.012  True
OU stationary mean vmax/gamma                                         20       19.9801      0.0199      0.02  True
Langevin Fano factor var/mean = sigma^2                             0.16      0.161622     0.00162     0.012  True
Two-stage protein q* = beta m*/gammaP                            14.7902       14.7902    1.78e-15     1e-08  True
Fast-protein limit: max |two-stage - one-stage| steady state           0   1.77636e-15    1.78e-15     1e-05  True
Step stimulus x(t): max |ODE - analytic|                               0   2.86285e-08    2.86e-08     1e-06  True
KO effect sign agreement with S (fraction)                             1             1           0         0  True
KO screen convergence (fraction)                                       1             1           0         0  True
Seed reproducibility: max |run A - run B|                              0             0           0         0  True
19 of 19 checks passed
Two of the audited thresholds. Left: repressilator amplitude against alpha; oscillation starts at the analytic Hopf point alpha = 2. Right: toggle-switch steady states against alpha; the symmetric state (blue) loses stability at alpha = 2 and two branches (teal) appear.
Two of the audited thresholds. Left: repressilator amplitude against alpha; oscillation starts at the analytic Hopf point alpha = 2. Right: toggle-switch steady states against alpha; the symmetric state (blue) loses stability at alpha = 2 and two branches (teal) appear.
Euler–Maruyama with zero noise against RK45: the error falls linearly with the step, as expected for a first-order scheme.
Euler–Maruyama with zero noise against RK45: the error falls linearly with the step, as expected for a first-order scheme.

3. Numerical methods and their limits

Known limitations