-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merging grids results in unexpected behavior #286
Comments
In the None case it is important to note that grid and grid2 do have the exact same bins, q2 and orders (i.e. they are identical except for the exact filling of the bins and the creation datetime) |
I'm not sure what the expected result of this operation is. I think the grid object is now clone-able in case you want to add the same thing to its self (but why not simply multiply=scale by 2 then?). Else I think Rust is complaining about ownership, i.e. the Rust
This is expected, since the merging is happening in place , i.e. |
I suppose the Python interface should convert the return value of I'm not sure why |
Line 917 in f52469c
I guess? Though I'm not sure why Lines 887 to 892 in f52469c
In any case, even though there would be a meaning to merge a grid with itself (that I'm not sure I see, since it should be a scale by 2, as @felixhekhorn said), this is unsupported in Rust itself... |
@cschwan it is actually doing it, it is raising a
All Python functions return something. If you do not return anything, they return |
It's an optimization. If we merge an empty grid with a non-empty one, we simply |
I'm not sure I understand why you might want to merge an empty grid...
... but not being familiar with the way mg5 uses PineAPPL could be the actual motivation. (though I'd often suggest avoiding having a function behave in two different ways, and instead use two different functions for that) |
I meant so say subgrid. If you merge grids in which each only one channel is filled (that's how Madgraph5_aMC@NLO does it), then you end up having a lot of empty subgrids where merging is trivial if you allow subgrids to be moved out of the other grid. |
Ok, this is a perfectly valid explanation. In principle, you might need both, the mutable and immutable version (in which you copy). In practice, there might be no use case for the immutable, so it is good as it is, and the error is perfectly fair. Maybe, the only missing bit is to document this behavior in the method docstring. |
This one is clear, and an unnecessary operation anyway. However, perhaps adding an error that just explains that merging the same grid with itself is unsupported would be user friendly.
This is also clear. In terms of enhancing user experience, I recommend either updating the docstring and documentation to clarify that the operation occurs in place, or following the convention of the pandas library by returning the merged grid as a new object. |
Issue arises in python, did not check other places.
Merging grids would from a user perspective result in the addition of the values at same bins x1,x2, etc. and result into addition at missing values. However, the merge results in errors or a None object.
Error case:
Input:
grid = pineappl.grid.Grid.read(path1)
grid.merge(grid)
Output:
Traceback (most recent call last): File "<string>", line 1, in <module> File "/data/theorie/gseevent/.conda/envs/lhapdf/lib/python3.11/site-packages/pineappl/grid.py", line 440, in merge self.raw.merge(other.raw) RuntimeError: Already mutably borrowed
None case
Input:
grid=pineappl.grid.Grid.read(path1)
grid2 = pineappl.grid.Grid.read(path2)
grid3 = grid2.merge(grid)
'Output',
grid3: None
The text was updated successfully, but these errors were encountered: