• No results found

OwlDE: Making ODEs first-class Owl citizens

N/A
N/A
Protected

Academic year: 2021

Share "OwlDE: Making ODEs first-class Owl citizens"

Copied!
4
0
0

Bezig met laden.... (Bekijk nu de volledige tekst)

Hele tekst

(1)

University of Groningen

OwlDE

Seri, Marcello; Kao, Ta-Chu

Published in:

Journal of Open Source Software

DOI:

10.21105/joss.01812

IMPORTANT NOTE: You are advised to consult the publisher's version (publisher's PDF) if you wish to cite from it. Please check the document version below.

Document Version

Publisher's PDF, also known as Version of record

Publication date: 2019

Link to publication in University of Groningen/UMCG research database

Citation for published version (APA):

Seri, M., & Kao, T-C. (2019). OwlDE: Making ODEs first-class Owl citizens. Journal of Open Source Software, 4(44), [1812]. https://doi.org/10.21105/joss.01812

Copyright

Other than for strictly personal use, it is not permitted to download or to forward/distribute the text or part of it without the consent of the author(s) and/or copyright holder(s), unless the work is under an open content license (like Creative Commons).

Take-down policy

If you believe that this document breaches copyright please contact us providing details, and we will remove access to the work immediately and investigate your claim.

Downloaded from the University of Groningen/UMCG research database (Pure): http://www.rug.nl/research/portal. For technical reasons the number of authors shown on this cover page is limited to 10 maximum.

(2)

OwlDE: making ODEs first-class Owl citizens

Marcello Seri

1

and Ta-Chu Kao

2

1 Bernoulli Institute for Mathematics, Computer Science and Artificial Intelligence, University of

Groningen 2 Computational and Biological Learning Lab, Department of Engineering, University of Cambridge DOI:10.21105/joss.01812 Software • Review • Repository • Archive

Editor: Matthew Sottile Reviewers: • @xoolive • @rljacobson • @mjsottile Submitted: 04 October 2019 Published: 20 December 2019 License

Authors of papers retain copyright and release the work under a Creative Commons Attribution 4.0 International License (CC-BY).

Summary

After only three years of intensive development and continuous optimisation, Owl has emerged in the OCaml ecosystem as a versatile and powerful scientific programming library, competitive with mainstream libraries such as SciPy and NumPy. What sets Owl apart is that it brings under one umbrella the flexibility of a dynamical language and the power and safety of the OCaml type system (Wang, 2017).

Today, Owl can be used to solve a wide range of scientific problems: it provides efficient types for handling multidimensional arrays and linear algebra operations built on top of BLAS and LAPACK; it supports machine learning applications with a powerful computational graph engine and automatic differentiation pipeline. To improve efficiency, Owl allows offloading computations to distributed systems and GPUs. With the recent addition of dataframes and integration with Jupyter Notebooks provided by ocaml-jupyter, Owl has the chance to become an excellent framework for exploratory mathematical analysis.

A notable omission in Owl’s ecosystem, when compared to similar solutions in python and Julia, was a package for solving ordinary differential equations. To fill this need, we designed OwlDE, a flexible and efficient ODE engine for Owl.

Design of the core module

The lack of automation around type classes and dynamic typing in OCaml may seem at first a huge impediment to designing a flexible and ergonomic ODE integrator library. Indeed, such a library should ideally allow the users to seamlessly use different algorithms that require different kinds of inputs and options, and return varying kinds of outputs. Such constraints on input/output types pose a major problem for the strong static type system of OCaml, even if they are in principle implementable exploiting advanced language features, and were one of the central issues in designing OwlDE.

We iterated various options and settled on the use of first-class modules. These have been introduced in OCaml since version 3.12, and further improved in subsequent releases. With first-class modules the user can parametrise functions over modules, allowing us to find a middle ground between the verbosity of functorial code and the composability of OCaml functions. The flexibility of this API allowed us to provide integration and bindings to external frameworks like SUNDIALS or ODEPACK in a completely seamless way. Such an API allowed us to compare native implementations with industry-grade solvers, both for mathematical exploration, testing and benchmark purposes.

To give an idea of the interface, the following code allows to integrate the initial value problem ˙

x = f (x, t) = Ax, x(t0) = x0

Seri et al., (2019). OwlDE: making ODEs first-class Owl citizens. Journal of Open Source Software, 4(44), 1812. https://doi.org/10.21105/ joss.01812

(3)

