A little suggestion about global variables


I want build a model using graph’s global feature. But DGL only has node-update and edge-update functions. If you can contain global update function, that’s will be helpfull.



Could you please elaborate on the context where you want to only update the graph features? In most graph neural networks I’ve seen, the graph feature is a function of the node features and edge features. To update the graph feature is first to perform node/edge feature update and then to apply a function to them (what we call the “readout” of graphs). If you really only want to update graph features independent of the particular graph structure, I think you can simply treat it as some input to a model without using DGL. Hope this helps.


Thanks for the question. One of the design philosophy of DGL is to take control of only the necessary. A global state is not tied to nodes or edges, so you could maintain it outside of DGL. Some demo codes:

g = DGLGraph(...)  # some graph with node features
glb_state = ...
def mfunc(edges):
  return {'m' : edges.src['h'] * glb_state}
for epoch in range(MAX_EPOCH):
  g.update_all(mfunc, ...)
  glb_state = SomeGlobalUpdateFunc(h)
  h = g.ndata['h']

See that glb_state is maintained as function closure outside of DGLGraph.