what's next in julia

62
What’s next in Jul_ Jiahao Chen MIT Computer Science and Artificial Intelligence Laboratory julialang.org Alan Edelman Jeff Bezanson Stefan Karpinski Viral B. Shah

Upload: jiahao-chen

Post on 11-Aug-2014

610 views

Category:

Data & Analytics


5 download

DESCRIPTION

 

TRANSCRIPT

Page 1: What's next in Julia

What’s next in Jul_

Jiahao Chen MIT Computer Science and Artificial Intelligence Laboratory

julialang.org

Alan EdelmanJeff Bezanson Stefan Karpinski Viral B. Shah

Page 2: What's next in Julia

What’s the big deal about Julia ?

julialang.org/benchmarks

Page 3: What's next in Julia

It bridges the divide between computer science and computational science

What’s the big deal about Julia ?

Page 4: What's next in Julia

It bridges the divide between computer science and computational science

What’s the big deal about Julia ?

data abstraction

performance

Page 5: What's next in Julia

It bridges the divide between computer science and computational science

What’s the big deal about Julia ?

data abstraction

performance

What if you didn’t have to choose between data abstraction and performance?

Page 6: What's next in Julia

It’s a programming language designed for technical computing

What’s the big deal about Julia ?

Page 7: What's next in Julia

It’s a programming language designed for technical computing

What’s the big deal about Julia ?

The key ingredients

Multi-methods (multiple dispatch)

Dataflow type inference

together allow for cost-efficient data abstraction

Page 8: What's next in Julia

Object-oriented programming with classes

What can I do with/to a thing?

Page 9: What's next in Julia

Object-oriented programming with classes

What can I do with/to a thing?

Page 10: What's next in Julia

Object-oriented programming with classes

What can I do with/to a thing?

top uppay fare

lose

buy

Page 11: What's next in Julia

Object-oriented programming with classes

What can I do with/to a thing?

top uppay fare

lose

buy

top uppay fare

lose

buy

Page 12: What's next in Julia

Object-oriented programming with classes

What can I do with/to a thing?

top uppay fare

lose

buy

top uppay fare

lose

buy

Page 13: What's next in Julia

Object-oriented programming with classes

What can I do with/to a thing?

top uppay fare

lose

buy

top uppay fare

lose

buy

pay farelose

buy

Page 14: What's next in Julia

methods objects

Object-oriented programming with classes

What can I do with/to a thing?

top uppay fare

lose

buy

top uppay fare

lose

buy

pay farelose

buy

Page 15: What's next in Julia

methods objects

Object-oriented programming with classes

What can I do with/to a thing?

top uppay fare

lose

buy

top uppay fare

lose

buy

pay farelose

buy

class-based OO !classes are more fundamental than methods

Page 16: What's next in Julia

Object-oriented programming with multi-methods

What can I do with/to a thing?

top up

pay fare

lose

buy

generic function

objectsmethods

Page 17: What's next in Julia

Object-oriented programming with multi-methods

What can I do with/to a thing?

top up

pay fare

lose

buy

generic function

objectsmethods

multimethods !relationships between objects and functions

Page 18: What's next in Julia

Multi-methods with type hierarchy

top up

pay fare

lose

buy

generic function

objectsmethods

rechargeable subway pass

single-use subway ticket

is a subtype of

subway ticket

abstract object

Page 19: What's next in Julia

generic function

objectsmethods

rechargeable subway pass

single-use subway ticket

is a subtype of

subway ticket

top up

pay fare

lose

buy

abstract object

Multi-methods with type hierarchy

Page 20: What's next in Julia

generic function

objectsmethods

rechargeable subway pass

single-use subway ticket

is a subtype of

subway ticket

top up

pay farelose

buy

abstract object

Multi-methods with type hierarchy

Page 21: What's next in Julia

The Julia codebase is compact

5,774 lines of Scheme 32,707 lines of C 59727 lines of Julia !+LLVM, BLAS, LAPACK, SuiteSparse, ARPACK, Rmath, GMP, MPFR, FFTW,…

Page 22: What's next in Julia

Data types as a lattice

Dana Scott, Data types as lattices, SIAM J. Comput. 5: 522-87. 1976

Real

Number

FloatingPoint Rational

Complex

Float64 BigFloat…

Integer

is a parameter ofis a subtype of

Signed BigInt

Any

Int64…

Page 23: What's next in Julia

Signed

Multiple dispatch with type lattice traversal

Real

Number

FloatingPoint Rational

Float64 BigFloat…

Integer

is a parameter ofis a subtype of

