Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

pymrm.checks

Back to modules overview

Deterministic checks for pymrm models.

Small tools for the verification steps every model needs, so that they do not have to be rewritten (and debugged) for each model:

The module depends on numpy and scipy only.

View module source on GitHub

Public API

SymbolTypeSummary
check_jacobianfunctionCompare the Jacobian returned by fun with central differences.
find_rootsfunctionLocate every sign change of f on [lo, hi] and refine each root.
observed_ordersfunctionRun a refinement study and report observed orders of convergence.
residual_checkfunctionJudge a solution by its componentwise backward error.

check_jacobian(fun, x, n_probe = 4, rtol = 0.0001, seed = 0, eps = None)

Open dedicated reference page

Compare the Jacobian returned by fun with central differences.

Parameters

Returns

View source on GitHub

find_roots(f, lo, hi, n_scan = 64, log = False, xtol = 1e-12)

Open dedicated reference page

Locate every sign change of f on [lo, hi] and refine each root.

Parameters

Returns

View source on GitHub

observed_orders(solve, ns, ratio = None)

Open dedicated reference page

Run a refinement study and report observed orders of convergence.

Parameters

Returns

Notes

The order from values q1, q2, q3 on successively finer grids is log(|q1 - q2| / |q2 - q3|) / log(ratio); it needs no exact solution. An order far from the expected one means the study is not in the asymptotic range, the refinement does not control the error that dominates, or there is a bug. For a non-uniform grid, refine it in a nested way (see the pymrm agent plugin’s profiles.md).

View source on GitHub

residual_check(fun, x, tol = 1e-08)

Open dedicated reference page

Judge a solution by its componentwise backward error.

An absolute threshold on the residual depends on the units and scaling of the equations. The backward error max_i |g_i| / (|J| |x| + |J x - g|)_i is scale-free: it measures the relative change in the (linearised) equation coefficients that would make x exact.

Parameters

Returns

View source on GitHub