Skip to content

We create NABLA: A fully functioning domain specific programming language for automatic differentiation

Notifications You must be signed in to change notification settings

kartiksrinivas007/AutoGradLanguage

Repository files navigation

Nabla

Lexer Build Status Parser Build Status Semantic Build Status

Nabla Image

Nabla is a Domain specific langauge built for the purpose of Tensor Operations and Automatic differentiation
It uses dynamically built computational graphs for back-propagation.

Table of Contents

Example

declare
{
    var Tensor a[2][1] = [[1],[2]];
    var Tensor b[1][2] = [[1,2]];
    var Tensor c[1][2] = [[1,2]];
    var Tensor d[1][2] = [[5,6]];
    var Tensor e[1][2] = [[53,64]];
    var Tensor g[1][2] = [[53,64]];
    var Tensor fin[1][1];
}
operations
{
    fin = sin(e+cos(2*b))*exp(d)@a;
}
gradient
{
    backward(fin);
    print(a);
    print(b);
    print(d);
    print(e);
    grad(a);
    grad(b);
    grad(d);
    grad(e);
}

The code will be converted into a computational graph(internally) of the form:- After this we will be able to use the chain rule to calculate the gradients of the Final variable in terms of the beginning variables

Computational graph

Installation

Requirements

Steps

  1. Clone the repository
git clone https://github.com/IITH-COMPILERS2/compilers-2-project-team-9-aug22.git
  1. Run the makefile
cd compilers-2-project-team-9-aug22
make
  1. Run the tests (optional)
make test

Documentation

To generate the documentation for the project, run the following command in the root directory of the project

doxygen

The documentation for the project can be found here

Stages

The lexer is the first stage of the compiler. It takes the input file and converts it into a stream of tokens. The tokens are then passed to the parser.

The parser is the second stage of the compiler. It takes the stream of tokens from the lexer and converts it into an Abstract Syntax Tree (AST). The AST is then passed to the semantic analyzer.

The semantic analyzer is the third stage of the compiler. It takes the AST from the parser and performs semantic analysis on it. The AST is then passed to the code generator.

The transpiler is the fourth stage of the compiler. It takes the AST from the semantic analyzer and converts it into a C++ file. The C++ file is then compiled and executed.

Class Hierarchy


Class Hierarchy

To see the class Hierarchy please switch to the branch AST and see files ast.h and ast.cpp

Testing


Go inside the lexer folder and run these commands to test lexer

make 
make test

Go inside the Parser folder and run these commands to test Parser

make 
make test

Go inside the Semantic folder and run these commands to test semantic analysis

make 
make test

Acknowledgements


About

We create NABLA: A fully functioning domain specific programming language for automatic differentiation

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published