Skip to main content

Fast, transparent first- and second-order automatic differentiation

Project description

ad

Fast, transparent first- and second-order automatic differentiation for Python

Tests Documentation Ruff

codecov Quality Gate Status License: BSD-3

PyPI Downloads Python versions

Overview

The ad package allows you to easily and transparently perform first- and second-order automatic differentiation. Advanced math involving trigonometric, logarithmic, hyperbolic, and related functions can be evaluated directly using the ad.admath submodule.

All base numeric types are supported (int, float, complex, etc.). The package is designed so underlying numeric types interact as they normally do during calculations. In practice, ad behaves like a lightweight wrapper that tracks derivatives while preserving standard numeric behavior.

From the Wikipedia entry on Automatic differentiation:

"AD exploits the fact that every computer program, no matter how complicated, executes a sequence of elementary arithmetic operations (addition, subtraction, multiplication, division, etc.) and elementary functions (exp, log, sin, cos, etc.). By applying the chain rule repeatedly to these operations, derivatives of arbitrary order can be computed automatically, and accurate to working precision."

See the package documentation for details and examples.

Main Features

  • Transparent calculations with derivatives, requiring little or no modification to existing code (including NumPy-based code).
  • Broad mathematical operation support, including most functions from math and cmath, plus convenience trigonometric, hyperbolic, and logarithmic helpers (csc, acoth, ln, etc.). Comparison operators follow the same rules as the wrapped numeric values.
  • Seamless real and complex arithmetic through ad.admath counterparts.
  • Automatic gradient and Hessian function generator for optimization workflows with scipy.optimize via gh(your_func_here).
  • Linear algebra routines in ad.linalg similar to NumPy's linalg, without LAPACK dependency.

Linear Algebra Routines

Decompositions

  • chol: Cholesky decomposition
  • lu: LU decomposition
  • qr: QR decomposition

Solving equations and matrix inversion

  • solve: General solver for linear systems
  • lstsq: Least-squares solver for linear systems
  • inv: Multiplicative inverse of a matrix

Installation

uv pip install ad

Requires Python 3.10+. See the full installation guide.

Documentation

License

BSD-3-Clause.

Project details


Download files

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

Source Distribution

ad-1.4.0.tar.gz (147.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ad-1.4.0-py3-none-any.whl (20.4 kB view details)

Uploaded Python 3

File details

Details for the file ad-1.4.0.tar.gz.

File metadata

  • Download URL: ad-1.4.0.tar.gz
  • Upload date:
  • Size: 147.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for ad-1.4.0.tar.gz
Algorithm Hash digest
SHA256 afebb623b37150572db8352143d5923accb9d5a929c19aaac7d0d32ffe9284c4
MD5 b7f1ea9132a03bf0030a77c3def91adb
BLAKE2b-256 4476276107aab2d2824686ae9c5b7a8346158acc05c426bd12f1b00029269d5e

See more details on using hashes here.

Provenance

The following attestation bundles were made for ad-1.4.0.tar.gz:

Publisher: publish_dist.yml on eggzec/ad

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ad-1.4.0-py3-none-any.whl.

File metadata

  • Download URL: ad-1.4.0-py3-none-any.whl
  • Upload date:
  • Size: 20.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for ad-1.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b2fde7bf2a467d0a5ba237ab71f40cf54034194785fea6bdeaf059d9cb91b7ac
MD5 1f0e1f29a55280d331c17f5f27cf85f3
BLAKE2b-256 05acea4b3bf10ea0f3ae0ca78f4c4913d05d73e6932fe3602c50d0b15be3140f

See more details on using hashes here.

Provenance

The following attestation bundles were made for ad-1.4.0-py3-none-any.whl:

Publisher: publish_dist.yml on eggzec/ad

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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