gr.jl - plotting for julia based on gr
TRANSCRIPT
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
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
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
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
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
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
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
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
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
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
! #"*
! #")
! #"&
#"#
#"&
#")
#"*
$"%
0°
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-"
#!"
"!&
"!"
"!&
#!" #!"
"!&
"!"
"!&
#!"
"!'
"!%
"!$
"!"
"!$
"!%
"!'
June 24th – 28th, 2015 Josef Heinen, Forschungszentrum Jülich, Peter Grünberg Institute, Scientific IT Systems
GR.jl in action …
11
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
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
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 …
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
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
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