Skip to content

YingboMa/SciCompDSL.jl

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SciCompDSL.jl

Build Status Coverage Status codecov.io

SciCompDSL.jl is a domain-specific language for scientific computing. It is used to build computational graphs as an intermediate representation (IR) of scientific computing problems. It uses a tagged variable IR in order to allow specification of complex models and allow for transformations of models. Together, this is an abstract form of a scientific model that is easy for humans to generate but also easy for programs to manipulate.

Warning: This repository is a work-in-progress

Introduction

Let's build an ODE. First we define some variables. In a differential equation system, we need to differentiate between our dependent variables, independent variables, and parameters. Therefore we label them as follows:

using SciCompDSL

# Define some variables
x = DependentVariable(:x)
y = DependentVariable(:y)
z = DependentVariable(:z)
t = IndependentVariable(:t)
D = Differential(t) # Default of first derivative, Derivative(t,1)
σ = Parameter()
ρ = Parameter()
β = Parameter()

Then we build the system:

eqs = [D*x == σ*(y-x),
       D*y == x*-z)-y,
       D*z == x*y - β*z]

Each operation builds an Operation type, and thus eqs is an array of Operation and Variables. This holds a tree of the full system that can be analyzed by other programs. We can turn this into a DiffEqSystem via:

de = DiffEqSystem(eqs,[t],[x,y,z],Variable[],[σ,ρ,β])

where we tell it the variable types and ordering (in the future this will be automatic). This can then generate the function. For example, we can see the generated code via:

SciCompDSL.generate_ode_function(de)

## Which returns:
:((du, u, p, t)->begin
                x = u[1]
                y = u[2]
                z = u[3]
                σ = p[1]
                ρ = p[2]
                β = p[3]
                x_t = σ * (y - x)
                y_t = x *- z) - y
                z_t = x * y - β * z
                du[1] = x_t
                du[2] = y_t
                du[3] = z_t
            end
        end)

and get the generated function via:

f = DiffEqFunction(de)

About

A DSL for Scientific Computing in Julia

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Julia 100.0%