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

Enable perfect hash support in GAE #2959

Merged
merged 1 commit into from
Jul 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions analytical_engine/core/fragment/arrow_projected_fragment.h
Original file line number Diff line number Diff line change
Expand Up @@ -1542,6 +1542,8 @@ class ArrowProjectedFragment

bool compact_edges() const { return fragment_->compact_edges(); }

bool use_perfect_hash() const { return vm_ptr_->use_perfect_hash(); }

private:
/**
* @brief For edges (indicated by nbr_list[begin:end)) of a given vertex,
Expand Down
13 changes: 9 additions & 4 deletions analytical_engine/core/io/property_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,17 +128,19 @@ class Edge {
struct Graph {
std::vector<std::shared_ptr<Vertex>> vertices;
std::vector<std::shared_ptr<Edge>> edges;
bool directed;
bool generate_eid;
bool retain_oid;
bool compact_edges;
bool directed = true;
bool generate_eid = true;
bool retain_oid = true;
bool compact_edges = false;
bool use_perfect_hash = false;

std::string SerializeToString() const {
std::stringstream ss;
ss << "directed: " << directed << "\n";
ss << "generate_eid: " << generate_eid << "\n";
ss << "retain_oid: " << retain_oid << "\n";
ss << "compact_edges: " << compact_edges << "\n";
ss << "use_perfect_hash: " << use_perfect_hash << "\n";
for (auto& v : vertices) {
ss << v->SerializeToString();
}
Expand Down Expand Up @@ -285,12 +287,15 @@ inline bl::result<std::shared_ptr<detail::Graph>> ParseCreatePropertyGraph(
BOOST_LEAF_AUTO(generate_eid, params.Get<bool>(rpc::GENERATE_EID));
BOOST_LEAF_AUTO(retain_oid, params.Get<bool>(rpc::RETAIN_OID));
BOOST_LEAF_AUTO(compact_edges, params.Get<bool>(rpc::COMPACT_EDGES, false));
BOOST_LEAF_AUTO(use_perfect_hash,
params.Get<bool>(rpc::USE_PERFECT_HASH, false));

auto graph = std::make_shared<detail::Graph>();
graph->directed = directed;
graph->generate_eid = generate_eid;
graph->retain_oid = retain_oid;
graph->compact_edges = compact_edges;
graph->use_perfect_hash = use_perfect_hash;

const auto& large_attr = params.GetLargeAttr();
for (const auto& item : large_attr.chunk_list().items()) {
Expand Down
7 changes: 4 additions & 3 deletions analytical_engine/core/loader/arrow_fragment_loader.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,11 @@ class ArrowFragmentLoader : public vineyard::ArrowFragmentLoader<OID_T, VID_T> {
const std::vector<std::string>& efiles,
const std::vector<std::string>& vfiles,
bool directed = true, bool generate_eid = false,
bool retain_oid = false, bool compact_edges = false)
bool retain_oid = false, bool compact_edges = false,
bool use_perfect_hash = false)
: Base(client, comm_spec, efiles, vfiles, directed, generate_eid,
retain_oid, vineyard::is_local_vertex_map<vertex_map_t>::value,
compact_edges),
compact_edges, use_perfect_hash),
graph_info_(nullptr),
giraph_enabled_(false) {}

Expand All @@ -121,7 +122,7 @@ class ArrowFragmentLoader : public vineyard::ArrowFragmentLoader<OID_T, VID_T> {
std::vector<std::string>{}, graph_info->directed,
graph_info->generate_eid, graph_info->retain_oid,
vineyard::is_local_vertex_map<vertex_map_t>::value,
graph_info->compact_edges),
graph_info->compact_edges, graph_info->use_perfect_hash),
graph_info_(graph_info) {
#ifdef ENABLE_JAVA_SDK
// check when vformat or eformat start with giraph. if not, we
Expand Down
4 changes: 4 additions & 0 deletions analytical_engine/core/object/fragment_wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ inline void set_graph_def(
graph_def.set_directed(fragment->directed());
graph_def.set_is_multigraph(fragment->is_multigraph());
graph_def.set_compact_edges(fragment->compact_edges());
graph_def.set_use_perfect_hash(fragment->use_perfect_hash());

auto v_entries = schema.vertex_entries();
auto e_entries = schema.edge_entries();
Expand Down Expand Up @@ -336,6 +337,7 @@ class FragmentWrapper<

new_graph_def.set_key(dst_graph_name);
new_graph_def.set_compact_edges(new_frag->compact_edges());
new_graph_def.set_use_perfect_hash(new_frag->use_perfect_hash());

gs::rpc::graph::VineyardInfoPb vy_info;
if (graph_def_.has_extension()) {
Expand Down Expand Up @@ -541,6 +543,7 @@ class FragmentWrapper<
rpc::graph::GraphDefPb new_graph_def;
new_graph_def.set_key(dst_graph_name);
new_graph_def.set_compact_edges(new_frag->compact_edges());
new_graph_def.set_use_perfect_hash(new_frag->use_perfect_hash());
gs::rpc::graph::VineyardInfoPb vy_info;
if (graph_def_.has_extension()) {
graph_def_.extension().UnpackTo(&vy_info);
Expand Down Expand Up @@ -706,6 +709,7 @@ class FragmentWrapper<

new_graph_def.set_key(dst_graph_name);
new_graph_def.set_compact_edges(new_frag->compact_edges());
new_graph_def.set_use_perfect_hash(new_frag->use_perfect_hash());

gs::rpc::graph::VineyardInfoPb vy_info;
if (graph_def_.has_extension()) {
Expand Down
3 changes: 3 additions & 0 deletions analytical_engine/core/server/graphscope_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,9 @@ ::grpc::Status GraphScopeService::RunStep(
graph_def.is_multigraph());
merged_graph_def.set_compact_edges(merged_graph_def.compact_edges() ||
graph_def.compact_edges());
merged_graph_def.set_use_perfect_hash(
merged_graph_def.use_perfect_hash() ||
graph_def.use_perfect_hash());
}
op_result->mutable_graph_def()->CopyFrom(merged_graph_def);
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ class ArrowProjectedVertexMap

fid_t GetFidFromGid(vid_t gid) const { return id_parser_.GetFid(gid); }

bool use_perfect_hash() const { return vertex_map_->use_perfect_hash(); }

private:
fid_t fnum_;
label_id_t label_num_;
Expand Down
4 changes: 4 additions & 0 deletions analytical_engine/frame/project_frame.cc
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ class ProjectSimpleFrame<gs::ArrowProjectedFragment<
graph_def.set_key(projected_graph_name);
graph_def.set_graph_type(rpc::graph::ARROW_PROJECTED);
graph_def.set_compact_edges(input_frag->compact_edges());
graph_def.set_use_perfect_hash(input_frag->use_perfect_hash());
gs::rpc::graph::VineyardInfoPb vy_info;
if (graph_def.has_extension()) {
graph_def.extension().UnpackTo(&vy_info);
Expand Down Expand Up @@ -116,6 +117,7 @@ class ProjectSimpleFrame<gs::ArrowProjectedFragment<

graph_def.set_directed(parent_meta.template GetKeyValue<bool>("directed_"));
graph_def.set_compact_edges(fragment->compact_edges());
graph_def.set_use_perfect_hash(fragment->use_perfect_hash());

gs::rpc::graph::VineyardInfoPb vy_info;
if (graph_def.has_extension()) {
Expand Down Expand Up @@ -186,6 +188,7 @@ class ProjectSimpleFrame<
graph_def.set_key(projected_graph_name);
graph_def.set_graph_type(rpc::graph::ARROW_FLATTENED);
graph_def.set_compact_edges(input_frag->compact_edges());
graph_def.set_use_perfect_hash(input_frag->use_perfect_hash());
gs::rpc::graph::VineyardInfoPb vy_info;
if (graph_def.has_extension()) {
graph_def.extension().UnpackTo(&vy_info);
Expand Down Expand Up @@ -235,6 +238,7 @@ class ProjectSimpleFrame<gs::DynamicProjectedFragment<VDATA_T, EDATA_T>> {
graph_def.set_key(projected_graph_name);
graph_def.set_graph_type(rpc::graph::DYNAMIC_PROJECTED);
graph_def.set_compact_edges(false);
graph_def.set_use_perfect_hash(false);
gs::rpc::graph::MutableGraphInfoPb graph_info;
if (graph_def.has_extension()) {
graph_def.extension().UnpackTo(&graph_info);
Expand Down
5 changes: 5 additions & 0 deletions analytical_engine/frame/property_graph_frame.cc
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ LoadGraph(const grape::CommSpec& comm_spec, vineyard::Client& client,

graph_def.set_key(graph_name);
graph_def.set_compact_edges(frag->compact_edges());
graph_def.set_use_perfect_hash(frag->use_perfect_hash());
gs::rpc::graph::VineyardInfoPb vy_info;
if (graph_def.has_extension()) {
graph_def.extension().UnpackTo(&vy_info);
Expand Down Expand Up @@ -160,6 +161,7 @@ LoadGraph(const grape::CommSpec& comm_spec, vineyard::Client& client,

graph_def.set_key(graph_name);
graph_def.set_compact_edges(frag->compact_edges());
graph_def.set_use_perfect_hash(frag->use_perfect_hash());

gs::rpc::graph::VineyardInfoPb vy_info;
if (graph_def.has_extension()) {
Expand Down Expand Up @@ -264,6 +266,7 @@ ToArrowFragment(vineyard::Client& client, const grape::CommSpec& comm_spec,
gs::rpc::graph::GraphDefPb graph_def;
graph_def.set_key(dst_graph_name);
graph_def.set_compact_edges(arrow_frag->compact_edges());
graph_def.set_use_perfect_hash(arrow_frag->use_perfect_hash());
gs::rpc::graph::VineyardInfoPb vy_info;
if (graph_def.has_extension()) {
graph_def.extension().UnpackTo(&vy_info);
Expand Down Expand Up @@ -310,6 +313,7 @@ ToDynamicFragment(const grape::CommSpec& comm_spec,
graph_def.set_directed(dynamic_frag->directed());
graph_def.set_graph_type(gs::rpc::graph::DYNAMIC_PROPERTY);
graph_def.set_compact_edges(false);
graph_def.set_use_perfect_hash(false);
gs::rpc::graph::MutableGraphInfoPb graph_info;
if (graph_def.has_extension()) {
graph_def.extension().UnpackTo(&graph_info);
Expand Down Expand Up @@ -354,6 +358,7 @@ AddLabelsToGraph(vineyard::ObjectID origin_frag_id,

graph_def.set_key(graph_name);
graph_def.set_compact_edges(frag->compact_edges());
graph_def.set_use_perfect_hash(frag->use_perfect_hash());

gs::rpc::graph::VineyardInfoPb vy_info;
if (graph_def.has_extension()) {
Expand Down
1 change: 1 addition & 0 deletions coordinator/gscoordinator/op_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,7 @@ def load_subgraph(
types_pb2.VID_TYPE: utils.s_to_attr("uint64_t"),
types_pb2.IS_FROM_VINEYARD_ID: utils.b_to_attr(False),
types_pb2.COMPACT_EDGES: utils.b_to_attr(False),
types_pb2.USE_PERFECT_HASH: utils.b_to_attr(False),
}
new_op = create_graph(
self._session_id,
Expand Down
2 changes: 1 addition & 1 deletion coordinator/setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ build-dir = docs/_build
all_files = 1

[upload_docs]
upload-dir = docs/_build/html
upload_dir = docs/_build/html

[isort]
ensure_newline_before_comments = True
Expand Down
28 changes: 17 additions & 11 deletions python/graphscope/client/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
import time
import uuid
import warnings
from typing import Any
from typing import Union

try:
import vineyard
Expand All @@ -52,7 +54,10 @@
from graphscope.deploy.hosts.cluster import HostsClusterLauncher
from graphscope.deploy.kubernetes.cluster import KubernetesClusterLauncher
from graphscope.deploy.kubernetes.utils import resolve_api_client
from graphscope.framework.app import App
from graphscope.framework.context import Context
from graphscope.framework.dag import Dag
from graphscope.framework.dag import DAGNode
from graphscope.framework.errors import FatalError
from graphscope.framework.errors import InvalidArgumentError
from graphscope.framework.errors import K8sError
Expand Down Expand Up @@ -945,7 +950,7 @@ def _unregister_default(self):
self._default_session.__exit__(None, None, None)
self._default_session = None

def _wrapper(self, dag_node):
def _wrapper(self, dag_node: DAGNode) -> Union[DAGNode, App, Context, Graph, Any]:
if self.eager():
return self.run(dag_node)
return dag_node
Expand Down Expand Up @@ -1251,15 +1256,13 @@ def g(
retain_oid=True,
vertex_map="global",
compact_edges=False,
):
use_perfect_hash=False,
) -> Union[Graph, GraphDAGNode]:
if (
isinstance(incoming_data, vineyard.ObjectID)
and repr(vineyard.ObjectID(incoming_data))
in self._vineyard_object_mapping_table
and repr(incoming_data) in self._vineyard_object_mapping_table
):
graph_vineyard_id = self._vineyard_object_mapping_table[
repr(vineyard.ObjectID(incoming_data))
]
graph_vineyard_id = self._vineyard_object_mapping_table[repr(incoming_data)]
logger.info("Restore graph from original graph: %s", graph_vineyard_id)
incoming_data = vineyard.ObjectID(graph_vineyard_id)
return self._wrapper(
Expand All @@ -1272,6 +1275,7 @@ def g(
retain_oid,
vertex_map,
compact_edges,
use_perfect_hash,
)
)

Expand Down Expand Up @@ -1629,12 +1633,12 @@ def default_session(session):
return _default_session_stack.get_controller(session)


def has_default_session():
def has_default_session() -> bool:
"""True if default session exists in current context."""
return not _default_session_stack.empty()


def get_default_session():
def get_default_session() -> Session:
"""Returns the default session for the current context.

Note that a new session will be created if there is no
Expand All @@ -1660,14 +1664,14 @@ def __init__(self):
super().__init__()
self.stack = []

def get_default(self):
def get_default(self) -> Session:
if not self.stack:
logger.info("Creating default session ...")
sess = session(cluster_type="hosts", num_workers=1)
sess.as_default()
return self.stack[-1]

def empty(self):
def empty(self) -> bool:
return len(self.stack) == 0

def reset(self):
Expand Down Expand Up @@ -1699,6 +1703,7 @@ def g(
retain_oid=True,
vertex_map="global",
compact_edges=False,
use_perfect_hash=False,
):
"""Construct a GraphScope graph object on the default session.

Expand Down Expand Up @@ -1729,6 +1734,7 @@ def g(
retain_oid,
vertex_map,
compact_edges,
use_perfect_hash,
)


Expand Down
7 changes: 7 additions & 0 deletions python/graphscope/framework/dag_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ def bind_app(graph, app_assets):
config[types_pb2.VERTEX_MAP_TYPE] = utils.i_to_attr(graph._vertex_map)
if hasattr(graph, "_compact_edges"):
config[types_pb2.COMPACT_EDGES] = utils.b_to_attr(graph._compact_edges)
if hasattr(graph, "_use_perfect_hash"):
config[types_pb2.USE_PERFECT_HASH] = utils.b_to_attr(graph._use_perfect_hash)
if app_assets.cmake_extra_options is not None:
config[types_pb2.CMAKE_EXTRA_OPTIONS] = utils.s_to_attr(
app_assets.cmake_extra_options
Expand Down Expand Up @@ -201,6 +203,7 @@ def add_labels_to_graph(graph, loader_op):
types_pb2.RETAIN_OID: utils.b_to_attr(graph._retain_oid),
types_pb2.VERTEX_MAP_TYPE: utils.i_to_attr(graph._vertex_map),
types_pb2.COMPACT_EDGES: utils.b_to_attr(graph._compact_edges),
types_pb2.USE_PERFECT_HASH: utils.b_to_attr(graph._use_perfect_hash),
types_pb2.VID_TYPE: utils.s_to_attr("uint64_t"),
types_pb2.IS_FROM_VINEYARD_ID: utils.b_to_attr(False),
types_pb2.IS_FROM_GAR: utils.b_to_attr(False),
Expand Down Expand Up @@ -436,6 +439,7 @@ def project_arrow_property_graph(graph, vertex_collections, edge_collections):
types_pb2.GRAPH_TYPE: utils.graph_type_to_attr(graph.graph_type),
types_pb2.VERTEX_MAP_TYPE: utils.i_to_attr(graph._vertex_map),
types_pb2.COMPACT_EDGES: utils.b_to_attr(graph._compact_edges),
types_pb2.USE_PERFECT_HASH: utils.b_to_attr(graph._use_perfect_hash),
}
config.update(
{
Expand Down Expand Up @@ -480,6 +484,8 @@ def project_to_simple(
config[types_pb2.VERTEX_MAP_TYPE] = utils.i_to_attr(graph._vertex_map)
if hasattr(graph, "_compact_edges"):
config[types_pb2.COMPACT_EDGES] = utils.b_to_attr(graph._compact_edges)
if hasattr(graph, "_use_perfect_hash"):
config[types_pb2.USE_PERFECT_HASH] = utils.b_to_attr(graph._use_perfect_hash)
op = Operation(
graph.session_id,
types_pb2.PROJECT_TO_SIMPLE,
Expand Down Expand Up @@ -1038,6 +1044,7 @@ def archive_graph(graph, path):
types_pb2.VID_TYPE: utils.s_to_attr("uint64_t"),
types_pb2.VERTEX_MAP_TYPE: utils.i_to_attr(graph._vertex_map),
types_pb2.COMPACT_EDGES: utils.b_to_attr(graph._compact_edges),
types_pb2.USE_PERFECT_HASH: utils.b_to_attr(graph._use_perfect_hash),
}
config[types_pb2.GRAPH_INFO_PATH] = utils.s_to_attr(path)
op = Operation(
Expand Down
Loading
Loading