QuantumGraphSkeleton¶
- class lsst.pipe.base.quantum_graph_skeleton.QuantumGraphSkeleton(task_labels: Iterable[str])¶
Bases:
objectAn under-construction quantum graph.
QuantumGraphSkeleton is intended for use inside
QuantumGraphBuilderand its subclasses.- Parameters:
Notes
QuantumGraphSkeleton models a bipartite version of the quantum graph, in which both quanta and datasets are represented as nodes and each type of node only has edges to the other type.
Square-bracket (
getitem) indexing returns a mutable mapping of a node’s flexible attributes.The details of the
QuantumGraphSkeletonAPI (e.g. which operations operate on multiple nodes vs. a single node) are set by what’s actually needed by current quantum graph generation algorithms. New variants can be added as needed, but adding all operations that might be useful for some future algorithm seems premature.Attributes Summary
The set of dataset nodes that are not associated with any task.
Test whether this graph has any quanta.
The total number of edges.
The total number of nodes of all types.
Methods Summary
add_dataset_node(parent_dataset_type_name, ...)Add a new node representing a dataset.
add_input_edge(task_key, dataset_key[, ...])Add an edge connecting a dataset to a quantum that consumes it.
add_input_edges(task_key, dataset_keys)Add edges connecting datasets to a quantum that consumes them.
add_output_edge(task_key, dataset_key)Add an edge connecting a dataset to the quantum that produces it.
add_prerequisite_node(ref, **attrs)Add a new node representing a prerequisite input dataset.
add_quantum_node(task_label, data_id, **attrs)Add a new node representing a quantum.
attach_dimension_records(butler, dimensions)Attach dimension records to the data IDs in the skeleton.
Drop any
DatasetRefassociated with this node in the output RUN collection.Find overall input datasets.
get_data_id(key)Return the full data ID for a quantum or dataset, if available.
get_dataset_ref(key)Return the
DatasetRefassociated with the given node.Return the dimension records attached to data IDs.
get_output_for_skip(key)Return the
DatasetRefassociated with the given node in a collection where it could lead to a quantum being skipped.Return the
DatasetRefassociated with the given node in the output RUN collection.get_quanta(task_label)Return the quanta for the given task label.
get_task_init_node(task_label)Return the graph node that represents a task's initialization.
has_task(task_label)Test whether the given task is in this skeleton.
Iterate over all quanta from any task, in topological (but otherwise unspecified) order.
iter_inputs_of(quantum_key)Iterate over the datasets consumed by the given quantum.
iter_outputs_of(quantum_key)Iterate over the datasets produced by the given quantum.
remove_dataset_nodes(keys)Remove nodes representing datasets.
remove_input_edges(task_key, dataset_keys)Remove edges connecting datasets to a quantum that consumes them.
Remove any dataset nodes that do not have any edges.
remove_output_edge(dataset_key)Remove the edge connecting a dataset to the quantum that produces it.
remove_quantum_node(key, remove_outputs)Remove a node representing a quantum.
remove_task(task_label)Fully remove a task from the skeleton.
set_data_id(key, data_id)Set the data ID associated with a node.
set_dataset_ref(ref[, key])Associate a dataset node with a
DatasetRefinstance.set_output_for_skip(ref)Associate a dataset node with a
DatasetRefthat represents an existing output in a collection where such outputs can cause a quantum to be skipped.Associate a dataset node with a
DatasetRefthat represents an existing output in the output RUN collectoin.update(other)Copy all nodes from
othertoself.Attributes Documentation
- global_init_outputs¶
The set of dataset nodes that are not associated with any task.
- has_any_quanta¶
Test whether this graph has any quanta.
- n_edges¶
The total number of edges.
- n_nodes¶
The total number of nodes of all types.
Methods Documentation
- add_dataset_node(parent_dataset_type_name: str, data_id: DataCoordinate, is_global_init_output: bool = False, **attrs: Any) DatasetKey¶
Add a new node representing a dataset.
- Parameters:
- parent_dataset_type_name
str Name of the parent dataset type.
- data_id
DataCoordinate The dataset data ID.
- is_global_init_output
bool, optional Whether this dataset is a global init output.
- **attrs
Any Additional attributes for the node.
- parent_dataset_type_name
- add_input_edge(task_key: QuantumKey | TaskInitKey, dataset_key: DatasetKey | PrerequisiteDatasetKey, ignore_unrecognized_quanta: bool = False) bool¶
Add an edge connecting a dataset to a quantum that consumes it.
- Parameters:
- task_key
QuantumKeyorTaskInitKey Identifier for the quantum node.
- dataset_key
DatasetKeyorPrerequisiteKey Identifier for the dataset node.
- ignore_unrecognized_quanta
bool, optional If
False, do nothing if the quantum node is not already present. IfTrue, the quantum node is assumed to be present.
- task_key
- Returns:
Notes
Dataset nodes that are not already present will be created.
- add_input_edges(task_key: QuantumKey | TaskInitKey, dataset_keys: Iterable[DatasetKey | PrerequisiteDatasetKey]) None¶
Add edges connecting datasets to a quantum that consumes them.
- Parameters:
- task_key
QuantumKeyorTaskInitKey Quantum to connect.
- dataset_keys
IterableofDatasetKeyorPrequisiteDatasetKey Datasets to join to the quantum.
- task_key
Notes
This must only be called if the task node has already been added. Use
add_input_edgeif this cannot be assumed.Dataset nodes that are not already present will be created.
- add_output_edge(task_key: QuantumKey | TaskInitKey, dataset_key: DatasetKey) None¶
Add an edge connecting a dataset to the quantum that produces it.
- Parameters:
- task_key
QuantumKeyorTaskInitKey Identifier for the quantum node. Must identify a node already present in the graph.
- dataset_key
DatasetKey Identifier for the dataset node. Must identify a node already present in the graph.
- task_key
- add_prerequisite_node(ref: DatasetRef, **attrs: Any) PrerequisiteDatasetKey¶
Add a new node representing a prerequisite input dataset.
- Parameters:
- ref
DatasetRef The dataset ref of the prerequisite.
- **attrs
Any Additional attributes for the node.
- ref
Notes
This automatically sets the ‘existing_input’ ref attribute (see
set_existing_input_ref), since prerequisites are always overall inputs.
- add_quantum_node(task_label: str, data_id: DataCoordinate, **attrs: Any) QuantumKey¶
Add a new node representing a quantum.
- Parameters:
- task_label
str Name of task.
- data_id
DataCoordinate The data ID of the quantum.
- **attrs
Any Additional attributes.
- task_label
- attach_dimension_records(butler: Butler, dimensions: DimensionGroup, dimension_records: Iterable[DimensionRecordSet] = ()) None¶
Attach dimension records to the data IDs in the skeleton.
This both attaches records to data IDs in the skeleton and aggregates any existing records on data IDS, so
get_dimension_datareturns all dimension records used in the skeleton. It can be called multiple times.- Parameters:
- butler
lsst.daf.butler.Butler Butler to use to query for missing dimension records.
- dimensions
lsst.daf.butler.DimensionGroup Superset of all of the dimensions of all data IDs.
- dimension_records
Iterable[lsst.daf.butler.DimensionRecordSet], optional Iterable of sets of dimension records to attach.
- butler
- discard_output_in_the_way(key: DatasetKey) None¶
Drop any
DatasetRefassociated with this node in the output RUN collection.Does nothing if there is no such
DatasetRef.- Parameters:
- key
DatasetKey Identifier for the graph node.
- key
- extract_overall_inputs() dict[lsst.pipe.base.quantum_graph_skeleton.DatasetKey | lsst.pipe.base.quantum_graph_skeleton.PrerequisiteDatasetKey, lsst.daf.butler._dataset_ref.DatasetRef]¶
Find overall input datasets.
- Returns:
- datasets
dict[DatasetKeyorPrerequisiteDatasetKey,DatasetRef] Overall-input datasets, including prerequisites and init-inputs.
- datasets
- get_data_id(key: QuantumKey | TaskInitKey | DatasetKey | PrerequisiteDatasetKey) DataCoordinate¶
Return the full data ID for a quantum or dataset, if available.
- Parameters:
- key
Key Identifier for the graph node.
- key
- Returns:
- data_id
DataCoordinate Expanded data ID for the node, if one is available.
- data_id
- Raises:
- KeyError
Raised if this node does not have an expanded data ID.
- get_dataset_ref(key: DatasetKey | PrerequisiteDatasetKey) DatasetRef | None¶
Return the
DatasetRefassociated with the given node.This does not return “output for skip” and “output in the way” datasets.
- Parameters:
- key
DatasetKeyorPrerequisiteDatasetKey Identifier for the graph node.
- key
- Returns:
- ref
DatasetReforNone Dataset reference associated with the node.
- ref
- get_dimension_data() list[lsst.daf.butler.dimensions._record_set.DimensionRecordSet]¶
Return the dimension records attached to data IDs.
- get_output_for_skip(key: DatasetKey) DatasetRef | None¶
Return the
DatasetRefassociated with the given node in a collection where it could lead to a quantum being skipped.- Parameters:
- key
DatasetKey Identifier for the graph node.
- key
- Returns:
- ref
DatasetReforNone Dataset reference associated with the node.
- ref
- get_output_in_the_way(key: DatasetKey) DatasetRef | None¶
Return the
DatasetRefassociated with the given node in the output RUN collection.- Parameters:
- key
DatasetKey Identifier for the graph node.
- key
- Returns:
- ref
DatasetReforNone Dataset reference associated with the node.
- ref
- get_quanta(task_label: str) Set[QuantumKey]¶
Return the quanta for the given task label.
- Parameters:
- task_label
str Label for the task.
- task_label
- Returns:
- quanta
Set[QuantumKey] A set-like object with the identifiers of all quanta for the given task. The skeleton object’s set of quanta must not be modified while iterating over this container; make a copy if mutation during iteration is necessary.
- quanta
- get_task_init_node(task_label: str) TaskInitKey¶
Return the graph node that represents a task’s initialization.
- Parameters:
- task_label
str The task label to use.
- task_label
- Returns:
- node
TaskInitKey The graph node representing this task’s initialization.
- node
- has_task(task_label: str) bool¶
Test whether the given task is in this skeleton.
Tasks are only added to the skeleton at initialization, but may be removed by
remove_taskif they end up having no quanta.
- iter_all_quanta() Iterator[QuantumKey]¶
Iterate over all quanta from any task, in topological (but otherwise unspecified) order.
- iter_inputs_of(quantum_key: QuantumKey | TaskInitKey) Iterator[DatasetKey | PrerequisiteDatasetKey]¶
Iterate over the datasets consumed by the given quantum.
- Parameters:
- quantum_key
QuantumKeyorTaskInitKey Quantum to iterate over.
- quantum_key
- Returns:
- datasets
IteratorofDatasetKeyorPrequisiteDatasetKey Datasets consumed by the given quanta.
- datasets
- iter_outputs_of(quantum_key: QuantumKey | TaskInitKey) Iterator[DatasetKey]¶
Iterate over the datasets produced by the given quantum.
- Parameters:
- quantum_key
QuantumKeyorTaskInitKey Quantum to iterate over.
- quantum_key
- Returns:
- datasets
IteratorofDatasetKey Datasets produced by the given quanta.
- datasets
- remove_dataset_nodes(keys: Iterable[DatasetKey | PrerequisiteDatasetKey]) None¶
Remove nodes representing datasets.
- Parameters:
- keys
IterableofDatasetKeyorPrerequisiteDatasetKey Nodes to remove.
- keys
- remove_input_edges(task_key: QuantumKey | TaskInitKey, dataset_keys: Iterable[DatasetKey | PrerequisiteDatasetKey]) None¶
Remove edges connecting datasets to a quantum that consumes them.
- Parameters:
- task_key
QuantumKeyorTaskInitKey Quantum to disconnect.
- dataset_keys
IterableofDatasetKeyorPrequisiteDatasetKey Datasets to remove from the quantum.
- task_key
- remove_output_edge(dataset_key: DatasetKey) None¶
Remove the edge connecting a dataset to the quantum that produces it.
- Parameters:
- dataset_key
DatasetKey Identifier for the dataset node. Must identify a node already present in the graph.
- dataset_key
- remove_quantum_node(key: QuantumKey, remove_outputs: bool) None¶
Remove a node representing a quantum.
- Parameters:
- key
QuantumKey Identifier for the node.
- remove_outputs
bool If
True, also remove all dataset nodes produced by this quantum. IfFalse, any such dataset nodes will become overall inputs.
- key
- remove_task(task_label: str) None¶
Fully remove a task from the skeleton.
All init-output datasets and quanta for the task must already have been removed.
- Parameters:
- task_label
str Name of task to remove.
- task_label
- set_data_id(key: QuantumKey | TaskInitKey | DatasetKey | PrerequisiteDatasetKey, data_id: DataCoordinate) None¶
Set the data ID associated with a node.
This updates the data ID in any
DatasetRefobjects associated with the node viaset_ref,set_output_for_skip, orset_output_in_the_wayas well, assuming it is an expanded version of the original data ID.- Parameters:
- key
Key Identifier for the graph node.
- data_id
DataCoordinate Data ID for the node.
- key
- set_dataset_ref(ref: DatasetRef, key: DatasetKey | PrerequisiteDatasetKey | None = None) None¶
Associate a dataset node with a
DatasetRefinstance.- Parameters:
- ref
DatasetRef DatasetRefto associate with the node.- key
DatasetKeyorPrerequisiteDatasetKey, optional Identifier for the graph node. If not provided, a
DatasetKeyis constructed from the dataset type name and data ID ofref.
- ref
- set_output_for_skip(ref: DatasetRef) None¶
Associate a dataset node with a
DatasetRefthat represents an existing output in a collection where such outputs can cause a quantum to be skipped.- Parameters:
- ref
DatasetRef DatasetRefto associate with the node.
- ref
- set_output_in_the_way(ref: DatasetRef) None¶
Associate a dataset node with a
DatasetRefthat represents an existing output in the output RUN collectoin.- Parameters:
- ref
DatasetRef DatasetRefto associate with the node.
- ref
- update(other: QuantumGraphSkeleton) None¶
Copy all nodes from
othertoself.- Parameters:
- other
QuantumGraphSkeleton Source of nodes. The tasks in
othermust be a subset of the tasks inself(this method is expected to be used to populate a skeleton for a full from independent-subgraph skeletons).
- other