NNPDF / pineappl

PineAPPL is not an extension of APPLgrid
https://nnpdf.github.io/pineappl/
GNU General Public License v3.0
13 stars 3 forks source link

Python bindings with PyO3 #51

Closed alecandido closed 3 years ago

alecandido commented 3 years ago

Hi @cschwan, I was reading about PyO3, and after a while I started thinking that it may be not so hard to provide bindings for pineappl using it.

I don't know how much you care, but I decided to make a try, just in my spare time. The goal it's to port a minimal subset of things, just a proof of concept, to expand after to the full one.

It should not take so much, but of course it's not my main business, so it will take its time. Do you mind if I try?

I also thought it was a good way to familiarize a little more with pineappl, since soon it will be useful (both because of yadism, but also because I am going to work on pineko too, and I know you are the expert on pineappl, but it won't hurt to know something more).

If you agree maybe you can suggest me which one could be "a minimal set".

cschwan commented 3 years ago

@AleCandido We need to replace the use of LagrangeSubgridV2 with another type. I can do the replacement, but I'd like to have an integration test for pineappl_py. Could you please add one (add a .yaml file generated by yadism, and the test should just check that the generated grid gives the right predictions)?

felixhekhorn commented 3 years ago

@cschwan Huhu, is this what you need? https://github.com/N3PDF/yadism/commit/967d3ec9e443ba917b26635fe2c2222445815eaf please tell us if you can run it!

cschwan commented 3 years ago

@felixhekhorn How do I install yadmark?

cschwan commented 3 years ago

Hi @felixhekhorn and @AleCandido , the FKTable class is definitely a good idea, and for the time being it's all we need in this direction. Before we merge this branch into master, however, I'd like to make the FKTable class a Rust struct and then thinly wrap it like any other class - in that regard it stands out from the rest now.

In general, we should come up with a list of rules that guide the design of the Python interface. From what we've done already, I'd say they are:

Before we merge, we should also make sure that

Finally, I propose to rename pineappl_py to pyneappl, what do you think?

alecandido commented 3 years ago

Starting from the top:

About the guidelines: I believe that's enough, especially because we are aiming for something minimal. Your crate is organized by structs, then in python is easy to mirror by classes. Spare functions would just turn into functions, and even modules are available on both sides (even nested), so it is only required to mirror. I would remain a little bit flexible on the amount of things that can be done in python, since pyo3 is not always complete or very easy to use sometimes applying some workaround through a little bit more code on the python side is fine as well. Nevertheless: less is more.

About the merge:

pyneappl makes perfect sense, I would say it's quite pythonic. But if we are going to replace @scarrazza ones then I wonder, why not pineappl itself? (pyneappl would be more stylish the same, but maybe keeping pineappl is a more direct choice)

cschwan commented 3 years ago

@AleCandido @felixhekhorn The last commit adds the convolute_eko2 method, which is also used in the Python bindings already. If you want to disable the new method simply change eko2 to eko there. The whole thing compiles, but unfortunately the DIS example from Pineko doesn't work yet - the numbers are simply wrong. I'm not sure if I can debug it today, but if you want to play with it in the meantime, please go ahead!

In any case, I implemented the following:

cschwan commented 3 years ago

An update of my last comment:

https://github.com/N3PDF/pineappl/blob/4b9129fd7d58f4c8e9f6188dd7a56abccbf7b3f0/pineappl/src/grid.rs#L1414-L1444

cschwan commented 3 years ago

Before merging into master we have to fix a few things (ordered by importance):

felixhekhorn commented 3 years ago

@cschwan

change create c'tors in Python?

you were thinking of https://github.com/N3PDF/pineappl/blob/fe5b83989144c4360db156daf7a12134d5ac86c4/pineappl_py/pineappl/grid.py#L23, right? then we can't because we need the c'tor with the raw wrapper object here: https://github.com/N3PDF/pineappl/blob/fe5b83989144c4360db156daf7a12134d5ac86c4/pineappl_py/pineappl/grid.py#L52

felixhekhorn commented 3 years ago

do we need PyBinRemapper?

it is still used here: https://github.com/N3PDF/yadism/blob/be995caf3a7f76dafd06336ba83fc570bc31f0a3/src/yadism/output.py#L236 so I guess the answer is yes ... or is there some other way?

felixhekhorn commented 3 years ago

add tests add more documentation

actually, where? Rust@pineappl, Rust@pineappl_py, Python@pineappl_py ?

felixhekhorn commented 3 years ago

check README

I made a proposal in https://github.com/N3PDF/pineappl/pull/51/commits/e8e18091a72f672212f41ea67559a3b2457156ee - please take a look

cschwan commented 3 years ago

add tests add more documentation

actually, where? Rust@pineappl, Rust@pineappl_py, Python@pineappl_py ?

What I'd like to see is tests of the Python interface, so tests written in Python!