Skip to content

Conversation

@SimonHeybrock
Copy link
Member

@SimonHeybrock SimonHeybrock commented Jul 22, 2024

Fixes #3435.
Fixes scipp/essreduce#47.
I also propose to close #1846. There are most likely still some remaining issues, but the original problem description has increasingly lower utility.

Implementing this change was simple at the beginning: Consider the first few commits, and you will see that adding the dim argument was very simple (since, e.g., the underlying make_binned already had an erase argument, which was almost exactly that). Apart from a few minor branching changes in behavior (cd8de34#diff-d64f8ed6d2f8ccfec8c613e469f7f4824afd55241e6775f1f433d7724dbb80cb) the tests just passed.

Now, for the not-so-nice part: Adding handling of the so far unsupported cases (mostly https://github.com/scipp/esssans/blob/a186d7eb7c57d2b367b097596b23b9ce425c0f35/src/ess/sans/i_of_q.py#L202-L259) and performance workarounds adds one more layer to the unfortunate stack of optimizations and handling of different cases in the Python and C++ implementations of binning and histogramming. I am not at all happy with this, and I am not confident that we will not find bugs in this (maybe not returning wrong results, but at least some optimized code branch raising exceptions in cases that should work). The entire thing is very hard to see through. We do have a good number of tests, and in many cases I saw existing tests flagging issues when I adding the new features and performance tweaks. But for now at least I am out of better ideas.

  • Works in ESSsans (can remove ~50 LOC)
  • Works in ESSdiffraction
  • Works in ESSreflectometry
  • Verify that performance is unchanged, compared to workarounds in ESS* packages.

To do:

  • Update docstrings

@SimonHeybrock SimonHeybrock requested a review from jl-wynen August 2, 2024 08:13
@SimonHeybrock SimonHeybrock marked this pull request as ready for review August 13, 2024 05:11
Copy link
Member

@jl-wynen jl-wynen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also add an explanation in the user guide.

I did not manage to completely follow the new logic. But I also don't see a good way to make sure that all cases are covered by tests.

arg_dict: dict[str, int | Variable] | None = None,
/,
*,
dim: str | tuple[str, ...] | None = None,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update cpp_classes.pyi to reflect this change.

assert xyz.hist(t=4, dim='x').dims == ('y', 'z', 't')


def test_hist_by_lower_dim_coord_operates_on_slabs():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are 'slabs'? I did not see that term anywhere else.

@SimonHeybrock
Copy link
Member Author

@jl-wynen Given some mixed experiences in the past, I'd try to document this in the docstrings, not notebooks, unless you see a particular need for explaining this elsewhere?

@jl-wynen
Copy link
Member

@jl-wynen Given some mixed experiences in the past, I'd try to document this in the docstrings, not notebooks, unless you see a particular need for explaining this elsewhere?

Fine by me.

@SimonHeybrock
Copy link
Member Author

@jl-wynen Could you please have a look at the latest commit? It only updates the docstring of hist, but I thought it is more efficient if you proof read it for clarity first, before I put equivalent descriptions on the other functions.

2. Given M-D input data with an N-D coordinate, where N<M, we can specify `dim` to
sum over, e.g., the remaining M-N dimensions while histogramming. This is often
equivalent to not specifying `dim` and a call to `sum` after histogramming but
is more memory efficient.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is also needed in nanhist, bin, group.

Also, I find it hard to follow without examples. Can you add some?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please see added examples!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 For the examples.

I understand that you don't want to duplicate the explanation. But can you at least add a link to hist from the other functions?

Copy link
Member Author

@SimonHeybrock SimonHeybrock Aug 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I definitely want to duplicate the explanations, please see #3501 (comment). If you consider the overall docs of hist understandable now I will do that?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I did not see that comment. I think the docstring is good enough now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

3 participants