Skip to content

DM-50244: Make quantum graph generation more permissive about missing init-outputs in --skip-existing-in collections #487

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions doc/changes/DM-50244.misc.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Make quantum graph generation more permissive about missing init-outputs in `--skip-existing-in` collections.
58 changes: 49 additions & 9 deletions python/lsst/pipe/base/quantum_graph_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,8 +346,16 @@
# Loop over tasks. The pipeline graph must be topologically
# sorted, so a quantum is only processed after any quantum that
# provides its inputs has been processed.
doomed_tasks: list[str] = []
for task_node in self._pipeline_graph.tasks.values():
self._resolve_task_quanta(task_node, full_skeleton)
doomed_tasks.extend(self._resolve_task_quanta(task_node, full_skeleton))
for task_label in doomed_tasks:
if full_skeleton.has_task(task_label):
raise InitInputMissingError(

Check warning on line 354 in python/lsst/pipe/base/quantum_graph_builder.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/pipe/base/quantum_graph_builder.py#L354

Added line #L354 was not covered by tests
f"Task {task_label} requires an init-output dataset that was not present "
f"in {self.skip_existing_in} and cannot be produced by this graph. "
"(see warnings logged earlier for details)."
)
# Add global init-outputs to the skeleton.
for dataset_type in self._global_init_output_types.values():
dataset_key = full_skeleton.add_dataset_node(
Expand Down Expand Up @@ -427,7 +435,7 @@

@final
@timeMethod
def _resolve_task_quanta(self, task_node: TaskNode, skeleton: QuantumGraphSkeleton) -> None:
def _resolve_task_quanta(self, task_node: TaskNode, skeleton: QuantumGraphSkeleton) -> list[str]:
"""Process the quanta for one task in a skeleton graph to skip those
that have already completed and adjust those that request it.

Expand All @@ -438,6 +446,14 @@
skeleton : `quantum_graph_skeleton.QuantumGraphSkeleton`
Preliminary quantum graph, to be modified in-place.

Returns
-------
doomed_tasks : `list` [ `str` ]
Labels of tasks that consume an init-output that will not be
produced by this quantum graph, because the producing task is being
dropped due to skip-existing-in and the output was not present in
the skip-existing-in collection.

Notes
-----
This method modifies ``skeleton`` in-place in several ways:
Expand Down Expand Up @@ -507,6 +523,7 @@
# raise if one of the check conditions is not met, which is the
# intended behavior.
helper = AdjustQuantumHelper(inputs=adjusted_inputs, outputs=adjusted_outputs)
quantum_data_id = skeleton[quantum_key]["data_id"]
try:
helper.adjust_in_place(task_node.get_connections(), task_node.label, quantum_data_id)
except NoWorkFound as err:
Expand Down Expand Up @@ -561,7 +578,7 @@
for no_work_quantum in no_work_quanta:
skeleton.remove_quantum_node(no_work_quantum, remove_outputs=True)
remaining_quanta = skeleton.get_quanta(task_node.label)
self._resolve_task_init(task_node, skeleton, bool(skipped_quanta))
doomed_tasks = self._resolve_task_init(task_node, skeleton, bool(skipped_quanta))
message_terms = []
if no_work_quanta:
message_terms.append(f"{len(no_work_quanta)} had no work to do")
Expand All @@ -582,6 +599,7 @@
"Dropping task %s because no quanta remain%s.", task_node.label, message_parenthetical
)
skeleton.remove_task(task_node.label)
return doomed_tasks

def _skip_quantum_if_metadata_exists(
self, task_node: TaskNode, quantum_key: QuantumKey, skeleton: QuantumGraphSkeleton
Expand Down Expand Up @@ -837,7 +855,7 @@
@final
def _resolve_task_init(
self, task_node: TaskNode, skeleton: QuantumGraphSkeleton, has_skipped_quanta: bool
) -> None:
) -> list[str]:
"""Add init-input and init-output dataset nodes and edges for a task to
the skeleton.

Expand All @@ -850,9 +868,18 @@
has_skipped_quanta : `bool`
Whether any of this task's quanta were skipped because they had
already succeeded.

Returns
-------
doomed_tasks : `list` [ `str` ]
Labels of tasks that consume an init-output that will not be
produced by this quantum graph, because the producing task is being
dropped due to skip-existing-in and the output was not present in
the skip-existing-in collection.
"""
quanta = skeleton.get_quanta(task_node.label)
task_init_key = TaskInitKey(task_node.label)
doomed_tasks: list[str] = []
if quanta:
adapted_inputs: NamedKeyDict[DatasetType, DatasetRef] = NamedKeyDict()
# Process init-inputs.
Expand Down Expand Up @@ -910,11 +937,23 @@
write_edge.parent_dataset_type_name, self.empty_data_id
)
if (ref := self.empty_dimensions_datasets.outputs_for_skip.get(dataset_key)) is None:
raise InitInputMissingError(
f"Init-output dataset {write_edge.parent_dataset_type_name!r} of skipped task "
f"{task_node.label!r} not found in skip-existing-in collection(s) "
f"{self.skip_existing_in}."
) from None
# init-outputs really shouldn't be missing, but because
# they might in important contexts (rapid analysis) we want
# to try really hard to just warn and proceed without them.
# First we see if any tasks are going to need those as
# inputs, and later once we've dropped all the task we're
# going to, we'll see if any remain that can't proceed.
consuming_tasks = self._pipeline_graph.consumers_of(write_edge.parent_dataset_type_name)
doomed_tasks.extend([n.label for n in consuming_tasks])
self.log.warning(

Check warning on line 948 in python/lsst/pipe/base/quantum_graph_builder.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/pipe/base/quantum_graph_builder.py#L946-L948

Added lines #L946 - L948 were not covered by tests
"Init-output dataset %r of skipped task %r not found in skip-existing-in "
"collection(s) %s. Proceeding unless this is needed as an input by a retained task.",
write_edge.parent_dataset_type_name,
task_node.label,
self.skip_existing_in,
)
skeleton.remove_dataset_nodes([dataset_key])
continue

Check warning on line 956 in python/lsst/pipe/base/quantum_graph_builder.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/pipe/base/quantum_graph_builder.py#L955-L956

Added lines #L955 - L956 were not covered by tests
skeleton.set_dataset_ref(ref, dataset_key)
# If this dataset was "in the way" (i.e. already in the output
# run), it isn't anymore.
Expand All @@ -924,6 +963,7 @@
# dooms all downstream quanta to the same fate, so we don't bother
# doing anything with the task's init-outputs, since nothing is
# going to consume them.
return doomed_tasks

@final
@timeMethod
Expand Down
Loading