Skip to main content

High-Performance Automatic Differentiation for Python

Project description

Python

XAD is a library designed for automatic differentiation, aimed at both beginners and advanced users. It is intended for use in production environments, emphasizing performance and ease of use. The library facilitates the computation of derivatives within computer programs, making the process efficient and straightforward for a wide range of mathematical functions, from simple arithmetic to complex calculations, ensuring accurate and automatic derivative computations.

The Python bindings for XAD offer the following features:

  • Support for both forward and adjoint modes at the first order.
  • Strong exception-safety guarantees.
  • High performance, as demonstrated in extensive production use.

For more details and to integrate XAD into your projects, consult the comprehensive documentation.

Application Areas

Automatic differentiation has many application areas, for example:

  • Machine Learning and Deep Learning: Training neural networks or other machine learning models.
  • Optimization: Solving optimization problems in engineering and finance.
  • Numerical Analysis: Enhancing numerical solution methods for differential equations.
  • Scientific Computing: Simulating physical systems and processes.
  • Risk Management and Quantitative Finance: Assessing and hedging risk in financial models.
  • Computer Graphics: Optimizing rendering algorithms.
  • Robotics: Improving control and simulation of robotic systems.
  • Meteorology: Enhancing weather prediction models.
  • Biotechnology: Modeling biological processes and systems.

Getting Started

Install:

pip install xad

Calculate first-order derivatives in adjoint mode:

import xad.adj_1st as xadj


# set independent variables
x0_ad = xadj.Real(1.0)
x1_ad = xadj.Real(1.5)
x2_ad = xadj.Real(1.3)
x3_ad = xadj.Real(1.2)

with xadj.Tape() as tape:
    # and register them
    tape.registerInput(x0_ad)
    tape.registerInput(x1_ad)
    tape.registerInput(x2_ad)
    tape.registerInput(x3_ad)

    # start recording derivatives
    tape.newRecording()

    # calculate the output
    y = x0_ad + x1_ad - x2_ad * x3_ad

    # register and seed adjoint of output
    tape.registerOutput(y)
    y.derivative = 1.0

    # compute all other adjoints
    tape.computeAdjoints()

    # output results
    print(f"y = {y}")
    print(f"first order derivatives:\n")
    print(f"dy/dx0 = {x0_ad.derivative}")
    print(f"dy/dx1 = {x1_ad.derivative}")
    print(f"dy/dx2 = {x2_ad.derivative}")
    print(f"dy/dx3 = {x3_ad.derivative}")

For more information, see the Documentation.

Related Projects

  • XAD Comprehensive automatic differentiation in Python and C++
  • QuantLib-Risks: Fast risk evaluations in Python and C++

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

xad-1.5.2-cp312-cp312-win_amd64.whl (370.3 kB view hashes)

Uploaded CPython 3.12 Windows x86-64

xad-1.5.2-cp312-cp312-musllinux_1_1_x86_64.whl (793.6 kB view hashes)

Uploaded CPython 3.12 musllinux: musl 1.1+ x86-64

xad-1.5.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (268.9 kB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ x86-64

xad-1.5.2-cp312-cp312-macosx_12_0_x86_64.whl (234.2 kB view hashes)

Uploaded CPython 3.12 macOS 12.0+ x86-64

xad-1.5.2-cp311-cp311-win_amd64.whl (371.1 kB view hashes)

Uploaded CPython 3.11 Windows x86-64

xad-1.5.2-cp311-cp311-musllinux_1_1_x86_64.whl (790.5 kB view hashes)

Uploaded CPython 3.11 musllinux: musl 1.1+ x86-64

xad-1.5.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (266.2 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

xad-1.5.2-cp311-cp311-macosx_12_0_x86_64.whl (222.8 kB view hashes)

Uploaded CPython 3.11 macOS 12.0+ x86-64

xad-1.5.2-cp310-cp310-win_amd64.whl (369.6 kB view hashes)

Uploaded CPython 3.10 Windows x86-64

xad-1.5.2-cp310-cp310-musllinux_1_1_x86_64.whl (789.4 kB view hashes)

Uploaded CPython 3.10 musllinux: musl 1.1+ x86-64

xad-1.5.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (264.4 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

xad-1.5.2-cp310-cp310-macosx_12_0_x86_64.whl (221.3 kB view hashes)

Uploaded CPython 3.10 macOS 12.0+ x86-64

xad-1.5.2-cp39-cp39-win_amd64.whl (354.3 kB view hashes)

Uploaded CPython 3.9 Windows x86-64

xad-1.5.2-cp39-cp39-musllinux_1_1_x86_64.whl (788.9 kB view hashes)

Uploaded CPython 3.9 musllinux: musl 1.1+ x86-64

xad-1.5.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (264.9 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

xad-1.5.2-cp39-cp39-macosx_12_0_x86_64.whl (221.4 kB view hashes)

Uploaded CPython 3.9 macOS 12.0+ x86-64

xad-1.5.2-cp38-cp38-win_amd64.whl (369.6 kB view hashes)

Uploaded CPython 3.8 Windows x86-64

xad-1.5.2-cp38-cp38-musllinux_1_1_x86_64.whl (788.9 kB view hashes)

Uploaded CPython 3.8 musllinux: musl 1.1+ x86-64

xad-1.5.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (264.2 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page