Skip to content
yaugenstPublic

About

Automatic differentiation for the NumPy code you already write

Topics

Resources

Contributing

Security policy

Stars

9 stars

Watchers

0 watching

Forks

Latest commit

 

History

79 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Advect

CI Coverage PyPI conda-forge Python versions

Advect is a focused automatic differentiation library for scientific Python, with broad NumPy API coverage and first-class support for the Python Array API standard. For repeated workloads, it can stage a function into a reusable, optimized program that can itself be differentiated, saved, and loaded.

Try it

python -m pip install advect
# or
conda install -c conda-forge advect
import numpy as np

import advect as ad


def energy(x):
    return np.sum(np.sin(x) ** 2)


x = np.array([0.0, 0.5, 1.0])
value, gradient = ad.value_and_grad(energy)(x)

print(f"loss: {value:.6f}")
print("gradient:", np.round(gradient, 6))
# loss: 0.937922
# gradient: [0.       0.841471 0.909297]

value_and_grad evaluates energy and differentiates it with respect to x. When the same kinds of inputs will run repeatedly, stage the function once:

program = ad.stage(energy, x)
restored = ad.StagedProgram.from_dict(program.to_dict())
print(f"restored loss: {restored(x):.6f}")
# restored loss: 0.937922

From the same code, Advect can compute JVPs, VJPs, Jacobians, Hessians, and higher-order or implicit derivatives. The core API also covers checkpointing and custom primitives. Optional integrations add SciPy and xarray workflows and bridges to other autodiff frameworks.

Related projects

Other NumPy-focused autodiff projects include HIPS Autograd and MyGrad. Advect also offers optional bridges that let a NumPy-backed function participate in JAX or PyTorch.

Learn and contribute

Start with the runnable tutorials, then use the API reference and compatibility tables for exact contracts. Contributors should begin with CONTRIBUTING.md and the developer guide.

Report security issues through GitHub's private advisory form. Advect is distributed under the MIT License.

About

Automatic differentiation for the NumPy code you already write

Topics

Resources

Contributing

Security policy

Stars

9 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages