Package: derivcheck
Derivcheck provides a robust and very sensitive checker of analytic partial
derivates. It is intended to be used in unit tests of other projects. Seederiv_check/basic_example.pyfor a basic example.InstallationDerivcheck can be installed with pip (system wide or in a virtual environment):pipinstallderivcheckAlternatively, you can install derivcheck in your home directory:pipinstallderivcheck--userLastly, you can also install derivcheck with conda. (Seehttps://www.continuum.io/downloads)condainstall-ctheochemderivcheckTestingThe tests can be executed as follows:pytestderivcheckBackground and usageThis module implements a functionassert_deriv, which uses Ridders’ numerical finite
difference scheme to test the implementation of analytic finite differences. Ridders’
method automatically finds the step size (given an initial upper estimate) and the
polynomial order that result in the best approximation. In practice, this means that 14
digits of precision can be reached with 6 to 12 evaluations of the function of interest.The implementation of Ridders’ method is based on the one from the book “Numerical
Recipes” (http://numerical.recipes/), which is in turn a slight rendition of the original
method as proposed by Ridders. (Ridders, C.J.F. 1982, Advances in Engineering Software,
vol. 4, no. 2, pp. 75–76.https://doi.org/10.1016/S0141-1195(82)80057-0)It is assumed that you have implemented two functions:fand its derivative or
gradientg. The functionftakes one argument: a scalar or array with shapeshape_in. It returns a scalar or an array with shapeshape_out. The functionghas the same input but returns a scalar or an array with shape (shape_out + shape_in).The consistency offandg, can then be tested around a input valueoriginwith the following code:assert_deriv(f,g,origin)whereoriginis a scalar or array with shapeshape_in, depending on whatfandgexpect as input. AnAssertionErroris raised when the gradient functiongis
not consistent with numerical derivatives off. If Ridders’ method does not converge
to sufficiently accurate estimates of a derivative, aFloatingPointErroris raised.The functionassert_derivtakes several optional arguments to tune its behavior:widths:floatornp.ndarray(default1e-4)The initial (maximal) step size for the finite difference method. Do not take a value
that is too small. When an array is given, each matrix element of the input of the
function gets a different step size. When a matrix element is set to zero, the
derivative towards that element is not tested. The function will not be sampled beyond
[origin-widths, origin+widths].output_mask:np.ndarrayorNone(default)This option is useful when the function returns an array output: it allows the caller to
select which components of the output need to be tested. When not given, all components
are tested.rtol:floatThe allowed relative error on the derivative.atol:floatThe allowed absolute error on the derivative.Release history2019-06-201.1.5Fix a bug related to sharing references to the origin argument of OneDumWrapper.
Start using Roberto to drive the CI.2017-09-211.1.4New template for travis.yml, only affects testing2017-08-221.1.3Switch to theochem channel on anaconda.2017-08-011.1.2Remove unused dependency on future.2017-08-011.1.1Fix dependencies to simplify testing.2017-08-011.1.0Tests are now included with the installed module.Experimental: deployment to github, pypi and anaconda.2017-07-301.0.2Updated README and install recipe for Conda2017-07-301.0.1Fix some missing files and extend README2017-07-281.0.0Ridders’ finite difference scheme for testing analytic derivatives.Fully deterministic procedure.More intuitive API2017-07-270.1.0Code is made Python 3 compatible and still works with 2.7. Some packaging
improvements.2017-07-270.0.0Initial version: code taken from the Romin project (with contributions and
ideas from Michael Richer and Paul W. Ayers). Some bugs were fixed through QA
and CI (pylint, pycodestyle, pydocstyle, nosetests and coverage).How to make a release (Github, PyPI and anaconda.org)Before you do this, make sure everything is OK. The PyPI releases cannot be undone. If you
delete a file from PyPI (because of a mistake), you cannot upload the fixed file with the
same filename! Seehttps://github.com/pypa/packaging-problems/issues/74Update the release history.Commit the final changes to master and push to github.Wait for the CI tests to pass. Check if the README looks ok, etc. If needed, fix things
and repeat step 2.Make a git version tag:git tag <some_new_version>Follow the semantic versioning
guidelines:http://semver.orgPush the tag to github:git push origin master--tags