Skip to main content

An automatic differentiation library (support forward and reverse mode)

Project description

EasyDiff Build Status codecov

EasyDiff is an automatic differentiation python library with forward and reverse mode supported. EasyDiff is developed as a Harvard CS207 (19Fall) course project by Group 18: Yang Zhou, Ruby Zhang, Kangli Wu, and Emily Gould. Check our documentation for more details.

How to use CrackAD

Installation

Option One: Downloading Using Pip

Get The Package

Simply open your terminal and type the following command:

pip install EasyDiff

Update The Package

To get new releases, paste this into your terminal:

pip install EasyDiff --upgrade

We highly recommend installing the package with pip. Yet, if that doesn't work for you, you can still get our package with the second option below.

Option Two: Downloading From GitHub

Clone the Repository

Clone our GitHub repository and navigate into this directory in your terminal:

git clone https://github.com/CrackAD/cs207-FinalProject.git

In order to use the CrackAD package, you'll need to create a virtual environment. We recommend conda because it is both a package and environment manager and is language agnostic. Please run the following commands in a terminal:

Create Conda Environment

Create an environment with the command, where env_name is the name of your choice. Since our package requires the NumPy package, we also install it at this step:

conda create --name env_name python numpy

Activate the Environment

To activate the Conda environment just created, run the following line:

source activate env_name

Or

conda activate env_name

Yet, it is possible that the second one doesn't work because conda will complain that the shell hasn't been configured to use conda activate. So we would recommend using the first line.

Install Packages

If you haven't installed NumPy in the first step, or if you ever need to install another package, simply do the following:

conda install numpy

To check whether the installation succeeded, we could list out all installed packages in this environment:

conda list

If the conda install did not work, try pip install:

pip install Numpy

Note that it is suggested to always try conda install first.

Demonstration

To use CrackAD, create a .py file (eg, driver.py) with the following lines of code:

from EasyDiff.ad import AD
from EasyDiff.var import Var
from EasyDiff.rev_var import Rev_Var
from EasyDiff.ad import AD_Mode
import numpy as np

# test forward mode. 
# give it a function of your choice
func = lambda x,y: Var.log(x) ** Var.sin(y)

# give the initial values to take the derivatives at
ad = AD(vals=np.array([2, 2]), ders=np.array([1, 1]), mode=AD_Mode.FORWARD)

# calculate and print the derivatives
print("Var.log(x) ** Var.sin(y): {}".format(vars(ad.auto_diff(func))))

# test reverse mode. 
func = lambda x,y: Rev_Var.log(x) ** Rev_Var.sin(y)
ad = AD(vals=np.array([2, 2]), ders=np.array([1, 1]), mode=AD_Mode.REVERSE)
print("Rev_Var.log(x) ** Rev_Var.sin(y): {}".format(vars(ad.auto_diff(func))))

Then, you can run the file in a terminal as follows:

python3 driver.py

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

easydiff-0.0.3.tar.gz (13.0 kB view details)

Uploaded Source

Built Distribution

easydiff-0.0.3-py3-none-any.whl (17.0 kB view details)

Uploaded Python 3

File details

Details for the file easydiff-0.0.3.tar.gz.

File metadata

  • Download URL: easydiff-0.0.3.tar.gz
  • Upload date:
  • Size: 13.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.4

File hashes

Hashes for easydiff-0.0.3.tar.gz
Algorithm Hash digest
SHA256 0cf6a4084819f1dc284cb18a96e3083b9895b6aa226dbfa5fe2f32a9b395e470
MD5 29e9829874ea3d020a4b3536da7ef41e
BLAKE2b-256 566d70508990759d03211eaba6a962cbfac01238a9070c95cc9b60712f835a7a

See more details on using hashes here.

File details

Details for the file easydiff-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: easydiff-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 17.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.4

File hashes

Hashes for easydiff-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 8d30709671b5ae3bd107b71dcca3126f4e8901ad8e646529070c22fe4e1197be
MD5 0c03ba8b4fb55aeaa39703d826d692aa
BLAKE2b-256 dcd893ba1805a9537dd0100376dcaa0d4ec6df52c5405ede43c921fc74348b66

See more details on using hashes here.

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