Hello,
I hope this message finds you well. I am currently attempting to construct a heterograph in C++ to accelerate my data processing pipeline. Could you please advise me on how to pass the generated DGLGraph back to Python? Below is my current attempt:
struct MetaGraph{
dgl::HeteroGraphRef hgidx;
py::object get_hgidx(){
return py::cast(hgidx);
}
};
dgl::HeteroGraphRef transformToMetaGraph(Graph& g){
std::vector<int> from_vec{1, 1, 1, 1, 1, 2, 2, 2, 2, 2};
std::vector<int> to_vec{0, 1, 2, 1, 2, 1, 2, 3, 1, 2};
int agn;
int bn;
auto from = dgl::IdArray::FromVector(from_vec);
auto to = dgl::IdArray::FromVector(to_vec);
auto metagraph = dgl::GraphRef(dgl::ImmutableGraph::CreateFromCOO(4, from, to));
std::vector<dgl::HeteroGraphRef> rel_graphs;
dgl::dgl_format_code_t code = 1;
auto row = dgl::IdArray::FromVector(g.ba.first);
auto col = dgl::IdArray::FromVector(g.ba.second);
auto hgptr = dgl::CreateFromCOO(
2, bn, agn, row, col, false, false, code);
rel_graphs.emplace_back(dgl::HeteroGraphRef(hgptr));
// ...
std::vector<dgl::HeteroGraphPtr> rel_ptrs;
rel_ptrs.reserve(rel_graphs.size());
for (const auto& ref : rel_graphs) {
rel_ptrs.push_back(ref.sptr());
}
auto hgptr_f = dgl::CreateHeteroGraph(
metagraph.sptr(), rel_ptrs, {agn, bn, sn, spn});
return dgl::HeteroGraphRef(hgptr_f);
}
PYBIND11_MODULE(GraphExtract, m) {
m.def("extractFeature", &extractFeature, "A func");
py::class_<MetaGraph, std::shared_ptr<MetaGraph>>(m, "MetaGraph")
.def(py::init<>())
.def("get_hgidx", &MetaGraph::get_hgidx);
}
When using get_hgidx in Python, the following prompt occurs:
g.get_hgidx()
TypeError: Unregistered type : dgl::HeteroGraphRef
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "<string>", line 1, in <module>
TypeError: Unable to convert function return value to a Python type! The signature was
(self: GraphExtract.MetaGraph) -> object
How can I conveniently read the DGLGraph constructed in C++ in Python? Alternatively, could you tell me any methods to accelerate the construction of heterographs?
Thank you very much for your assistance.
Best regards.