Skip to main content

Lazy automatic differentiation for Python

Project description

grast

Lazy automatic differentiation for Python

Install

Requires python >= 3.10

pip install grast

Usage

Create function R^n -> R

from grast import var

x = var('x')
y = var('y')
z = var('z').freeze()  # do not compute derivative

h = x/y + y**x
f = z * h + 3

Get gradient

df = f.grad()
df_dx = df['x']
df_dy = df['y']

Evaluate with specific arguments

args = dict(x=-3, y=5, z=2)
f(args)
df_dx(args)
df_dy(args)

View in symbolic format

print(str(f))
print(str(df_dx))
print(str(df_dy))

References

  1. F. Krawiec, S. Peyton Jones, N. Krishnaswami, T. Ellis, R. A. Eisenberg, A. Fitzgibbon. 2022. Provably correct, asymptotically efficient, higher-order reverse-mode automatic differentiation. Proc. ACM Program. Lang., 6, POPL (2022), 1–30. https://doi.org/10.1145/3498710

  2. Jerzy Karczmarczuk. 1998. Functional Differentiation of Computer Programs. In Proceedings of the Third ACM SIGPLAN International Conference on Functional Programming (Baltimore, Maryland, USA) (ICFP ’98). Association for Computing Machinery, New York, NY, USA, 195-203. https://doi.org/10.1145/289423.289442

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

grast-0.1.2.tar.gz (11.3 kB view hashes)

Uploaded Source

Built Distribution

grast-0.1.2-py3-none-any.whl (14.8 kB view hashes)

Uploaded Python 3

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