Skip to content


Repository files navigation


About acorns


Package license: MIT

Feedstock license: BSD 3-Clause

Current Version: 3.0 - Fixes bugs and supports features described in the user guide

Summary: An easy-to-use Code Generator for Gradients and Hessians

ACORNS is an algorithm for automatic differention of algorithms written in a subset of C99 code and its efficient implementation as a Python script.


Installing acorns from the conda-forge channel can be achieved by adding conda-forge to your channels with:

conda config --add channels conda-forge

Once the conda-forge channel has been enabled, acorns can be installed with:

conda install acorns


Please refer to the examples/ directory and the basic_example.ipynb for more examples. Here is a basic usage of the package:

import acorns

c_function = "int function_test(double a, double p){ \
    double energy = a*a*a*a*p+1/(p*p) - 1/p * p/a; \
    return 0; \

acorns.autodiff(c_function, 'energy', ['a','p'], func = 'function_test', output_filename = 'test_grad_forward',
       output_func = 'compute_grad_forward')

Examples directory:

  1. - basic examples of forward and reverse, single and double autodifferentiation

  2. - example of including parallel for loops

  3. - example script for splitting derivatives into multiple files

  4. - runs sample functions from the examples/sample_functions/ directory, includes single and double dimensional array examples

  5. For unrolling - example input examples/unrolled_example.c and output code examples/unrolled_example_output.c along with differentiation of the output code examples/unrolled_example_fd_output.c are provided.

Known problems

  • Support for nested loops is limited to two.
  • Does not currently support complicated data structures.

Please refer to the user guide for further reading: user guide

Package Contents:

README.rst: This README file.

LICENSE: MIT Installation script

examples/: A directory with some examples of using Acorns

acorns/: The acorns module source code.