[Dune-devel] [SOCIS2014] Integrating DUNE with Python

Christian Engwer christian.engwer at uni-muenster.de
Sun May 11 23:43:41 CEST 2014


Dear Mihai,

our idea of the project is to add coarse grain python interface to
DUNE. The challenge is that we have several implementations of the
same interface and make heavy use of C++ templates. Thus it is
necessary to keep track of the template versions we are dealing
with. All this leads to the situation, that we can not create and
compile the python interface a-priori, but have to generate these on
the fly.

I see different steps towards the total goal:

a) we must be able to generate python-interface code automatically.
   In the first place this should be for a given class with given
   template parameters: e.g. the user specifies that we wrap
   Dune::YaspGrid<2> and all the interfaces (what ever we want to have
   here) are generated on the fly.

   At this stage we don't have to decide on a particular set of
   functions which we want to wrap. In general we will focus more on
   the expensive coarse grain functions and avoid the fine grained
   interfaces (e.g. direct entity access) ad these will be too
   expensive.

   Here we have no particular favorite yet. Different people have been
   using different tools. Some people have used swig, but I personally
   consider this as a problematic choice, as swig is not using a c++
   parser to parse the c++ code. People have also used Cython and
   boost-python, both with their own pros and cons. Here one important
   part would involve a small evaluation of the different options.

b) we must compile and load this auto-generated python-interface.
   The "Instant" project is a good starting point for this. Other
   similar projects are for example python-weave, which is even
   heavier. We don't need the most fancy implementation here, but
   something that fits our needs.

c) using existing python wrappers we want to instantiate other classes
   and use these classes as template parameters. For example if we
   want to mimic the main code in DUNE-PDELab and setup a
   GridFunctionSpace:

     using DuneGrid   as Grid
     using DunePDELab as PDELab

     grid = Grid.YaspGrid(dim = 2, ...)
     grid.globalRefine(3)
     gv = grid.leafGridView()
     fem = PDELab.QkLocalFiniteElementMap(order = 1)
     q1space = PDELab.GridFunctionSpace(gv, fem)

   This requires us to keep track of the C++ types (incl. template
   parameters) of instatiated python objects. This information is then
   used to create the parameters for the next object.

The first goal should be to have working prototypes for these
different goals. Then we will have to discuss how to proceed.

I suggest that you try getting into DUNE and C++ using the
Dune-grid-howto. For further reading I suggest the example of the
DUNE-PDELab-Howto; this will give you a bit of an overview which parts
are actually expose to the user from a high-level application point of
view. In C++ the ugly part is that still all template parameters are
required in order to transport them to the inner level. In python we
can hide these details and unclutter the user code.

I hope this helps a little bit.

Ciao
Christian

On Thu, May 08, 2014 at 09:27:47PM +0300, Mihai Neacsu wrote:
> Hello Dune!
> 
> I’m Mihai, a CS undergraduate at Politehnica Univ. of Bucharest,
> currently in the 4th and final year of study.
> 
> There's is a project that caught my attention and I'd like to
> contribute to Dune and make it accessible from Python. I'm also happy
> it involes working my favourite programming languages: C++ and Python.
> I also got to work with Cython on other open source projects such as
> Kivy.
> 
> I'm going to start going through the source files from the Instant
> project to get better understanding on how they made it work. Any kind
> of help for getting on the right direction is this project is greatly
> appreciated (further reading, suggestions).
> 
> 
> Thank you,
> Mihai Neacsu
> 
> 
> [1] https://bitbucket.org/fenics-project/instant
> 
> _______________________________________________
> Dune-devel mailing list
> Dune-devel at dune-project.org
> http://lists.dune-project.org/mailman/listinfo/dune-devel

-- 
Prof. Dr. Christian Engwer 
Institut für Numerische und Angewandte Mathematik
Fachbereich Mathematik und Informatik der Universität Münster
Einsteinstrasse 62
48149 Münster

E-Mail	christian.engwer at uni-muenster.de
Telefon	+49 251 83-35067
FAX		+49 251 83-32729




More information about the Dune-devel mailing list