Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

extract the edgelist from the graph #4750

Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
d95967e
expose decompress_to_edgelist to the CAPI
jnke2016 Nov 9, 2024
426c7ed
expose decompress to edgelist to the PLC API
jnke2016 Nov 9, 2024
dd734b1
expose decompress to edgelist to the python API
jnke2016 Nov 9, 2024
8dc23fe
remove debug print
jnke2016 Nov 10, 2024
ee14ff6
fix typo
jnke2016 Nov 10, 2024
37caab7
remove unsued code and support edge ids and types
jnke2016 Nov 10, 2024
230f239
add mg implementation of decompress_to_edgelist
jnke2016 Nov 11, 2024
e0fd0b5
rename file
jnke2016 Nov 11, 2024
946b033
update docstrings
jnke2016 Nov 11, 2024
17e2123
remove argument
jnke2016 Nov 11, 2024
fe9a277
remove 'legacy_renum_only' flag and move the function 'decompress_to_…
jnke2016 Nov 11, 2024
1182ff5
rename variable and update docstrings
jnke2016 Nov 19, 2024
6b701b5
fix typo
jnke2016 Nov 19, 2024
73eb575
add test for the edge extraction functionality
jnke2016 Nov 19, 2024
88bd561
add test for the edge extraction functionality on mg graph
jnke2016 Nov 19, 2024
6af846b
add method to extract the edgelist from an SG graph
jnke2016 Nov 19, 2024
f34070c
remove deprecated flag
jnke2016 Nov 19, 2024
3b978d5
remove global test variables
jnke2016 Nov 19, 2024
4845241
fix style
jnke2016 Nov 19, 2024
3563ea9
Merge remote-tracking branch 'upstream/branch-24.12' into branch-24.1…
jnke2016 Nov 19, 2024
326d76a
fix style
jnke2016 Nov 19, 2024
767af09
add missing return statement
jnke2016 Nov 19, 2024
335729c
deprecate old API
jnke2016 Nov 20, 2024
abb695e
add new API to retrieve the edgelist from a graph
jnke2016 Nov 20, 2024
b84bdd8
re-order function declaration and fix typo
jnke2016 Nov 20, 2024
4145cc9
add mew API to extract edgelist and deprecate old API
jnke2016 Nov 20, 2024
2b47fe3
fix style
jnke2016 Nov 20, 2024
7e53957
Merge remote-tracking branch 'upstream/branch-24.12' into branch-24.1…
jnke2016 Nov 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,7 @@ add_library(cugraph_c
src/c_api/weakly_connected_components.cpp
src/c_api/strongly_connected_components.cpp
src/c_api/allgather.cpp
src/c_api/decompress_to_edgelist.cpp
)
add_library(cugraph::cugraph_c ALIAS cugraph_c)

Expand Down
19 changes: 19 additions & 0 deletions cpp/include/cugraph_c/graph_functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,25 @@ cugraph_error_code_t cugraph_degrees(const cugraph_resource_handle_t* handle,
cugraph_degrees_result_t** result,
cugraph_error_t** error);

/**
* @brief Construct the edge list from the graph view object.
*
* @param [in] handle Handle for accessing resources
* @param [in] graph Graph to operate on
* @param [in] do_expensive_check A flag to run expensive checks for input arguments (if set to
* true)
* @param [out] result Opaque pointer to induced subgraph result
* @param [out] error Pointer to an error object storing details of any error. Will
* be populated if error code is not CUGRAPH_SUCCESS
* @return error code
*/
cugraph_error_code_t cugraph_decompress_to_edgelist(
const cugraph_resource_handle_t* handle,
cugraph_graph_t* graph,
bool_t do_expensive_check,
cugraph_induced_subgraph_result_t** result,
cugraph_error_t** error);

