Skip to content

Commit

Permalink
Fix the node_prop_indices in tranformView
Browse files Browse the repository at this point in the history
  • Loading branch information
gurbinder533 committed Feb 20, 2022
1 parent 1fe9b59 commit 42e06f9
Show file tree
Hide file tree
Showing 28 changed files with 142 additions and 133 deletions.
29 changes: 28 additions & 1 deletion libgraph/include/katana/analytics/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "katana/ErrorCode.h"
#include "katana/PropertyGraph.h"
#include "katana/Result.h"
#include "katana/TypedPropertyGraph.h"

namespace katana::analytics {

Expand Down Expand Up @@ -112,6 +113,32 @@ class KATANA_EXPORT TemporaryPropertyGuard {

KATANA_EXPORT void SplitStringByComma(
std::string& str, std::vector<std::string>* vec);
} // namespace katana::analytics

template <typename EdgeWeightType>
static katana::Result<void>
AddDefaultEdgeWeight(
katana::PropertyGraph* pg, const std::string& edge_weight_property_name,
const EdgeWeightType& default_val, katana::TxnContext* txn_ctx) {
struct EdgeWt : public katana::PODProperty<EdgeWeightType> {};
using EdgeData = std::tuple<EdgeWt>;

if (auto res = pg->ConstructEdgeProperties<EdgeData>(
txn_ctx, {edge_weight_property_name});
!res) {
return res.error();
}

auto typed_graph =
KATANA_CHECKED((katana::TypedPropertyGraph<std::tuple<>, EdgeData>::Make(
pg, {}, {edge_weight_property_name})));
katana::do_all(
katana::iterate(typed_graph.OutEdges()),
[&](auto e) {
typed_graph.template GetEdgeData<EdgeWt>(e) = default_val;
},
katana::steal(), katana::loopname("SetDefaultWeight"));
return katana::ResultSuccess();

} // namespace katana::analytics
} // namespace katana::analytics
#endif
2 changes: 1 addition & 1 deletion libgraph/include/katana/analytics/sssp/sssp.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ KATANA_EXPORT Result<void> Sssp(
KATANA_EXPORT Result<void> SsspAssertValid(
PropertyGraph* pg, size_t start_node,
const std::string& edge_weight_property_name,
const std::string& output_property_name);
const std::string& output_property_name, katana::TxnContext* txn_ctx);

struct KATANA_EXPORT SsspStatistics {
/// The number of nodes reachable from the source node.
Expand Down
22 changes: 15 additions & 7 deletions libgraph/src/GraphTopology.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ katana::GraphTopology::Copy(const GraphTopology& that) noexcept {
return katana::GraphTopology(
that.adj_indices_.data(), that.adj_indices_.size(), that.dests_.data(),
that.dests_.size(), that.edge_prop_indices_.data(),
that.edge_prop_indices_.data());
that.node_prop_indices_.data());
}

katana::GraphTopology::PropertyIndex
Expand Down Expand Up @@ -122,12 +122,14 @@ katana::EdgeShuffleTopology::MakeTransposeCopy(

AdjIndexVec out_indices;
EdgeDestVec out_dests;
PropIndexVec edge_prop_indices;
AdjIndexVec out_dests_offset;
PropIndexVec edge_prop_indices;
PropIndexVec node_prop_indices;

out_indices.allocateInterleaved(topology.NumNodes());
out_dests.allocateInterleaved(topology.NumEdges());
edge_prop_indices.allocateInterleaved(topology.NumEdges());

out_dests_offset.allocateInterleaved(topology.NumNodes());

katana::ParallelSTL::fill(out_indices.begin(), out_indices.end(), Edge{0});
Expand Down Expand Up @@ -178,13 +180,19 @@ katana::EdgeShuffleTopology::MakeTransposeCopy(
},
katana::steal(), katana::no_stats());

// Node property indexes do not change for EdgeShuffleTopology.
const PropertyIndex* from = topology.node_prop_indices_.data();
if (from) {
node_prop_indices.allocateInterleaved(topology.NumNodes());
katana::ParallelSTL::copy(
&from[0], &from[topology.NumNodes()], node_prop_indices.begin());
}

return std::make_shared<EdgeShuffleTopology>(EdgeShuffleTopology{
katana::RDGTopology::TransposeKind::kYes,
katana::RDGTopology::EdgeSortKind::kAny,
std::move(out_indices),
std::move(out_dests),
std::move(edge_prop_indices),
{}});
katana::RDGTopology::EdgeSortKind::kAny, std::move(out_indices),
std::move(out_dests), std::move(edge_prop_indices),
std::move(node_prop_indices)});
}

