Feasibility of Racket for scientific and engineering calculations

780 views
Skip to first unread message

John Kitchin

unread,
Nov 2, 2015, 8:15:25 PM11/2/15
to Racket Users
Hi all,

I am exploring whether Racket could be a Lisp replacement for Python in scientific and engineering calculations. I currently use Python extensively in teaching chemical engineering courses (http://kitchingroup.cheme.cmu.edu/pycse/) and in running molecular simulations (http://kitchingroup.cheme.cmu.edu/dft-book/), but I am interested in transitioning these to a Lisp.

Why? Because I really like writing Lisp code, and some interesting things I can do with it. My current experience is all with emacs-lisp, which at the moment has no hope for replacing Python as it lacks a real ffi.

Python works for scientific/engineering calculations because of numpy/scipy/matplotlib which provide the majority of our needs, and largely they just wrap C/Fortran numerical libraries. It is also distributed with batteries included that make it trivial to install these days. It seems like Racket can do this too.

How feasible would it be to use Racket to solve the problems described here: http://kitchingroup.cheme.cmu.edu/pycse/pycse.pdf

I am trying to gauge how difficult it would be to start using Racket for these problems. Does anyone know of any similar kinds of projects as my Python project above in Racket?

Thanks!

Alexey Cherkaev

unread,
Nov 3, 2015, 4:36:07 AM11/3/15
to Racket Users
Hi John,

I am a PhD student doing a degree in chemical engineering. I am doing some process modelling work using MIT-Scheme (scmutils to be precise) at the moment but I would like to port it to Racket, which is feasible, but does require some extra work:

- Racket already has great plotting library
- FFI is relatively simple, but some conscious decisions need to be made when working with unmanaged memory of C-libraries.
- I have on my TODO list to make an FFI-wrapper for Sundials library. It is not a top priority right now though as I need to have a working prototype of my model first. If there are other people interested in this wrapper, it would be great to pull the efforts together to make it (and I can also move it up on my priority list).


Cheers,
Alexey

Konrad Hinsen

unread,
Nov 3, 2015, 5:10:51 AM11/3/15
to John Kitchin, Racket Users
John,

> I am exploring whether Racket could be a Lisp replacement for
> Python in scientific and engineering calculations. I currently use
> Python extensively in teaching chemical engineering courses
> (http://kitchingroup.cheme.cmu.edu/pycse/) and in running molecular
> simulations (http://kitchingroup.cheme.cmu.edu/dft-book/), but I am
> interested in transitioning these to a Lisp.

If "a Lisp" is all you want, the easiest transition path would be to
Hy (hylang.org). That said, Racket has much more to offer in terms of
a "Lisp experience".

> Python works for scientific/engineering calculations because of
> numpy/scipy/matplotlib which provide the majority of our needs, and
> largely they just wrap C/Fortran numerical libraries. It is also
> distributed with batteries included that make it trivial to install
> these days. It seems like Racket can do this too.

Yes. The main difference between Python and Racket in that respect is
the size of the already existing ecosystem for scientific computing.
Racket has much less (much, much, much less), although what's there
(the math library, in particular providing arrays and plotting) is
excellent.

Racket's CFFI can be used much like Python's, with the added advantage
that you can leverage the macro system to generate much of the
boilerplate code associated with that kind of work. It's just that
almost everything remains to be done, whereas in the Python world most
popular C and Fortran libraries already have FFI-based wrappers.

If you decide to try out Racket, consider a look at

https://github.com/pedropramos/PyonR

which is a Python implementation for the Racket universe. It won't help you
with the CFFI stuff, but it will let you reuse pure Python code.

Finally, you may be interested in a summary of my own experiences with
Racket for scientific computing:

https://khinsen.wordpress.com/2014/05/10/exploring-racket/

> How feasible would it be to use Racket to solve the problems
> described here: http://kitchingroup.cheme.cmu.edu/pycse/pycse.pdf

I don't expect any difficulties with doing all that in Racket, but do expect
to spend some serious amount of time on it.

Konrad.

John Kitchin

unread,
Nov 3, 2015, 7:10:36 AM11/3/15
to Konrad Hinsen, Racket Users
Thanks, your blog post very succinctly summarizes what I have been
looking for as a feasibility analysis. We are in quite similar places of
thinking about the scientific computing present and looking to the
scientific computing future.

It doesn't look like Racket (or anything) will be an easy replacement
for what we do in Python now, but Racket still looks the most promising
to me at the moment for what I am looking for in the long run. I look
forward to seeing how it progresses.

Thanks also for the pointers to these interesting projects!

Best wishes,
--
Professor John Kitchin
Doherty Hall A207F
Department of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213
412-268-7803
@johnkitchin
http://kitchingroup.cheme.cmu.edu

Jens Axel Søgaard

unread,
Nov 10, 2015, 12:29:04 PM11/10/15
to John Kitchin, Racket Users
A few useful resources:

Matrices

Science Collection

Math library

Also: If you are looking for concrete algorithms - just ask. Chances are that
someone has a Racket and/or Scheme implementation lying around.

If you are interested in symbolic computations I have a few ideas.

/Jens Axel



--
You received this message because you are subscribed to the Google Groups "Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to racket-users...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
--
Jens Axel Søgaard

John Kitchin

unread,
Nov 10, 2015, 10:34:50 PM11/10/15
to Jens Axel Søgaard, Racket Users
Those are great resources! Thanks!

Marc Kaufmann

unread,
Nov 12, 2015, 11:26:25 AM11/12/15
to Racket Users, jens...@soegaard.net, jkit...@andrew.cmu.edu
Since you mention symbolic computations: is there anything that does symbolic differentiation in Racket - I know Maxima is written in Common Lisp. I would I would be happy with only differentiation and little of the other stuff, if only to check my own computations (in economics) as I have perform a sign-error in 25% of the cases...

Jens Axel Søgaard

unread,
Nov 12, 2015, 11:31:08 AM11/12/15
to Marc Kaufmann, Racket Users, jkit...@andrew.cmu.edu
Hi Marc,

Take a look at:


Start with the readme and play with a few examples.

Skim (later parts) of:


to see what's implemented.

Any bug reports and comments are welcome.

/Jens Axel


--
Jens Axel Søgaard

Reply all
Reply to author
Forward
0 new messages