Skip to content

Commit

Permalink
Make real Qgraph in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hsinfang committed Nov 27, 2024
1 parent 359373e commit 6247441
Showing 1 changed file with 39 additions and 14 deletions.
53 changes: 39 additions & 14 deletions tests/test_middleware_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
import lsst.daf.butler.tests as butler_tests
from lsst.obs.base.formatters.fitsExposure import FitsImageFormatter
from lsst.obs.base.ingest import RawFileDatasetInfo, RawFileData
import lsst.pipe.base
from lsst.pipe.base.tests.simpleQGraph import makeSimpleQGraph
import lsst.resources
import lsst.sphgeom

Expand Down Expand Up @@ -570,7 +572,7 @@ def _check_run_pipeline_fallback(self, callable, pipe_files, graphs, final_label
def test_run_pipeline_fallback_1failof2(self):
pipe_list = [os.path.join(self.data_dir, 'ApPipe.yaml'),
os.path.join(self.data_dir, 'SingleFrame.yaml')]
graph_list = [[], ["node1", "node2"]]
graph_list = [self._make_test_graph(0), self._make_test_graph(2)]
expected = "SingleFrame.yaml"

self._prepare_run_pipeline()
Expand All @@ -580,7 +582,7 @@ def test_run_pipeline_fallback_1failof2(self):
def test_run_pipeline_fallback_1failof2_inverse(self):
pipe_list = [os.path.join(self.data_dir, 'ApPipe.yaml'),
os.path.join(self.data_dir, 'SingleFrame.yaml')]
graph_list = [["node1", "node2"], []]
graph_list = [self._make_test_graph(2), self._make_test_graph(0)]
expected = "ApPipe.yaml"

self._prepare_run_pipeline()
Expand All @@ -590,7 +592,7 @@ def test_run_pipeline_fallback_1failof2_inverse(self):
def test_run_pipeline_fallback_2failof2(self):
pipe_list = [os.path.join(self.data_dir, 'ApPipe.yaml'),
os.path.join(self.data_dir, 'SingleFrame.yaml')]
graph_list = [[], []]
graph_list = [self._make_test_graph(0), self._make_test_graph(0)]
expected = ""

self._prepare_run_pipeline()
Expand All @@ -602,7 +604,7 @@ def test_run_pipeline_fallback_0failof3(self):
pipe_list = [os.path.join(self.data_dir, 'ApPipe.yaml'),
os.path.join(self.data_dir, 'SingleFrame.yaml'),
os.path.join(self.data_dir, 'ISR.yaml')]
graph_list = [["node1", "node2"], ["node3", "node4"], ["node5"]]
graph_list = [self._make_test_graph(2), self._make_test_graph(2), self._make_test_graph(0)]
expected = "ApPipe.yaml"

self._prepare_run_pipeline()
Expand All @@ -613,7 +615,7 @@ def test_run_pipeline_fallback_1failof3(self):
pipe_list = [os.path.join(self.data_dir, 'ApPipe.yaml'),
os.path.join(self.data_dir, 'SingleFrame.yaml'),
os.path.join(self.data_dir, 'ISR.yaml')]
graph_list = [[], ["node3", "node4"], ["node5"]]
graph_list = [self._make_test_graph(0), self._make_test_graph(2), self._make_test_graph(1)]
expected = "SingleFrame.yaml"

self._prepare_run_pipeline()
Expand All @@ -624,7 +626,7 @@ def test_run_pipeline_fallback_2failof3(self):
pipe_list = [os.path.join(self.data_dir, 'ApPipe.yaml'),
os.path.join(self.data_dir, 'SingleFrame.yaml'),
os.path.join(self.data_dir, 'ISR.yaml')]
graph_list = [[], [], ["node5"]]
graph_list = [self._make_test_graph(0), self._make_test_graph(0), self._make_test_graph(1)]
expected = "ISR.yaml"

self._prepare_run_pipeline()
Expand All @@ -635,7 +637,7 @@ def test_run_pipeline_fallback_2failof3_inverse(self):
pipe_list = [os.path.join(self.data_dir, 'ApPipe.yaml'),
os.path.join(self.data_dir, 'SingleFrame.yaml'),
os.path.join(self.data_dir, 'ISR.yaml')]
graph_list = [[], ["node3", "node4"], []]
graph_list = [self._make_test_graph(0), self._make_test_graph(2), self._make_test_graph(0)]
expected = "SingleFrame.yaml"

self._prepare_run_pipeline()
Expand Down Expand Up @@ -745,7 +747,7 @@ def test_run_preprocessing_full(self):
def test_run_preprocessing_fallback_1failof2(self):
pipe_list = [os.path.join(self.data_dir, 'Preprocess.yaml'),
os.path.join(self.data_dir, 'MinPrep.yaml')]
graph_list = [[], ["node1", "node2"]]
graph_list = [self._make_test_graph(0), self._make_test_graph(2)]
expected = "MinPrep.yaml"

self._prepare_run_preprocessing()
Expand All @@ -754,7 +756,7 @@ def test_run_preprocessing_fallback_1failof2(self):
def test_run_preprocessing_fallback_1failof2_inverse(self):
pipe_list = [os.path.join(self.data_dir, 'Preprocess.yaml'),
os.path.join(self.data_dir, 'MinPrep.yaml')]
graph_list = [["node1", "node2"], []]
graph_list = [self._make_test_graph(2), self._make_test_graph(0)]
expected = "Preprocess.yaml"

self._prepare_run_preprocessing()
Expand All @@ -763,7 +765,7 @@ def test_run_preprocessing_fallback_1failof2_inverse(self):
def test_run_preprocessing_fallback_2failof2(self):
pipe_list = [os.path.join(self.data_dir, 'Preprocess.yaml'),
os.path.join(self.data_dir, 'MinPrep.yaml')]
graph_list = [[], []]
graph_list = [self._make_test_graph(0), self._make_test_graph(0)]
expected = ""

self._prepare_run_preprocessing()
Expand All @@ -775,7 +777,7 @@ def test_run_preprocessing_fallback_0failof3(self):
pipe_list = [os.path.join(self.data_dir, 'Preprocess.yaml'),
os.path.join(self.data_dir, 'MinPrep.yaml'),
os.path.join(self.data_dir, 'NoPrep.yaml')]
graph_list = [["node1", "node2"], ["node3", "node4"], ["node5"]]
graph_list = [self._make_test_graph(2), self._make_test_graph(2), self._make_test_graph(1)]
expected = "Preprocess.yaml"

self._prepare_run_preprocessing()
Expand All @@ -785,7 +787,7 @@ def test_run_preprocessing_fallback_1failof3(self):
pipe_list = [os.path.join(self.data_dir, 'Preprocess.yaml'),
os.path.join(self.data_dir, 'MinPrep.yaml'),
os.path.join(self.data_dir, 'NoPrep.yaml')]
graph_list = [[], ["node3", "node4"], ["node5"]]
graph_list = [self._make_test_graph(0), self._make_test_graph(2), self._make_test_graph(1)]
expected = "MinPrep.yaml"

self._prepare_run_preprocessing()
Expand All @@ -795,7 +797,7 @@ def test_run_preprocessing_fallback_2failof3(self):
pipe_list = [os.path.join(self.data_dir, 'Preprocess.yaml'),
os.path.join(self.data_dir, 'MinPrep.yaml'),
os.path.join(self.data_dir, 'NoPrep.yaml')]
graph_list = [[], [], ["node5"]]
graph_list = [self._make_test_graph(0), self._make_test_graph(0), self._make_test_graph(1)]
expected = "NoPrep.yaml"

self._prepare_run_preprocessing()
Expand All @@ -805,7 +807,7 @@ def test_run_preprocessing_fallback_2failof3_inverse(self):
pipe_list = [os.path.join(self.data_dir, 'Preprocess.yaml'),
os.path.join(self.data_dir, 'MinPrep.yaml'),
os.path.join(self.data_dir, 'NoPrep.yaml')]
graph_list = [[], ["node3", "node4"], []]
graph_list = [self._make_test_graph(0), self._make_test_graph(2), self._make_test_graph(0)]
expected = "MinPrep.yaml"

self._prepare_run_preprocessing()
Expand Down Expand Up @@ -912,6 +914,29 @@ def _make_expanded_ref(registry, dtype, data_id, run):
return lsst.daf.butler.DatasetRef(registry.getDatasetType(dtype), data_id, run=run) \
.expanded(registry.expandDataId(data_id))

@staticmethod
def _make_test_graph(n_quanta):
"""Make a `QuantumGraph` for tests.
Parameters
----------
n_quanta : `int`
Number of quanta in a graph.
Returns
-------
qgraph : `~lsst.pipe.base.QuantumGraph`
Quantum graph instance.
"""
with tempfile.TemporaryDirectory() as tmpdir:
if n_quanta == 0:
butler = Butler(Butler.makeRepo(tmpdir))
return lsst.pipe.base.QuantumGraph({}, universe=butler.dimensions)
elif n_quanta < 0:
raise RuntimeError("Invalid input")
else:
return makeSimpleQGraph(n_quanta, root=tmpdir)[1]

def test_get_sasquatch_dispatcher(self):
self.assertIsNone(_get_sasquatch_dispatcher())
with unittest.mock.patch.dict(os.environ,
Expand Down

0 comments on commit 6247441

Please sign in to comment.