BigInt

Any

Int64…

Page 24: What's next in Julia

Signed

Multiple dispatch with type lattice traversal

Real

Number

FloatingPoint Rational

Float64 BigFloat…

Integer

is a parameter ofis a subtype of

BigInt

Any

Int64…

Page 25: What's next in Julia

Signed

Multiple dispatch with type lattice traversal

Real

Number

FloatingPoint Rational

Float64 BigFloat…

Integer

is a parameter ofis a subtype of

BigInt

Any

Int64…

Page 26: What's next in Julia

Signed

Multiple dispatch with type lattice traversal

Real

Number

FloatingPoint Rational

Float64 BigFloat…

Integer

is a parameter ofis a subtype of

BigInt

Any

Int64…

no method here try supertype

super(Int64) = Signed

Page 27: What's next in Julia

Signed

Multiple dispatch with type lattice traversal

Real

Number

FloatingPoint Rational

Float64 BigFloat…

Integer

is a parameter ofis a subtype of

BigInt

Any

Int64…

no method here try supertype

super(Int64) = Signed

no method here either super(Signed) = Integer

Page 28: What's next in Julia

Signed

Multiple dispatch with type lattice traversal

Real

Number

FloatingPoint Rational

Float64 BigFloat…

Integer

is a parameter ofis a subtype of

BigInt

Any

Int64…

no method here try supertype

super(Int64) = Signed

no method here either super(Signed) = Integer

found a method

Page 29: What's next in Julia

Signed

Multiple dispatch with type lattice traversal

Real

Number

FloatingPoint Rational

Float64 BigFloat…

Integer

is a parameter ofis a subtype of

BigInt

Any

Int64…

Page 30: What's next in Julia

Signed

Multiple dispatch with type lattice traversal

Real

Number

FloatingPoint Rational

Float64 BigFloat…

Integer

is a parameter ofis a subtype of

BigInt

Any

Int64…

Page 31: What's next in Julia
Page 32: What's next in Julia

Julia

LLVM IR

Machine assembly

Page 33: What's next in Julia
Page 34: What's next in Julia

aggressive type specialization !compiler generates specialized methods for different input types to the same generic function

Page 35: What's next in Julia

unitful computations with essentially no runtime overhead

Keno Fischer Harvard Physics and Mathematics

Page 36: What's next in Julia

Type lattice of arrays

DenseArray{T, N}

AbstractArray{T, N}

Array{T, N}

is a subtype of

Any

Array{T,1}===Vector{T}Array{T,2}===Matrix{T}

A single parametric type defines many types of matrices Matrix{Float64}, Matrix{Int64},Matrix{BigFloat}, Matrix{Complex128},Matrix{Rational}, Matrix{Quaternion{Float64}},…

Page 37: What's next in Julia

Type lattice of arrays

DenseArray{T, N}

AbstractArray{T, N}

Array{T, N}

is a subtype of

Any

Array{T,1}===Vector{T}Array{T,2}===Matrix{T}

A single parametric type defines many types of matrices Matrix{Float64}, Matrix{Int64},Matrix{BigFloat}, Matrix{Complex128},Matrix{Rational}, Matrix{Quaternion{Float64}},…

Page 38: What's next in Julia

Type lattice of arrays

DenseArray{T, N}

AbstractArray{T, N}

Array{T, N}

is a subtype of

Any

Array{T,1}===Vector{T}Array{T,2}===Matrix{T}

rotation matrices structured matrices

distributed arrays

A single parametric type defines many types of matrices Matrix{Float64}, Matrix{Int64},Matrix{BigFloat}, Matrix{Complex128},Matrix{Rational}, Matrix{Quaternion{Float64}},…

Page 39: What's next in Julia

Multi-methods for linear algebra

What can I do with/to a thing?

find eigenvalues and eigenvectors

find singular values

find singular values and vectors

find eigenvalues

generic function

objectsmethods

general matrix

symmetric tridiagonal matrix

bidiagonal matrix

Methods can take advantage of special matrix structures

eigvals

eigfact

svdvals

svdfact

Matrix

SymTridiagonal

Bidiagonal

Page 40: What's next in Julia

So how does this help us with linear algebra?

Page 41: What's next in Julia

So how does this help us with linear algebra?

Multi-method dispatch on special matrix types

Page 42: What's next in Julia

So how does this help us with linear algebra?

Multi-method dispatch on special matrix types

Page 43: What's next in Julia

So how does this help us with linear algebra?

Multi-method dispatch on special matrix types