std::shared_ptr<katana::EdgeShuffleTopology>
Expand Down
35 changes: 3 additions & 32 deletions libgraph/src/analytics/k_shortest_paths/ksssp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,35 +294,6 @@ PrintPath(const Path* path) {
katana::gPrint(" ", path->parent);
}

/**
* Adds edge weights if there are none
*
* @param pg property graph
* @param edge_weight_property_name edge weights
*/
template <typename EdgeWeightType>
static katana::Result<void>
AddDefaultEdgeWeight(
katana::PropertyGraph* pg, const std::string& edge_weight_property_name,
katana::TxnContext* txn_ctx) {
using EdgeData = std::tuple<EdgeWeightType>;

if (auto res = pg->ConstructEdgeProperties<EdgeData>(
txn_ctx, {edge_weight_property_name});
!res) {
return res.error();
}

auto typed_graph =
KATANA_CHECKED((katana::TypedPropertyGraph<std::tuple<>, EdgeData>::Make(
pg, {}, {edge_weight_property_name})));
katana::do_all(
katana::iterate(typed_graph.OutEdges()),
[&](auto e) { typed_graph.template GetEdgeData<EdgeWeightType>(e) = 1; },
katana::steal(), katana::loopname("InitEdgeWeight"));
return katana::ResultSuccess();
}

