Skip to content
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

Try sharing common parts of workflow compute to make tests run faster #182

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
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
30 changes: 27 additions & 3 deletions tests/loki/iofq_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from ess import loki, sans
from ess.sans.conversions import ElasticCoordTransformGraph
from ess.sans.types import (
BackgroundRun,
BackgroundSubtractedIofQ,
BackgroundSubtractedIofQxy,
BeamCenter,
Expand All @@ -21,15 +22,20 @@
CorrectForGravity,
Denominator,
DimsToKeep,
Incident,
IofQ,
IofQxy,
MaskedData,
MaskedSolidAngle,
Numerator,
QBins,
QxBins,
QyBins,
ReturnEvents,
SampleRun,
TofMonitor,
Transmission,
TransmissionRun,
UncertaintyBroadcastMode,
WavelengthBands,
WavelengthBins,
Expand Down Expand Up @@ -85,6 +91,23 @@ def test_pipeline_can_compute_IofQ(uncertainties, qxy: bool):
assert_identical(result, reference)


@pytest.fixture(scope='module')
def workflow_with_data():
pipeline = make_workflow()
pipeline[BeamCenter] = sans.beam_center_from_center_of_mass(pipeline)
for run in (SampleRun, BackgroundRun):
keys = (
MaskedData[run],
MaskedSolidAngle[run],
TofMonitor[run, Incident],
TofMonitor[TransmissionRun[run], Incident],
TofMonitor[TransmissionRun[run], Transmission],
)
for key, value in pipeline.compute(keys).items():
pipeline[key] = value
return pipeline


@pytest.mark.parametrize(
'uncertainties',
[UncertaintyBroadcastMode.drop, UncertaintyBroadcastMode.upper_bound],
Expand All @@ -98,10 +121,11 @@ def test_pipeline_can_compute_IofQ(uncertainties, qxy: bool):
BackgroundSubtractedIofQxy,
],
)
def test_pipeline_can_compute_IofQ_in_event_mode(uncertainties, target):
pipeline = make_workflow()
def test_pipeline_can_compute_IofQ_in_event_mode(
Copy link
Member

Choose a reason for hiding this comment

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

I think the approach is fine. The test looks almost identical to before, it just has a fixture which has some pre-computed stuff in it. It's not making some tests depend on others or anything like that.

How does it change the overall time it takes to run all tests?

Copy link
Member Author

Choose a reason for hiding this comment

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

How does it change the overall time it takes to run all tests?

You would have to do something similar for quite a few more tests. But the worse offender is currently the beam-center finder, but I don't feel it is worth playing with that.

uncertainties, target, workflow_with_data
):
pipeline = workflow_with_data.copy()
pipeline[UncertaintyBroadcastMode] = uncertainties
pipeline[BeamCenter] = sans.beam_center_from_center_of_mass(pipeline)
reference = pipeline.compute(target)
pipeline[ReturnEvents] = True
result = pipeline.compute(target)
Expand Down