stev!{T<:BlasFloat} calls sgestvdgestvcgestvzgestv

and handles workspace memory allocation

Page 44: What's next in Julia

So how does this help us with linear algebra?

Multi-method dispatch with generic fallbacks

Matrix operations on general rings

Page 45: What's next in Julia

So how does this help us with linear algebra?

Multi-method dispatch with generic fallbacks

Matrix operations on general rings textbook algorithm

Page 46: What's next in Julia

So how does this help us with linear algebra?

Multi-method dispatch with generic fallbacks

Matrix operations on general rings

Page 47: What's next in Julia

Matrix factorization types

Page 48: What's next in Julia

Iterative algorithms as iterators

for item in iterable #bodyend!

#is equivalent to!

state = start(iterable) while !done(iterable, state) item, state = next(iterable, state) # bodyend

Page 49: What's next in Julia

Conjugate gradients (Hestenes-Stiefel)

http://en.wikipedia.org/wiki/Conjugate_gradient_method

Page 50: What's next in Julia

Conjugate gradients (Hestenes-Stiefel)

http://en.wikipedia.org/wiki/Conjugate_gradient_method

Can we write this as an iterator?

Page 51: What's next in Julia

Conjugate gradients (Hestenes-Stiefel)

http://en.wikipedia.org/wiki/Conjugate_gradient_method

Can we write this as an iterator?

state = start(iterable)

done(iterable, state)

Page 52: What's next in Julia

Conjugate gradients (Hestenes-Stiefel)

http://en.wikipedia.org/wiki/Conjugate_gradient_method

state = start(iterable)

done(iterable, state)

state, dx = next(iterable, state)

Page 53: What's next in Julia

immutable cg_hs #iterative solver K :: KrylovSpace #wraps A, v0, k t :: Terminator #termination criteriaend immutable cg_hs_state r :: Vector #residual p :: Vector #search direction rnormsq :: Float64 #Squared norm of previous residual iter :: Int #iteration countend start(a::cg_hs) = cg_hs_state(a.K.v0, zeros(size(a.K.v0,1)), Inf, 0) function next(a::cg_hs, s::cg_hs_state) rnormsq = dot(s.r, s.r) p = s.r + (rnormsq/s.rnormsq)*s.p Ap = a.K.A*p α = rnormsq / dot(p, Ap) α*p, cg_hs_state(s.r-α*Ap, p, rnormsq, s.iter+1)end done(a::cg_hs, s::cg_hs_state) = done(a.t, s)!K = method(KrylovSpace(A, b, k), Terminator())x += reduce(+, K) # for dx in K; x += dx; end

Hestenes-Stiefel CG

Page 54: What's next in Julia

immutable cg_hs #iterative solver K :: KrylovSpace #wraps A, v0, k t :: Terminator #termination criteriaend immutable cg_hs_state r :: Vector #residual p :: Vector #search direction rnormsq :: Float64 #Squared norm of previous residual iter :: Int #iteration countend start(a::cg_hs) = cg_hs_state(a.K.v0, zeros(size(a.K.v0,1)), Inf, 0) function next(a::cg_hs, s::cg_hs_state) rnormsq = dot(s.r, s.r) p = s.r + (rnormsq/s.rnormsq)*s.p Ap = a.K.A*p α = rnormsq / dot(p, Ap) α*p, cg_hs_state(s.r-α*Ap, p, rnormsq, s.iter+1)end done(a::cg_hs, s::cg_hs_state) = done(a.t, s)!K = method(KrylovSpace(A, b, k), Terminator())x += reduce(+, K) # for dx in K; x += dx; end

Hestenes-Stiefel CG

Abstracts out termination check and solution update steps

Page 55: What's next in Julia

Native parallelism constructs

Page 56: What's next in Julia

Native parallelism constructs

Page 57: What's next in Julia

Native parallelism constructs

Page 58: What's next in Julia

Distributed arrays

Page 59: What's next in Julia

IJulia: Julia in IPython Notebook

Page 60: What's next in Julia

IJulia: Julia in IPython Notebook

Page 61: What's next in Julia

JuMP: writing simple DSLs in Julia

Iain Dunning Miles LubinMIT

Operations Research

Page 62: What's next in Julia

Andreas N. Jensen U. Copenhagen

Economics

Alan EdelmanJeff Bezanson Stefan Karpinski Viral B. Shah

Carlo Baldassi Poly. Torino

Neuroscience

Tim E. Holy WUSTL

Anatomy

Douglas M. Bates Wisconsin-Madison

Statistics

Steven G. Johnson MIT

Mathematics