Member of the Helmholtz Association 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
Motivation 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
a bunch of (new) requirements 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
which lead to performance problems 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
Julia visualization solutions Plotly Bokeh Gadfly most popular 2D plotting system for Julia PyPlot Python de-facto standard ( workhorse ) PyPlot 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 Winston Gadfly GLPlot 2D 3D 5
Problems so far Crux of the matter separated 2D and (hardware accelerated) 3D world Interop some graphics backends "only" produce "figures" no presentation of continuous data streams poor performance on large data sets Speed Quality 6
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
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
How it works: GR layer architecture Qt console interaction Notebooks support for Python or Julia kernels Use GR as a Matplotlib backend; mix GR, MPL and GR3 code glgr / igr App C / ObjC OpenGL Qt / wx event loop ES socket communication IPython GR off-screen rendering PyPy Swift direct rendering GR3 C / C++ JavaScript generation Browser... POV-Ray generation GLUT GLFW wxglcanvas QGLWidget Generate ray-traced graphics scenes Create HTML5 output GKS WebGL OpenGL (WGL / CGL / GLX) POV-Ray Create video animations on the fly GKS logical device drivers Qt wx X11 Quartz Win32 TikZ PDF MOV gksqt GKSTerm LATEX PS 0MQ HTML5 SVG OpenGL... More logical device drivers / plugins: CGM, GKSM, GIF, RF, UIL WMF, Xfig GS (BMP, JPEG, PNG, TIFF) Highlights: simultaneous output to multiple output devices direct generation of MPEG4 image sequences flicker-free display ("double buffering ) IPython / Jupyter notebook integration
Matplotlib using the GR backend $( $& Arrow Line2D %#"# $% $)"' $# * $%"' ( $#"# Ellipse FancyBoxPatch & )"' % '"#! $! "!! %! $! #! "! #! "! # % & + ( #"* #") &"( #"& &"# #"# %"( 135 $"( &"# &"( '"# '"( ("# #"* #") &"( #"& &"# #"# %"( %"#! #") $"( &"( #!"# "!)+ "!'( "!%& "!## "!## "!%& "!'( "!)+ #!"# 6 4 0 ( 225 315! #"* &"# #! # &$% # %$') # &$* # %$(+ # '$% # '$% 2! #"& %"( %! $! 10 180 '"# %"# %! $"% '"( $"( $! 8! #"* %"( #! # %$&' # &$* '"# '"( # &$% # %$* %$% %$* &$% &$* '$% )/07,5/2- * (,0*82*9 1,6.!*440/+*7/32 73./-.# 5,63087/32 75/+327385/2-" 45! #") +327385- :/7. 0,9,06 %$%% &$%! #"& %"# %"# "! #"# $# *!! "! ( $"% '"# $"( %$&' ) %$% %"'!%!% '"( $"# $"# %$') 90 4+30351,6. :/7. 0,9,06 ("# &$% &! ' PathPatch %$(+ # %$* # Polygon &$* %$* %! Circle %$), &! $'"# - Rectangle "!! +, Wedge 051..-7-7/67!'%% 431276" '$% %%"' & $ " $ $ & " $ & ( "!' %$' "!* "!( "!& "!$ "!" "!$ "!& "!( "!* "!% "!$ "!" %$% "!$ "!% "!' #!" # %$' "!& #!" & ( ( 270 # &$% # &$% # %$' %$% %$' &$% "!& "!" "!" "!& "!& #!" #!" 10
GR.jl in action 11
GR + PyPlot interop Important: tells MPL backend not to update PyPlot GR3 GR 12
using GR in Juno simple IDE syntax highlighting command completion inline graphics click images to view notebooks
or Jupyter 700 Performance (anim.jl) 600 fps 500 400 300 200 100 0 MPL MPL+GR GR click images to view notebooks
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
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
Thank you for your attention Questions? Contact: j.heinen@fz-juelich.de @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