cugraph icon indicating copy to clipboard operation
cugraph copied to clipboard

[QST]: How to (Add/Remove edges) from a graph?

Open Ibrahim25-ai opened this issue 1 year ago • 1 comments

rmm::device_uvector<int64_t> d_edge_srcs(srcs.size(), stream1); rmm::device_uvector<int64_t> d_edge_dsts(dsts.size(), stream1);

raft::update_device(d_edge_srcs.data(), srcs.data(), srcs.size(), stream1);

raft::update_device(d_edge_dsts.data(),  dsts.data(), dsts.size(),  stream1);


    
std::optional<rmm::device_uvector<double>> d_edge_weights{std::nullopt}; 


cugraph::graph_properties_t properties{.is_symmetric = true, .is_multigraph = true};


bool renumber = true;
    cugraph::graph_t<int64_t, int64_t, false, false> graph(handle1);
    std::optional<rmm::device_uvector<int64_t>> renumber_map{std::nullopt};

std::tie(graph, std::ignore, std::ignore, std::ignore, renumber_map)  = cugraph::create_graph_from_edgelist<int64_t, int64_t, double, int64_t, int32_t, false, false>(
    handle1,
    std::nullopt, // Pass std::nullopt if no vertex ids are provided, otherwise, provide a device_uvector of vertex ids.
    std::move(d_edge_srcs),
    std::move(d_edge_dsts),
    std::move(d_edge_weights),
    std::nullopt, // std::nullopt for default vertex ids
    std::nullopt, // std::nullopt for default vertex labels
    properties,
    renumber,
    true // sorted by degree
);

the edge masking is supported in v24.04.00 ,so how i can add or remove edges without destructing the graph_t ?

Code of Conduct

  • [X] I agree to follow cuGraph's Code of Conduct
  • [X] I have searched the open issues and have found no duplicates for this question

Ibrahim25-ai avatar Apr 28 '24 17:04 Ibrahim25-ai

Support for dynamic graphs is in design currently. I expect that we will have a clearer concept of how we plan on handling them and what the timeline for implementation will be at some point this summer.

Removing Edges Until the dynamic graphs feature is in place, there is no support for removing edges from a graph. You can use the edge mask to virtually remove the edges. https://github.com/rapidsai/cugraph/blob/3393b060f06cb00fe846387b652a4b38d56b23a8/cpp/tests/structure/weight_sum_test.cpp#L110 is a recent update to a unit test that uses edge masking. You can create an edge property (from an rmm::device_uvector that identifies which edges to mask out. They will still consume memory, and there will be a small overhead to skip them when traversing, but you should get the correct functionality and performance on edge masking is pretty good.

Adding Edges Until the dynamic graphs feature is in place, there is no mechanism for adding edges to an existing graph without rebuilding it. If you know the entire possible edge set up front you can create the graph and use edge masking to simulate the addition of edges from the graph. If you are truly dynamically adding edges to the graph and you don't know them all a priori then you will need to recreate the graph.

Graph creation is pretty fast. If you still have the original list of edges, append the new edges to the list and create a new graph. If you don't have a copy of the original edges, you can construct a new copy from the graph using the function https://github.com/rapidsai/cugraph/blob/3393b060f06cb00fe846387b652a4b38d56b23a8/cpp/include/cugraph/graph_functions.hpp#L372 which will take a cugraph::graph_view_t and generate the list of edges that are part of it. Appending your new edges to this structure you should be able to create the new graph.

ChuckHastings avatar Apr 29 '24 15:04 ChuckHastings