ClusteredQuantumGraph

class lsst.ctrl.bps.ClusteredQuantumGraph(incoming_graph_data=None, **attr)

Bases: networkx.classes.digraph.DiGraph

Graph where the data for a node is a subgraph of the full QuantumGraph represented by a list of NodeIds.

Using lsst.pipe.base.NodeId instead of integer because the QuantumGraph API requires them. Chose skipping the repeated creation of objects to use API over totally minimized memory usage.

Methods Summary

add_cluster(name, node_ids[, label, tags]) Add a cluster of quanta as a node in the graph.
add_node(node_for_adding, **attr) Override add_node function to ensure that nodes are limited to QuantumGraphs
add_nodes_from(nodes_for_adding, **attr) Add multiple nodes.

Methods Documentation

add_cluster(name, node_ids, label=None, tags=None)

Add a cluster of quanta as a node in the graph.

Parameters:
name : str

Node name which must be unique in the graph.

node_ids : list of NodeId

NodeIds for QuantumGraph subset.

label : str, optional

Label for the cluster. Can be used in grouping clusters.

tags : dict [str, Any], optional

Arbitrary tags for the cluster.

add_node(node_for_adding, **attr)

Override add_node function to ensure that nodes are limited to QuantumGraphs

Parameters:
node_for_adding : str or list of NodeId

Name of cluster or cluster data (list of NodeIds).

attr : keyword arguments, optional

Attributes to be saved with node in graph.

add_nodes_from(nodes_for_adding, **attr)

Add multiple nodes.

Parameters:
nodes_for_adding : iterable container

A container of nodes (list, dict, set, etc.). OR A container of (node, attribute dict) tuples. Node attributes are updated using the attribute dict.

attr : keyword arguments, optional (default= no attributes)

Update attributes for all nodes in nodes. Node attributes specified in nodes as a tuple take precedence over attributes specified via keyword arguments.

See also

add_node

Examples

>>> G = nx.Graph()  # or DiGraph, MultiGraph, MultiDiGraph, etc
>>> G.add_nodes_from("Hello")
>>> K3 = nx.Graph([(0, 1), (1, 2), (2, 0)])
>>> G.add_nodes_from(K3)
>>> sorted(G.nodes(), key=str)
[0, 1, 2, 'H', 'e', 'l', 'o']

Use keywords to update specific node attributes for every node.

>>> G.add_nodes_from([1, 2], size=10)
>>> G.add_nodes_from([3, 4], weight=0.4)

Use (node, attrdict) tuples to update attributes for specific nodes.

>>> G.add_nodes_from([(1, dict(size=11)), (2, {"color": "blue"})])
>>> G.nodes[1]["size"]
11
>>> H = nx.Graph()
>>> H.add_nodes_from(G.nodes(data=True))
>>> H.nodes[1]["size"]
11