/**
* @brief Get the vertex ids
*
Expand Down
131 changes: 131 additions & 0 deletions cpp/src/c_api/decompress_to_edgelist.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
/*
* Copyright (c) 2022-2024, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "c_api/abstract_functor.hpp"
#include "c_api/core_result.hpp"
#include "c_api/graph.hpp"
#include "c_api/induced_subgraph_result.hpp"
#include "c_api/resource_handle.hpp"
#include "c_api/utils.hpp"

#include <cugraph_c/algorithms.h>

#include <cugraph/algorithms.hpp>
#include <cugraph/detail/shuffle_wrappers.hpp> // FIXME: mihgt remove the shuffle headers because they are unsued
#include <cugraph/detail/utility_wrappers.hpp>
#include <cugraph/graph_functions.hpp>

#include <optional>

namespace {

struct decompress_to_edgelist_functor : public cugraph::c_api::abstract_functor {
raft::handle_t const& handle_;
cugraph::c_api::cugraph_graph_t* graph_{};

cugraph::c_api::cugraph_core_result_t const* core_result_{};
bool do_expensive_check_{};
cugraph::c_api::cugraph_induced_subgraph_result_t* result_{};

decompress_to_edgelist_functor(cugraph_resource_handle_t const* handle,
cugraph_graph_t* graph,
bool do_expensive_check)
: abstract_functor(),
handle_(*reinterpret_cast<cugraph::c_api::cugraph_resource_handle_t const*>(handle)->handle_),
graph_(reinterpret_cast<cugraph::c_api::cugraph_graph_t*>(graph)),
do_expensive_check_(do_expensive_check)
{
}

template <typename vertex_t,
typename edge_t,
typename weight_t,
typename edge_type_type_t,
bool store_transposed,
bool multi_gpu>
void operator()()
{
if constexpr (!cugraph::is_candidate<vertex_t, edge_t, weight_t>::value) {
unsupported();
} else {
if constexpr (store_transposed) {
error_code_ = cugraph::c_api::
transpose_storage<vertex_t, edge_t, weight_t, store_transposed, multi_gpu>(
handle_, graph_, error_.get());
if (error_code_ != CUGRAPH_SUCCESS)
;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's this?

}
// FIXME: Transpose_storage may have a bug, since if store_transposed is True it can reverse
// the bool value of is_symmetric
auto graph =
reinterpret_cast<cugraph::graph_t<vertex_t, edge_t, store_transposed, multi_gpu>*>(graph_->graph_);

auto graph_view = graph->view();

auto edge_weights = reinterpret_cast<
cugraph::edge_property_t<cugraph::graph_view_t<vertex_t, edge_t, store_transposed, multi_gpu>,
weight_t>*>(graph_->edge_weights_);

auto edge_ids = reinterpret_cast<
cugraph::edge_property_t<cugraph::graph_view_t<vertex_t, edge_t, store_transposed, multi_gpu>,
edge_t>*>(graph_->edge_ids_);

auto edge_types = reinterpret_cast<
cugraph::edge_property_t<cugraph::graph_view_t<vertex_t, edge_t, store_transposed, multi_gpu>,
edge_type_type_t>*>(graph_->edge_types_);

auto number_map = reinterpret_cast<rmm::device_uvector<vertex_t>*>(graph_->number_map_);


auto [result_src, result_dst, result_wgt, result_edge_id, result_edge_type] =
cugraph::decompress_to_edgelist<vertex_t, edge_t, weight_t, edge_type_type_t, store_transposed, multi_gpu>(
handle_,
graph_view,
(edge_weights != nullptr) ? std::make_optional(edge_weights->view()) : std::nullopt,
(edge_ids != nullptr) ? std::make_optional(edge_ids->view()) : std::nullopt,
(edge_types != nullptr) ? std::make_optional(edge_types->view()) : std::nullopt,
(number_map != nullptr) ? std::make_optional<raft::device_span<vertex_t const>>(
number_map->data(), number_map->size())
: std::nullopt,
do_expensive_check_);


result_ = new cugraph::c_api::cugraph_induced_subgraph_result_t{
new cugraph::c_api::cugraph_type_erased_device_array_t(result_src, graph_->vertex_type_),
new cugraph::c_api::cugraph_type_erased_device_array_t(result_dst, graph_->vertex_type_),
result_wgt ? new cugraph::c_api::cugraph_type_erased_device_array_t(*result_wgt, graph_->weight_type_)
: NULL,
result_edge_id ? new cugraph::c_api::cugraph_type_erased_device_array_t(*result_edge_id, graph_->edge_type_)
: NULL,
result_edge_type ? new cugraph::c_api::cugraph_type_erased_device_array_t(*result_edge_type, graph_->edge_type_id_type_)
: NULL,
NULL};
}
}
};

} // namespace

extern "C" cugraph_error_code_t cugraph_decompress_to_edgelist(const cugraph_resource_handle_t* handle,
cugraph_graph_t* graph,
bool_t do_expensive_check,
cugraph_induced_subgraph_result_t** result,
cugraph_error_t** error)
{
decompress_to_edgelist_functor functor(handle, graph, do_expensive_check);

return cugraph::c_api::run_algorithm(graph, functor, result, error);
}
41 changes: 4 additions & 37 deletions python/cugraph/cugraph/structure/graph_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ def from_cudf_edgelist(
edge_type=None,
renumber=True,
store_transposed=False,
legacy_renum_only=False,
symmetrize=None,
):
"""
Expand Down Expand Up @@ -168,13 +167,6 @@ def from_cudf_edgelist(
If True, stores the transpose of the adjacency matrix. Required
for certain algorithms.

legacy_renum_only : bool, optional (default=False)
If True, skips the C++ renumbering step. Must be true for
pylibcugraph algorithms. Must be false for algorithms
not yet converted to the pylibcugraph C API.

This parameter is deprecated and will be removed.

symmetrize: bool, optional (default=None)
If True, symmetrize the edge list for an undirected graph. Setting
this flag to True for a directed graph returns an error. The default
Expand Down Expand Up @@ -210,7 +202,6 @@ def from_cudf_edgelist(
edge_type=edge_type,
renumber=renumber,
store_transposed=store_transposed,
legacy_renum_only=legacy_renum_only,
symmetrize=symmetrize,
)

Expand Down Expand Up @@ -305,8 +296,7 @@ def from_dask_cudf_edgelist(
edge_id=None,
edge_type=None,
renumber=True,
store_transposed=False,
legacy_renum_only=False,
store_transposed=False
):
"""
Initializes the distributed graph from the dask_cudf.DataFrame
Expand Down Expand Up @@ -353,13 +343,6 @@ def from_dask_cudf_edgelist(
If True, stores the transpose of the adjacency matrix. Required
for certain algorithms.

legacy_renum_only : bool, optional (default=False)
If True, skips the C++ renumbering step. Must be true for
pylibcugraph algorithms. Must be false for algorithms
not yet converted to the pylibcugraph C API.

This parameter is deprecated and will be removed.

"""

if self._Impl is None:
Expand All @@ -377,8 +360,7 @@ def from_dask_cudf_edgelist(
edge_id=edge_id,
edge_type=edge_type,
renumber=renumber,
store_transposed=store_transposed,
legacy_renum_only=legacy_renum_only,
store_transposed=store_transposed
)

# Move to Compat Module
Expand Down Expand Up @@ -868,8 +850,7 @@ def from_cudf_edgelist(
destination="destination",
edge_attr=None,
renumber=True,
store_transposed=False,
legacy_renum_only=False,
store_transposed=False
):
"""
Initialize a graph from the edge list. It is an error to call this
Expand Down Expand Up @@ -909,13 +890,6 @@ def from_cudf_edgelist(
If True, stores the transpose of the adjacency matrix. Required
for certain algorithms.

legacy_renum_only : bool, optional (default=False)
If True, skips the C++ renumbering step. Must be true for
pylibcugraph algorithms. Must be false for algorithms
not yet converted to the pylibcugraph C API.

This parameter is deprecated and will be removed.

Examples
--------
>>> df = cudf.read_csv(datasets_path / 'karate.csv', delimiter=' ',
Expand Down Expand Up @@ -944,8 +918,7 @@ def from_dask_cudf_edgelist(
destination="destination",
edge_attr=None,
renumber=True,
store_transposed=False,
legacy_renum_only=False,
store_transposed=False
):
"""
Initializes the distributed graph from the dask_cudf.DataFrame
Expand Down Expand Up @@ -980,12 +953,6 @@ def from_dask_cudf_edgelist(
If True, stores the transpose of the adjacency matrix. Required
for certain algorithms.

legacy_renum_only : bool, optional (default=False)
If True, skips the C++ renumbering step. Must be true for
pylibcugraph algorithms. Must be false for algorithms
not yet converted to the pylibcugraph C API.

This parameter is deprecated and will be removed.
"""
raise TypeError("Distributed N-partite graph not supported")

Expand Down
Loading
Loading