Hello everyone,
Firstly I will try to briefly explain what I am trying to do. In my application I am creating a graph of around 300 nodes and 2000 edges (that we will call the base graph) and then it is merged with a different graph (that we will call the variable graph) and altogether is imputed into the GNN layers.
As the base graph is always the same (same nodes, features and edges) I want to create it just once and then do a copy that is merged with the variable graph in each case. Aiming to speed up the process since the base graph doesn’t have to be created in each instance.
This is what I’ve tried so far:
class VariableGraph(DGLGraph):
@staticmethod
def generate_base_graph():
[...]
base_graph = dgl.DGLGraph()
base_graph.add_nodes(...)
base_graph.add_edges(...)
base_graph.node['h'] = ...
[...]
return base_graph
BASEGRAPGH= generate_class_variable.__func__()
def __init__(self, data, alt, mode='train', debug=False):
super(VariableGraph, self).__init__(copy.deepcopy(self.BASEGRAPGH))
[...]
# logic to merge base graph with variable graph
[...]
So I create the base graph as a class variable and pass it in the super method of the VariableGraph class that is inhirited from DGLGraph class. I thought that in this way the base graph is only created once and a copy of it is pased each time the VariableGraph is instantiated. However, I get the following error:
File "/home/daniel/.local/lib/python3.8/site-packages/dgl/heterograph.py", line 68, in __init__
dgl._ffi.base.DGLError: The input is already a DGLGraph. No need to create it again
I hope you undersand what I am trying to do here. If you have any doubt don’t hesitate to ask me. Maybe there is a simpler way of doing it. I am looking forward to your answers.
Greetings,
Daniel.