gr.jl - plotting for julia based on gr

17
GR.jl – Plotting for Julia based on GR June 24 th – 28 th , 2015 Massachusetts Institute of Technology, Cambridge, Massachusetts | JuliaCon 2015 | Josef Heinen | @josef_heinen Member of the Helmholtz Association

Upload: josef-heinen

Post on 14-Aug-2015

186 views

Category:

Software


3 download

TRANSCRIPT

Page 1: GR.jl - Plotting for Julia based on GR

GR.jl – Plotting for Julia based on GR

June 24th – 28th, 2015

Massachusetts Institute of Technology, Cambridge, Massachusetts | JuliaCon 2015 | Josef Heinen | @josef_heinen

Mem

ber o

f the

Hel

mho

ltz A

ssoc

iatio

n

Page 2: GR.jl - Plotting for Julia based on GR

June 24th – 28th, 2015 Josef Heinen, Forschungszentrum Jülich, Peter Grünberg Institute, Scientific IT Systems

The GR framework was originally developed for Python with the objective of providing easy-to-use methods for:

✓ displaying scattering spectra in real-time

✓ visualizing and analyzing two- and three-dimensional data sets 

✓ creating publication-quality and web-ready graphics

✓ making glossy figures for scientific journals or press releases

2

Motivation

Page 3: GR.jl - Plotting for Julia based on GR

June 24th – 28th, 2015 Josef Heinen, Forschungszentrum Jülich, Peter Grünberg Institute, Scientific IT Systems

✓ speed up plotting times for real-time monitoring purposes

✓ visualize large data sets, probably with a dynamic component, preferably in real-time 

✓ create animations or videos on the fly

3

… a bunch of (new) requirements

Page 4: GR.jl - Plotting for Julia based on GR

June 24th – 28th, 2015 Josef Heinen, Forschungszentrum Jülich, Peter Grünberg Institute, Scientific IT Systems

How can we fix them?

✓ Several Python modules can be compiled into native code, making them much faster (Cython)

✓ Compiling hotspots on the fly (Numba, PyPy) can significantly speed up numerical code segments

✓ Computations can be distributed, but …

… these approaches cannot easily be applied to visualization software!

➟ What about Julia?

4

… which lead to performance problems

Page 5: GR.jl - Plotting for Julia based on GR

June 24th – 28th, 2015 Josef Heinen, Forschungszentrum Jülich, Peter Grünberg Institute, Scientific IT Systems

Julia visualization solutions

Gadfly — most popular 2D plotting system for Julia

PyPlot — Python de-facto standard (“workhorse”)

Winston — MATLAB-like 2D plotting

Plotly — Julia wrapper for the plot.ly REST API

GLPlot — powerful 3D graphics(successor GLVisualize on the way)

OpenGL — fast, but low-level API

5

2D 3D

Gadfly

Bokeh

GLPlot

PyPlot

Plotly

Winston

Page 6: GR.jl - Plotting for Julia based on GR

June 24th – 28th, 2015 Josef Heinen, Forschungszentrum Jülich, Peter Grünberg Institute, Scientific IT Systems

separated 2D and (hardware accelerated) 3D world

some graphics backends "only" produce "figures"➟ no presentation of continuous data streams

poor performance on large data sets

Problems so far — Crux of the matter

6

Quality

Interop

Speed

Page 7: GR.jl - Plotting for Julia based on GR

June 24th – 28th, 2015 Josef Heinen, Forschungszentrum Jülich, Peter Grünberg Institute, Scientific IT Systems

Use GR to achieve more graphics performance

✓ procedural graphics backend (completely written in C) ➟ presentation of continuous data streams

✓ builtin support for 2D plotting and OpenGL (GR3) ➟ coexistent 2D and 3D world

✓ interoperability with GUI toolkits and Web frameworks➟ good user interaction

✓ … ready for Julia v0.4

7

Page 8: GR.jl - Plotting for Julia based on GR

June 24th – 28th, 2015 Josef Heinen, Forschungszentrum Jülich, Peter Grünberg Institute, Scientific IT Systems

Use GR to extend PyPlot’s capabilities

✓ combine the power of PyPlot and GR ➟ next Matplotlib release will allow selecting the backend by setting the environment variable MPLBACKEND

✓ produce video contents on the fly by adding a single line of code ➟ no need to import an animation module or write extra code

✓ create plots containing both 2D and 3D graphics elements

8

Page 9: GR.jl - Plotting for Julia based on GR

June 24th – 28th, 2015 Josef Heinen, Forschungszentrum Jülich, Peter Grünberg Institute, Scientific IT Systems

How it works: GR layer architecture

GKS logical device drivers

C / C++

GKS

GR

OpenGL (WGL / CGL / GLX)

POV-Ray generation

off-screen rendering

direct rendering

Browser

JavaScriptgeneration

WebGL

IPython

Win32X11

GKSTermgksqt LATEX

Qt Quartz PDF

C / ObjC

OpenGL ES

glgr / iGR Appsocket

communication

Qt / wx event loop

0MQ OpenGL

More logical device drivers / plugins:– CGM, GKSM, GIF, RF, UIL– WMF, Xfig– GS (BMP, JPEG, PNG, TIFF)

...

HTML5

wx

POV-Ray

GLUTGLFW

wxGLCanvasQGLWidget

...

SVGPSMOV

GR3