/**
* Sets up and runs implementation of ksssp
*
Expand Down Expand Up @@ -538,9 +509,9 @@ katana::analytics::Ksssp(
if (edge_weight_property_name.empty()) {
TemporaryPropertyGuard temporary_edge_property{
pg->EdgeMutablePropertyView()};
struct EdgeWt : public katana::PODProperty<int64_t> {};
KATANA_CHECKED(AddDefaultEdgeWeight<EdgeWt>(
pg, temporary_edge_property.name(), txn_ctx));
using EdgeWeightType = int64_t;
KATANA_CHECKED(katana::analytics::AddDefaultEdgeWeight<EdgeWeightType>(
pg, temporary_edge_property.name(), 1, txn_ctx));
return kSSSPWithWrap<int64_t>(
pg, temporary_edge_property.name(), start_node, report_node, num_paths,
is_symmetric, txn_ctx, plan);
Expand Down
38 changes: 9 additions & 29 deletions libgraph/src/analytics/leiden_clustering/leiden_clustering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -628,29 +628,6 @@ struct LeidenClusteringImplementation
}
};

template <typename EdgeWeightType>
static katana::Result<void>
AddDefaultEdgeWeight(
katana::PropertyGraph* pg, const std::string& edge_weight_property_name,
katana::TxnContext* txn_ctx) {
using EdgeData = std::tuple<EdgeWeightType>;

if (auto res = pg->ConstructEdgeProperties<EdgeData>(
txn_ctx, {edge_weight_property_name});
!res) {
return res.error();
}

auto typed_graph =
KATANA_CHECKED((katana::TypedPropertyGraph<std::tuple<>, EdgeData>::Make(
pg, {}, {edge_weight_property_name})));
katana::do_all(
katana::iterate(typed_graph.OutEdges()),
[&](auto e) { typed_graph.template GetEdgeData<EdgeWeightType>(e) = 1; },
katana::steal(), katana::loopname("InitEdgeWeight"));
return katana::ResultSuccess();
}

template <typename EdgeWeightType>
static katana::Result<void>
LeidenClusteringWithWrap(
Expand Down Expand Up @@ -740,9 +717,11 @@ katana::analytics::LeidenClustering(
if (edge_weight_property_name.empty()) {
TemporaryPropertyGuard temporary_edge_property{
pg->EdgeMutablePropertyView()};
struct EdgeWt : public katana::PODProperty<int64_t> {};
KATANA_CHECKED(AddDefaultEdgeWeight<EdgeWt>(
pg, temporary_edge_property.name(), txn_ctx));

using EdgeWeightType = int64_t;
KATANA_CHECKED(katana::analytics::AddDefaultEdgeWeight<EdgeWeightType>(
pg, temporary_edge_property.name(), 1, txn_ctx));

return LeidenClusteringWithWrap<int64_t>(
pg, temporary_edge_property.name(), output_property_name, is_symmetric,
plan, txn_ctx);
Expand Down Expand Up @@ -915,9 +894,10 @@ katana::analytics::LeidenClusteringStatistics::Compute(
if (edge_weight_property_name.empty()) {
TemporaryPropertyGuard temporary_edge_property{
pg->EdgeMutablePropertyView()};
struct EdgeWt : public katana::PODProperty<int64_t> {};
KATANA_CHECKED(AddDefaultEdgeWeight<EdgeWt>(
pg, temporary_edge_property.name(), txn_ctx));

using EdgeWeightType = int64_t;
KATANA_CHECKED(katana::analytics::AddDefaultEdgeWeight<EdgeWeightType>(
pg, temporary_edge_property.name(), 1, txn_ctx));

auto modularity_result = CalModularityWrap<int64_t>(
pg, temporary_edge_property.name(), property_name);
Expand Down
40 changes: 9 additions & 31 deletions libgraph/src/analytics/louvain_clustering/louvain_clustering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -501,29 +501,6 @@ struct LouvainClusteringImplementation
}
};

template <typename EdgeWeightType>
static katana::Result<void>
AddDefaultEdgeWeight(
katana::PropertyGraph* pg, const std::string& edge_weight_property_name,
katana::TxnContext* txn_ctx) {
using EdgeData = std::tuple<EdgeWeightType>;

if (auto res = pg->ConstructEdgeProperties<EdgeData>(
txn_ctx, {edge_weight_property_name});
!res) {
return res.error();
}

auto typed_graph =
KATANA_CHECKED((katana::TypedPropertyGraph<std::tuple<>, EdgeData>::Make(
pg, {}, {edge_weight_property_name})));
katana::do_all(
katana::iterate(typed_graph.OutEdges()),
[&](auto e) { typed_graph.template GetEdgeData<EdgeWeightType>(e) = 1; },
katana::steal(), katana::loopname("InitEdgeWeight"));
return katana::ResultSuccess();
}

template <typename EdgeWeightType>
static katana::Result<void>
LouvainClusteringWithWrap(
Expand Down Expand Up @@ -609,10 +586,11 @@ katana::analytics::LouvainClustering(
if (edge_weight_property_name.empty()) {
TemporaryPropertyGuard temporary_edge_property{
pg->EdgeMutablePropertyView()};
struct EdgeWt : public katana::PODProperty<int64_t> {};
KATANA_CHECKED(AddDefaultEdgeWeight<EdgeWt>(
pg, temporary_edge_property.name(), txn_ctx));
return LouvainClusteringWithWrap<int64_t>(
using EdgeWeightType = int64_t;
KATANA_CHECKED(katana::analytics::AddDefaultEdgeWeight<EdgeWeightType>(
pg, temporary_edge_property.name(), 1, txn_ctx));

return LouvainClusteringWithWrap<EdgeWeightType>(
pg, temporary_edge_property.name(), output_property_name, is_symmetric,
plan, txn_ctx);
}
Expand Down Expand Up @@ -785,11 +763,11 @@ katana::analytics::LouvainClusteringStatistics::Compute(
if (edge_weight_property_name.empty()) {
TemporaryPropertyGuard temporary_edge_property{
pg->EdgeMutablePropertyView()};
struct EdgeWt : public katana::PODProperty<int64_t> {};
KATANA_CHECKED(AddDefaultEdgeWeight<EdgeWt>(
pg, temporary_edge_property.name(), txn_ctx));
using EdgeWeightType = int64_t;
KATANA_CHECKED(katana::analytics::AddDefaultEdgeWeight<EdgeWeightType>(
pg, temporary_edge_property.name(), 1, txn_ctx));

auto modularity_result = CalModularityWrap<int64_t>(
auto modularity_result = CalModularityWrap<EdgeWeightType>(
pg, temporary_edge_property.name(), property_name);
if (!modularity_result) {
return modularity_result.error();
Expand Down
41 changes: 39 additions & 2 deletions libgraph/src/analytics/sssp/sssp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,6 @@ SSSPWithWrap(
if (!graph) {
return graph.error();
}

return Sssp(graph.value(), start_node, plan);
}

Expand All @@ -550,6 +549,25 @@ katana::analytics::Sssp(
const std::string& edge_weight_property_name,
const std::string& output_property_name, katana::TxnContext* txn_ctx,
SsspPlan plan) {
if (!edge_weight_property_name.empty() &&
!pg->HasEdgeProperty(edge_weight_property_name)) {
return KATANA_ERROR(
katana::ErrorCode::NotFound, "Edge Property: {} Not found",
edge_weight_property_name);
}
// If edge property name empty, add int64_t property
// add initialize it to 1.
if (edge_weight_property_name.empty()) {
TemporaryPropertyGuard temporary_edge_property{
pg->EdgeMutablePropertyView()};
using EdgeWeightType = int64_t;
KATANA_CHECKED(katana::analytics::AddDefaultEdgeWeight<EdgeWeightType>(
pg, temporary_edge_property.name(), 1, txn_ctx));

return SSSPWithWrap<EdgeWeightType>(
pg, start_node, temporary_edge_property.name(), output_property_name,
plan, txn_ctx);
}
switch (KATANA_CHECKED(pg->GetEdgeProperty(edge_weight_property_name))
->type()
->id()) {
Expand Down Expand Up @@ -626,7 +644,26 @@ katana::Result<void>
katana::analytics::SsspAssertValid(
katana::PropertyGraph* pg, size_t start_node,
const std::string& edge_weight_property_name,
const std::string& output_property_name) {
const std::string& output_property_name, katana::TxnContext* txn_ctx) {
if (!edge_weight_property_name.empty() &&
!pg->HasEdgeProperty(edge_weight_property_name)) {
return KATANA_ERROR(
katana::ErrorCode::NotFound, "Edge Property: {} Not found",
edge_weight_property_name);
}
// If edge property name empty, add int64_t property
// add initialize it to 1.
if (edge_weight_property_name.empty()) {
TemporaryPropertyGuard temporary_edge_property{
pg->EdgeMutablePropertyView()};
using EdgeWeightType = int64_t;
KATANA_CHECKED(katana::analytics::AddDefaultEdgeWeight<EdgeWeightType>(
pg, temporary_edge_property.name(), 1, txn_ctx));

return SsspValidateImpl<EdgeWeightType>(
pg, start_node, temporary_edge_property.name(), output_property_name);
}

switch (
KATANA_CHECKED(pg->GetNodeProperty(output_property_name))->type()->id()) {
case arrow::UInt32Type::type_id:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ main(int argc, char** argv) {
katana::analytics::SplitStringByComma(edge_types, &vec_edge_types);
}

auto pg_projected_view = katana::TransformationView::MakeProjectedGraph(
auto pg_projected_view = katana::PropertyGraph::MakeProjectedGraph(
*pg.get(), vec_node_types, vec_edge_types);

std::cout << "Projected graph has: "
Expand Down
2 changes: 1 addition & 1 deletion lonestar/analytics/cpu/bfs/bfs_cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ main(int argc, char** argv) {
katana::analytics::SplitStringByComma(edge_types, &vec_edge_types);
}

auto pg_projected_view = katana::TransformationView::MakeProjectedGraph(
auto pg_projected_view = katana::PropertyGraph::MakeProjectedGraph(
*pg.get(), vec_node_types, vec_edge_types);

std::cout << "Projected graph has: "
Expand Down
2 changes: 1 addition & 1 deletion lonestar/analytics/cpu/cdlp/cdlp_cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ main(int argc, char** argv) {
katana::analytics::SplitStringByComma(edge_types, &vec_edge_types);
}

auto pg_projected_view = katana::TransformationView::MakeProjectedGraph(
auto pg_projected_view = katana::PropertyGraph::MakeProjectedGraph(
*pg.get(), vec_node_types, vec_edge_types);

std::cout << "Projected graph has: "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ main(int argc, char** argv) {
katana::analytics::SplitStringByComma(edge_types, &vec_edge_types);
}

auto pg_projected_view = katana::TransformationView::MakeProjectedGraph(
auto pg_projected_view = katana::PropertyGraph::MakeProjectedGraph(
*pg.get(), vec_node_types, vec_edge_types);

std::cout << "Projected graph has: "
Expand Down
2 changes: 1 addition & 1 deletion lonestar/analytics/cpu/jaccard/jaccard_cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ main(int argc, char** argv) {
katana::analytics::SplitStringByComma(edge_types, &vec_edge_types);
}

auto pg_projected_view = katana::TransformationView::MakeProjectedGraph(
auto pg_projected_view = katana::PropertyGraph::MakeProjectedGraph(
*pg.get(), vec_node_types, vec_edge_types);

std::cout << "Projected graph has: "
Expand Down
2 changes: 1 addition & 1 deletion lonestar/analytics/cpu/k-core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ add_test_scale(small k-core-cpu INPUT rmat15 INPUT_URI "${RDG_RMAT15}" --kCoreNu

## Test TranformView
add_test_scale(small k-core-cpu NO_VERIFY INPUT ldbc003 INPUT_URI "${RDG_LDBC_003}" --node_types=Person)
add_test_scale(small k-core-cpu NO_VERIFY INPUT ldbc003 INPUT_URI "${RDG_LDBC_003}" --node_types=CONTAINER_OF)
add_test_scale(small k-core-cpu NO_VERIFY INPUT ldbc003 INPUT_URI "${RDG_LDBC_003}" --edge_types=CONTAINER_OF)
2 changes: 1 addition & 1 deletion lonestar/analytics/cpu/k-core/kcore_cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ main(int argc, char** argv) {
katana::analytics::SplitStringByComma(edge_types, &vec_edge_types);
}

auto pg_projected_view = katana::TransformationView::MakeProjectedGraph(
auto pg_projected_view = katana::PropertyGraph::MakeProjectedGraph(
*pg.get(), vec_node_types, vec_edge_types);

std::cout << "Projected graph has: "
Expand Down
Loading

0 comments on commit 42e06f9

Please sign in to comment.