Skip to content

Commit

Permalink
[networkx] Update the built-in app implementation to make the behavio…
Browse files Browse the repository at this point in the history
…r consistent with NetworkX implementation (#1176)
  • Loading branch information
acezen committed Dec 20, 2021
1 parent 3049ef9 commit 76d4641
Show file tree
Hide file tree
Showing 16 changed files with 758 additions and 619 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/gae.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
run: |
# default install to "/opt/graphscope"
make gae ENABLE_JAVA_SDK=ON BUILD_TEST=ON
# also make coordinator andclient for python test
# also make coordinator and client for python test
make coordinator && make client
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ all: graphscope
graphscope: install

.PHONY: gsruntime-image
gsruntime:
gsruntime-image:
$(MAKE) -C $(WORKING_DIR)/k8s/ gsruntime-image VERSION=$(VERSION)

.PHONY: gsvineyard-image
gsvineyard:
gsvineyard-image:
$(MAKE) -C $(WORKING_DIR)/k8s/ gsvineyard-image VERSION=$(VERSION)

.PHONY: graphscope-image
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,36 +79,29 @@ class EigenvectorCentrality
return false;
}

template <typename FRAG_T_, typename = void>
struct Pull {
void operator()(const fragment_t& frag, context_t& ctx,
message_manager_t& messages) {
auto inner_vertices = frag.InnerVertices();
auto& x = ctx.x;
auto& x_last = ctx.x_last;
void Pull(const fragment_t& frag, context_t& ctx,
message_manager_t& messages) {
auto inner_vertices = frag.InnerVertices();
auto& x = ctx.x;
auto& x_last = ctx.x_last;

if (frag.directed()) {
for (auto& v : inner_vertices) {
auto es = frag.GetIncomingAdjList(v);
x[v] = x_last[v];
auto es = frag.GetIncomingAdjList(v);
for (auto& e : es) {
x[v] += x_last[e.get_neighbor()];
double edata = 1.0;
static_if<!std::is_same<edata_t, grape::EmptyType>{}>(
[&](auto& e, auto& data) {
data = static_cast<double>(e.get_data());
})(e, edata);
x[v] += x_last[e.get_neighbor()] * edata;
}
}
}
};

template <typename FRAG_T_>
struct Pull<FRAG_T_,
typename std::enable_if<!std::is_same<
typename FRAG_T_::edata_t, grape::EmptyType>::value>::type> {
void operator()(const fragment_t& frag, context_t& ctx,
message_manager_t& messages) {
auto inner_vertices = frag.InnerVertices();
auto& x = ctx.x;
auto& x_last = ctx.x_last;

} else {
for (auto& v : inner_vertices) {
auto es = frag.GetIncomingAdjList(v);
x[v] = x_last[v];
auto es = frag.GetOutgoingAdjList(v);
for (auto& e : es) {
double edata = 1.0;
static_if<!std::is_same<edata_t, grape::EmptyType>{}>(
Expand All @@ -119,11 +112,11 @@ class EigenvectorCentrality
}
}
}
};
}

void PEval(const fragment_t& frag, context_t& ctx,
message_manager_t& messages) {
Pull<fragment_t>{}(frag, ctx, messages);
Pull(frag, ctx, messages);
auto inner_vertices = frag.InnerVertices();

// call NormAndCheckTerm before send. because we normalize the vector 'x' in
Expand Down Expand Up @@ -157,7 +150,7 @@ class EigenvectorCentrality

x_last.Swap(x);

Pull<fragment_t>{}(frag, ctx, messages);
Pull(frag, ctx, messages);

if (NormAndCheckTerm(frag, ctx))
return;
Expand Down
44 changes: 31 additions & 13 deletions analytical_engine/apps/centrality/katz/katz_centrality.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,20 +75,38 @@ class KatzCentrality : public AppBase<FRAG_T, KatzCentralityContext<FRAG_T>>,
auto& x = ctx.x;
auto& x_last = ctx.x_last;

for (auto& v : inner_vertices) {
auto es = frag.GetIncomingAdjList(v);
x[v] = 0;
for (auto& e : es) {
// do the multiplication y^T = Alpha * x^T A - Beta
double edata = 1.0;
static_if<!std::is_same<edata_t, grape::EmptyType>{}>(
[&](auto& e, auto& data) {
data = static_cast<double>(e.get_data());
})(e, edata);
x[v] += x_last[e.get_neighbor()] * edata;
if (frag.directed()) {
for (auto& v : inner_vertices) {
auto es = frag.GetIncomingAdjList(v);
x[v] = 0;
for (auto& e : es) {
// do the multiplication y^T = Alpha * x^T A - Beta
double edata = 1.0;
static_if<!std::is_same<edata_t, grape::EmptyType>{}>(
[&](auto& e, auto& data) {
data = static_cast<double>(e.get_data());
})(e, edata);
x[v] += x_last[e.get_neighbor()] * edata;
}
x[v] = x[v] * ctx.alpha + ctx.beta;
messages.SendMsgThroughEdges(frag, v, ctx.x[v]);
}
} else {
for (auto& v : inner_vertices) {
auto es = frag.GetOutgoingAdjList(v);
x[v] = 0;
for (auto& e : es) {
// do the multiplication y^T = Alpha * x^T A - Beta
double edata = 1.0;
static_if<!std::is_same<edata_t, grape::EmptyType>{}>(
[&](auto& e, auto& data) {
data = static_cast<double>(e.get_data());
})(e, edata);
x[v] += x_last[e.get_neighbor()] * edata;
}
x[v] = x[v] * ctx.alpha + ctx.beta;
messages.SendMsgThroughEdges(frag, v, ctx.x[v]);
}
x[v] = x[v] * ctx.alpha + ctx.beta;
messages.SendMsgThroughEdges(frag, v, ctx.x[v]);
}
}

Expand Down
124 changes: 56 additions & 68 deletions analytical_engine/core/fragment/dynamic_projected_fragment.h
Original file line number Diff line number Diff line change
Expand Up @@ -450,9 +450,9 @@ class DynamicProjectedFragment {
using vertex_t = typename fragment_t::vertex_t;
using vdata_t = VDATA_T;
using edata_t = EDATA_T;
using projected_adj_linked_list_t =
using adj_list_t =
dynamic_projected_fragment_impl::ProjectedAdjLinkedList<edata_t>;
using const_projected_adj_linked_list_t =
using const_adj_list_t =
dynamic_projected_fragment_impl::ConstProjectedAdjLinkedList<edata_t>;
using vertex_range_t = typename fragment_t::vertex_range_t;
template <typename DATA_T>
Expand Down Expand Up @@ -617,163 +617,151 @@ class DynamicProjectedFragment {
return fragment_->HasParent(v);
}

inline projected_adj_linked_list_t GetIncomingAdjList(const vertex_t& v) {
inline adj_list_t GetIncomingAdjList(const vertex_t& v) {
int32_t ie_pos;
if (fragment_->duplicated() && fragment_->IsOuterVertex(v)) {
ie_pos = fragment_->outer_ie_pos()[v.GetValue() - fragment_->ivnum()];
} else {
ie_pos = fragment_->inner_ie_pos()[v.GetValue()];
}
if (ie_pos == -1) {
return projected_adj_linked_list_t();
return adj_list_t();
}
return projected_adj_linked_list_t(
fragment_->id_mask(), fragment_->ivnum(), e_prop_key_,
fragment_->inner_edge_space()[ie_pos].begin(),
fragment_->inner_edge_space()[ie_pos].end());
return adj_list_t(fragment_->id_mask(), fragment_->ivnum(), e_prop_key_,
fragment_->inner_edge_space()[ie_pos].begin(),
fragment_->inner_edge_space()[ie_pos].end());
}

inline const_projected_adj_linked_list_t GetIncomingAdjList(
const vertex_t& v) const {
inline const_adj_list_t GetIncomingAdjList(const vertex_t& v) const {
int32_t ie_pos;
if (fragment_->duplicated() && fragment_->IsOuterVertex(v)) {
ie_pos = fragment_->outer_ie_pos()[v.GetValue() - fragment_->ivnum()];
} else {
ie_pos = fragment_->inner_ie_pos()[v.GetValue()];
}
if (ie_pos == -1) {
return const_projected_adj_linked_list_t();
return const_adj_list_t();
}
return const_projected_adj_linked_list_t(
fragment_->id_mask(), fragment_->ivnum(), e_prop_key_,
fragment_->inner_edge_space()[ie_pos].cbegin(),
fragment_->inner_edge_space()[ie_pos].cend());
return const_adj_list_t(fragment_->id_mask(), fragment_->ivnum(),
e_prop_key_,
fragment_->inner_edge_space()[ie_pos].cbegin(),
fragment_->inner_edge_space()[ie_pos].cend());
}

inline projected_adj_linked_list_t GetIncomingInnerVertexAdjList(
const vertex_t& v) {
inline adj_list_t GetIncomingInnerVertexAdjList(const vertex_t& v) {
auto ie_pos = fragment_->inner_ie_pos()[v.GetValue()];
if (ie_pos == -1) {
return projected_adj_linked_list_t();
return adj_list_t();
}
return projected_adj_linked_list_t(
fragment_->id_mask(), fragment_->ivnum(), e_prop_key_,
fragment_->inner_edge_space().InnerNbr(ie_pos).begin(),
fragment_->inner_edge_space().InnerNbr(ie_pos).end());
return adj_list_t(fragment_->id_mask(), fragment_->ivnum(), e_prop_key_,
fragment_->inner_edge_space().InnerNbr(ie_pos).begin(),
fragment_->inner_edge_space().InnerNbr(ie_pos).end());
}

inline const_projected_adj_linked_list_t GetIncomingInnerVertexAdjList(
inline const_adj_list_t GetIncomingInnerVertexAdjList(
const vertex_t& v) const {
auto ie_pos = fragment_->inner_ie_pos()[v.GetValue()];
if (ie_pos == -1) {
return const_projected_adj_linked_list_t();
return const_adj_list_t();
}
return const_projected_adj_linked_list_t(
return const_adj_list_t(
fragment_->id_mask(), fragment_->ivnum(), e_prop_key_,
fragment_->inner_edge_space().InnerNbr(ie_pos).cbegin(),
fragment_->inner_edge_space().InnerNbr(ie_pos).cend());
}

inline projected_adj_linked_list_t GetIncomingOuterVertexAdjList(
const vertex_t& v) {
inline adj_list_t GetIncomingOuterVertexAdjList(const vertex_t& v) {
auto ie_pos = fragment_->inner_ie_pos()[v.GetValue()];
if (ie_pos == -1) {
return projected_adj_linked_list_t();
return adj_list_t();
}
return projected_adj_linked_list_t(
fragment_->id_mask(), fragment_->ivnum(), e_prop_key_,
fragment_->inner_edge_space().OuterNbr(ie_pos).begin(),
fragment_->inner_edge_space().OuterNbr(ie_pos).end());
return adj_list_t(fragment_->id_mask(), fragment_->ivnum(), e_prop_key_,
fragment_->inner_edge_space().OuterNbr(ie_pos).begin(),
fragment_->inner_edge_space().OuterNbr(ie_pos).end());
}

inline const_projected_adj_linked_list_t GetIncomingOuterVertexAdjList(
inline const_adj_list_t GetIncomingOuterVertexAdjList(
const vertex_t& v) const {
auto ie_pos = fragment_->inner_ie_pos()[v.GetValue()];
if (ie_pos == -1) {
return const_projected_adj_linked_list_t();
return const_adj_list_t();
}
return const_projected_adj_linked_list_t(
return const_adj_list_t(
fragment_->id_mask(), fragment_->ivnum(), e_prop_key_,
fragment_->inner_edge_space().OuterNbr(ie_pos).cbegin(),
fragment_->inner_edge_space().OuterNbr(ie_pos).cend());
}

inline projected_adj_linked_list_t GetOutgoingAdjList(const vertex_t& v) {
inline adj_list_t GetOutgoingAdjList(const vertex_t& v) {
int32_t oe_pos;
if (fragment_->duplicated() && fragment_->IsOuterVertex(v)) {
oe_pos = fragment_->outer_oe_pos()[v.GetValue() - fragment_->ivnum()];
} else {
oe_pos = fragment_->inner_oe_pos()[v.GetValue()];
}
if (oe_pos == -1) {
return projected_adj_linked_list_t();
return adj_list_t();
}
return projected_adj_linked_list_t(
fragment_->id_mask(), fragment_->ivnum(), e_prop_key_,
fragment_->inner_edge_space()[oe_pos].begin(),
fragment_->inner_edge_space()[oe_pos].end());
return adj_list_t(fragment_->id_mask(), fragment_->ivnum(), e_prop_key_,
fragment_->inner_edge_space()[oe_pos].begin(),
fragment_->inner_edge_space()[oe_pos].end());
}

inline const_projected_adj_linked_list_t GetOutgoingAdjList(
const vertex_t& v) const {
inline const_adj_list_t GetOutgoingAdjList(const vertex_t& v) const {
int32_t oe_pos;
if (fragment_->duplicated() && fragment_->IsOuterVertex(v)) {
oe_pos = fragment_->outer_oe_pos()[v.GetValue() - fragment_->ivnum()];
} else {
oe_pos = fragment_->inner_oe_pos()[v.GetValue()];
}
if (oe_pos == -1) {
return const_projected_adj_linked_list_t();
return const_adj_list_t();
}
return const_projected_adj_linked_list_t(
fragment_->id_mask(), fragment_->ivnum(), e_prop_key_,
fragment_->inner_edge_space()[oe_pos].cbegin(),
fragment_->inner_edge_space()[oe_pos].cend());
return const_adj_list_t(fragment_->id_mask(), fragment_->ivnum(),
e_prop_key_,
fragment_->inner_edge_space()[oe_pos].cbegin(),
fragment_->inner_edge_space()[oe_pos].cend());
}

inline projected_adj_linked_list_t GetOutgoingInnerVertexAdjList(
const vertex_t& v) {
inline adj_list_t GetOutgoingInnerVertexAdjList(const vertex_t& v) {
auto oe_pos = fragment_->inner_oe_pos()[v.GetValue()];
if (oe_pos == -1) {
return projected_adj_linked_list_t();
return adj_list_t();
}
return projected_adj_linked_list_t(
fragment_->id_mask(), fragment_->ivnum(), e_prop_key_,
fragment_->inner_edge_space().InnerNbr(oe_pos).begin(),
fragment_->inner_edge_space().InnerNbr(oe_pos).end());
return adj_list_t(fragment_->id_mask(), fragment_->ivnum(), e_prop_key_,
fragment_->inner_edge_space().InnerNbr(oe_pos).begin(),
fragment_->inner_edge_space().InnerNbr(oe_pos).end());
}

inline const_projected_adj_linked_list_t GetOutgoingInnerVertexAdjList(
inline const_adj_list_t GetOutgoingInnerVertexAdjList(
const vertex_t& v) const {
auto oe_pos = fragment_->inner_oe_pos()[v.GetValue()];
if (oe_pos == -1) {
return const_projected_adj_linked_list_t();
return const_adj_list_t();
}
return const_projected_adj_linked_list_t(
return const_adj_list_t(
fragment_->id_mask(), fragment_->ivnum(), e_prop_key_,
fragment_->inner_edge_space().InnerNbr(oe_pos).cbegin(),
fragment_->inner_edge_space().InnerNbr(oe_pos).cend());
}

inline projected_adj_linked_list_t GetOutgoingOuterVertexAdjList(
const vertex_t& v) {
inline adj_list_t GetOutgoingOuterVertexAdjList(const vertex_t& v) {
auto oe_pos = fragment_->inner_oe_pos()[v.GetValue()];
if (oe_pos == -1) {
return projected_adj_linked_list_t();
return adj_list_t();
}
return projected_adj_linked_list_t(
fragment_->id_mask(), fragment_->ivnum(), e_prop_key_,
fragment_->inner_edge_space().OuterNbr(oe_pos).begin(),
fragment_->inner_edge_space().OuterNbr(oe_pos).end());
return adj_list_t(fragment_->id_mask(), fragment_->ivnum(), e_prop_key_,
fragment_->inner_edge_space().OuterNbr(oe_pos).begin(),
fragment_->inner_edge_space().OuterNbr(oe_pos).end());
}

inline const_projected_adj_linked_list_t GetOutgoingOuterVertexAdjList(
inline const_adj_list_t GetOutgoingOuterVertexAdjList(
const vertex_t& v) const {
auto oe_pos = fragment_->inner_oe_pos()[v.GetValue()];
if (oe_pos == -1) {
return const_projected_adj_linked_list_t();
return const_adj_list_t();
}
return const_projected_adj_linked_list_t(
return const_adj_list_t(
fragment_->id_mask(), fragment_->ivnum(), e_prop_key_,
fragment_->inner_edge_space().OuterNbr(oe_pos).cbegin(),
fragment_->inner_edge_space().OuterNbr(oe_pos).cend());
Expand Down
4 changes: 2 additions & 2 deletions analytical_engine/test/app_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -345,8 +345,8 @@ declare -a apps=(

# these algorithms need to check with directed flag
declare -a apps_with_directed=(
"katz"
"eigenvector"
# "katz"
# "eigenvector"
"degree_centrality"
"clustering"
)
Expand Down

0 comments on commit 76d4641

Please sign in to comment.