Highlights:– simultaneous output to multiple output devices– direct generation of MPEG4 image sequences– flicker-free display ("double buffering”)– IPython / Jupyter notebook integration

TikZ

SwiftPyPy

Generate ray-traced graphics scenes

Notebooks support for Python or Julia kernels

Use GR as a Matplotlib backend;

mix GR, MPL and GR3 code

Create HTML5 output

Qt console interaction

Create video animations on the fly

Page 10: GR.jl - Plotting for Julia based on GR

June 24th – 28th, 2015 Josef Heinen, Forschungszentrum Jülich, Peter Grünberg Institute, Scientific IT Systems

Matplotlib using the GR backend

10

Circle

Rectangle

Wedge

Polygon

Ellipse

Arrow

PathPatch

FancyBoxPatch

Line2D

! % # % & ( * $#

+

! %

#

%

&

(

*

$#

$%

$&

$(

-

#"#

%"'

'"#

)"'

$#"#

$%"'

$'"#

$)"'

%#"#

%%"'

+ ,

'

%! $!

#! "!

!"!

#!$!

%!

(

%!

$! #!

"!!

"!#!

$!%!

)

"!!

&!

!

&!

"!!

# '$% # &$* # &$% # %$* %$% %$* &$% &$* '$%# '$%

# &$*

# &$%

# %$*

%$%

%$*

&$%

&$*

'$%051..-7- 7/67 !'%% 431276"

# %$(+

# %$')

# %$&'

%$%%

%$&'

%$')

%$(+

%$),

$"# $"( %"# %"( &"# &"( '"# '"( ("#$"#

$"(

%"#

%"(

&"#

&"(

'"#

'"(

("#4+30351,6. :/7. 0,9,06

! #"*

! #")

! #"&

#"#

#"&

#")

#"*

$"%

$"( %"# %"( &"# &"( '"# '"(

$"(

%"#

%"(

&"#

&"(

'"#

'"(

+327385- :/7. 0,9,06

! #"*

! #")

! #"&

#"#

#"&

#")

#"*

$"%

45°

90°

135°

180°

225°

270°

315°

24

68

10

( &

$"

$&

( (

&

$

"

$

&

(

#!"#

"!)+

"!'(

"!%&

"!##

"!##

"!%&

"!'(

"!)+

#!"#

"!*

"!(

"!&

"!$

"!"

"!$

"!&

"!(

"!*

# &$% # %$' %$% %$' &$%# &$%

# %$'

%$%

%$'

&$%

)/07,5/2- * (,0*82*9 1,6.!*440/+*7/32 73 ./-.# 5,63087/32 75/+327385/2-"

#!"

"!&

"!"

"!&

#!" #!"

"!&

"!"

"!&

#!"

"!'

"!%

"!$

"!"

"!$

"!%

"!'

Page 11: GR.jl - Plotting for Julia based on GR

June 24th – 28th, 2015 Josef Heinen, Forschungszentrum Jülich, Peter Grünberg Institute, Scientific IT Systems

GR.jl in action …

11

Page 12: GR.jl - Plotting for Julia based on GR

June 24th – 28th, 2015 Josef Heinen, Forschungszentrum Jülich, Peter Grünberg Institute, Scientific IT Systems

GR + PyPlot interop

12

PyPlot

GR3

GR

Important: tells MPL backend not to update

Page 13: GR.jl - Plotting for Julia based on GR

June 24th – 28th, 2015 Josef Heinen, Forschungszentrum Jülich, Peter Grünberg Institute, Scientific IT Systems

… using GR in Juno

click images to view notebooks …

✓ simple IDE

✓ syntax highlighting

✓ command completion

✓ inline graphics

Page 14: GR.jl - Plotting for Julia based on GR

June 24th – 28th, 2015 Josef Heinen, Forschungszentrum Jülich, Peter Grünberg Institute, Scientific IT Systems

… or Jupyter

Performance (anim.jl)

0

100

200

300

400

500

600

700

MPL MPL+GR GR

fps

click images to view notebooks …

Page 15: GR.jl - Plotting for Julia based on GR

June 24th – 28th, 2015 Josef Heinen, Forschungszentrum Jülich, Peter Grünberg Institute, Scientific IT Systems

What happens next?

✓ provide more convenience function

✓ migrate the GR3 library to modern OpenGL (using OpenGL shader language) ➟ visualize millions of vertices / faces

✓ simplify the installation

✓ migrate the molecule renderer (mogli) from Python to C

✓ create a JavaScript based GR backend using an LLVM-to-JS compiler infrastructure, e.g. emscripten(in a proof-of-concept we could show, that GR + GKS can be transpiled to JS without any modifications)

15

Page 16: GR.jl - Plotting for Julia based on GR

June 24th – 28th, 2015 Josef Heinen, Forschungszentrum Jülich, Peter Grünberg Institute, Scientific IT Systems

Resources

✓ Website: http://gr-framework.org

✓ GR package: https://github.com/jheinen/GR.jl

✓ Mogli package: https://pypi.python.org/pypi/mogli

✓ Talk material: GR.jl – Plotting for Julia based on GR

16

Page 17: GR.jl - Plotting for Julia based on GR

June 24th – 28th, 2015 Josef Heinen, Forschungszentrum Jülich, Peter Grünberg Institute, Scientific IT Systems

Thank you for your attention

Questions?

Contact: [email protected] @josef_heinen

Thanks to: Florian Rhiem, Ingo Heimbach, Christian Felder, David Knodt, Jörg Winkler, Fabian Beule, Philip Klinkhammer, Marvin Goblet, Daniel Kaiser, et al.

17