Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion refl1d/probe/probe.py
Original file line number Diff line number Diff line change
Expand Up @@ -1636,7 +1636,7 @@ def oversample(self, n=20, seed=1):
oversample.__doc__ = Probe.oversample.__doc__

def _calculate_union(self):
theta_offsets = [x.theta_offset.value for x in self.xs if x is not None]
theta_offsets = [x.theta_offset.value for x in self.xs if x is not None and hasattr(x, "theta_offset")]
Copy link
Member

Choose a reason for hiding this comment

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

The measurement union function uses both Q (hence the dependence on theta_offset) and also dQ, therefore sample_broadening should also be part of the key.

Rather than assuming these properties exist and that they are the only properties that affect the measurement union, we could be delegating to the underlying class, with something like a xs._QdQ_key() method. This will matter more when we have full support for ProbeSet as polarized cross sections.

Copy link
Member Author

Choose a reason for hiding this comment

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

That's a good catch on the sample_broadening dependency... this optimization (_calculate_union) is pretty useful in reducing calculation time but it adds a lot of complexity!

union_cache_key = (theta_offsets, self.oversampling, self.oversampling_seed, tuple(self.oversampled_regions))
if self._union_cache_key == union_cache_key:
# no change in offsets or oversampling: use cached values of measurement union
Expand Down Expand Up @@ -1929,6 +1929,7 @@ def __init__(
self.oversampling_seed = oversampling_seed
self.oversampled_regions = oversampled_regions if oversampled_regions is not None else []
# this sets self.Q, self.dQ, self._calc_Q:
self._union_cache_key = None
self._calculate_union()

@property
Expand Down
Loading