Can DGLGraph get the shortest path between two node?

I wanna get the loss weighted by the path length between the negative node and the positive node (maybe the sampling weight also generate by this) in a hierarchical graph.

Dose DGL provide graph API for this usage?

You could implement single-source-shortest-path using message passing:

g.ndata['x'] = torch.zeros(g.num_nodes())
g.ndata['x'][:] = 1000000    # very big number
g.ndata['x'][source] = 0
for _ in range(graph_diameter):
    g.update_all(fn.u_add_e('x', 'distance', 'm'), fn.min('m', 'x'))

If you have multiple sources you can parallelize similarly. Note that this will give you a num_sources x num_nodes distance tensor.