The output of python function can not pass to the snapshot

Dear Experts,

I am trying to define a python function, define a new column on my RDF using this function, and save it via snapshot but at the last stage in the snapshot the new column is not understood, The simple version of the code is below
_

test.py (916 Bytes)

The part of segmentation error I get which seems the core of the problem is

TypeError: Template method resolution failed:
none of the 3 overloaded methods succeeded. Full details:
ROOT::RDF::RResultPtr<ROOT::RDF::RInterfaceROOT::Detail::RDF::RLoopManager,void > ROOT::RDF::RInterfaceROOT::Detail::RDF::RJittedFilter,void::Snapshot(basic_string_view<char,char_traits > treename, basic_string_view<char,char_traits > filename, initializer_list columnList, const ROOT::RDF::RSnapshotOptions& options = ROOT::RDF::RSnapshotOptions()) =>
TypeError: could not convert argument 3

ROOT Version:6.28/12
Compiler:_ clang version 14.0.3

Hi,

Thanks for the post. We acknowledge your question. While the experts look at the script (@vpadulan) can you confirm you see the same with any 6.30 release?

Best,
Danilo

Hello Danilo,

I have tested the script with Root 30-v06 and the same error is happening.

Best
Mohsen

Dear @setesami ,

Thanks for reaching out to the forum and sorry for the late reply. I took a quick look at your code and noticed that you pass the third argument of the Snapshot call with curly brackets instead of square brackets. Before proceeding further with debugging, could you try passing a Python list like ["elemvaid"]? Let me know if this helps.

Cheers,
Vincenzo

Dear Vincenzo,

Thanks for your reply.
I have tested with square brackets but I get the same error.

Best
Mohsen

Dear @setesami ,

Ok thanks. I actually started reading your snippet bottom-up, and I didn’t notice the upper part of it. You are creating a Python function, then you are trying to use it while defining the body of a C++ function to the cling compiler. Apart from the fact that both the Python function and the C++ function have the same name, so at best you will incur in an infinite recursion problem, I would like to step back to the general approach you are trying. I have not seen yet such an example of simply “calling” a Python function in C++ code declared to cling. Did you do this because you followed some tutorial, or some piece of documentation? What are you trying to achieve there?

Cheers,
Vincenzo

Dear Vincenzo,

Thank you very much for your reply. So sorry for my late reply as I oddly missed your response.
The idea of writing this script is to define a function (which only needs to be written within python due to use of an external package) and then use this function to define a new column in the root dataframe and save the column via snapshot.

With the part within this declaration
ROOT.gInterpreter.Declare(“”"

“”")

I tried to declare this function which apparently is not correctly implemented as you said. I hope It is clearer now. Please let me know if it needs more clarification. Do you have any clue how it should be implemented?

Best
Mohsen

Best
Mohsen

Dear @setesami ,

Calling a pure Python function from within the RDataFrame event loop is just not possible (at the moment surely). There are a few ways that you could tackle this challenge in general. One way is to use ROOT.Numba.Declare to JIT your Python function via Numba, if that is possible. See an example at ROOT: tutorials/pyroot/pyroot004_NumbaDeclare.py File Reference.

Another way is to use the akward array to/from RDataFrame feature, so you could populate the column you need within Python then use the RDataFrame Snapshot to store to TTree. An example at How to convert to/from ROOT RDataFrame — Awkward Array 2.6.5 documentation

Cheers,
Vincenzo

Dear Vincenzo,

Thanks a lot.
The first option sounds very good but it seems it has a problem when one loops over the argument elements. I have attached a simple code with 2 functions, the first function is working but the second one which is commented now produces some errors regarding the jitter e.g

raise Exception(‘Failed to jit Python callable {} with numba.jit’.format(func))

Do you have any idea how to solve this jit problem?

Best
Mohsen

new1.py (530 Bytes)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.