where A is the 2x2 matrix (1,−1; 2, −3), x0= (−1; 1) and t0= 0. open Owl open Owl_ode open Owl_ode.Types (* f(x,t) *) let f x t = let a = [|[|1.; -1.|]; [|2.; -3.|]|] |> Mat.of_arrays in Mat.(a *@ x) (* temporal specification:

construct a record using the constructor T1 and includes information of start time, duration, and step size.*)

let tspec = T1 {t0 = 0.; duration = 2.; dt=1E-3}

(* initial state of the system *)

let x0 = Mat.of_array [|-1.; 1.|] 2 1

(* ts and xs will contain the integrated times and the values of the state x at each of those times *)

let ts, xs = Ode.odeint Native.D.rk4 f x0 tspec ()

The tight integration with the OCaml and Owl ecosystem allows us also to benefit from some of their strengths. The strong static type system made refactoring and code analysis an immediate task, and greatly reduced the necessary test surface. The powerful functorised ndarray subsystem exposed by Owl made the library trivially extensible also in somewhat unexpected directions. Indeed, it is possible to take the integrators exposed by OwlDE and use them to reproduce the work of (Chen, Rubanova, Bettencourt, & Duvenaud, 2018) without the need to rewrite any of the core functions, as done in adjoint_ode. Similarly, it is possible to extend the range of integrators and introduce new ones rather seamlessly, as done in cviode, an implementation of the integrators introduced in (Vermeeren, Bravetti, & Seri, 2019).

One further strength of this library, comes from its native OCaml component, which can be compiled to JavaScript and used for interactive simulations in the browser, as demoed during the OCaml Workshop at ICFP 2019 in Berlin. The demo and the usage instructions are freely available atowlde-demo-icfp2019.

Conclusion

When it comes to scientific programming, fast prototyping and ease of use have long been considered the province of dynamically-typed languages like python. However, our experience developing Owl and OwlDE, and the feedback from users who primarily use these tools for research, suggests otherwise. In fact, the OCaml type system often ensures correctness and speeds up computations without increasing verbosity, or hindering usability and readability. In many cases, we discovered that porting python code to OCaml code via Owl was nearly trivial and the resulting OCaml code was often comparable in length, but with the added benefits of fewer runtime errors and improved performance. We look forward to developing OwlDE and Owl further with inputs from the OCaml community.

Seri et al., (2019). OwlDE: making ODEs first-class Owl citizens. Journal of Open Source Software, 4(44), 1812. https://doi.org/10.21105/ joss.01812

(4)

Acknowledgements

The authors would like to thank Liang Wang, Guillaume Hennequin, the Cambridge OCaml Labs and all the contributors to Owl and Owl_ode for their support and help throughout the development of the project.

References

Chen, T. Q., Rubanova, Y., Bettencourt, J., & Duvenaud, D. K. (2018). Neu-ral ordinary differential equations. In S. Bengio, H. Wallach, H. Larochelle, K. Grauman, N. Cesa-Bianchi, & R. Garnett (Eds.), Advances in neural information processing systems 31 (pp. 6571–6583). Curran Associates, Inc. Retrieved from

http://papers.nips.cc/paper/7892-neural-ordinary-differential-equations.pdf

Vermeeren, M., Bravetti, A., & Seri, M. (2019). Contact variational integrators. Journal of Physics A: Mathematical and Theoretical. doi:10.1088/1751-8121/ab4767

Wang, L. (2017). Owl: A general-purpose numerical library in ocaml. Retrieved from https: //arxiv.org/abs/1707.09616

Seri et al., (2019). OwlDE: making ODEs first-class Owl citizens. Journal of Open Source Software, 4(44), 1812. https://doi.org/10.21105/ joss.01812

Referenties

GERELATEERDE DOCUMENTEN

In a one- week emotional reflection experiment using the experience sampled data of 28 wearable users, their scores on the Toronto Alexithymia Scale 20 were compared to scores of

By using new technologies, interacting with the object and being able to choose what you want to know, this product will also attract younger visitors to the museum. The museum gets

Most similarities between the RiHG and the three foreign tools can be found in the first and second moment of decision about the perpetrator and the violent incident

This study provides insight into the effects of thematic congruence in digital native advertising on ad recognition, ad credibility and ad attitude among the Dutch people.. The

The first part of the results presented will focus on the evolution of the termination shock, outer boundary, and average magnetic field in the PWN, while the second part will focus

• You must not create a unit name that coincides with a prefix of existing (built-in or created) units or any keywords that could be used in calc expressions (such as plus, fil,

The package is primarily intended for use with the aeb mobile package, for format- ting document for the smartphone, but I’ve since developed other applications of a package that

An algebra task was chosen because previous efforts to model algebra tasks in the ACT-R architecture showed activity in five different modules when solving algebra problem;