MCPcopy Create free account
hub / github.com/alibaba/GraphScope / wrap_init

Function wrap_init

python/graphscope/analytical/udf/wrapper.py:29–70  ·  view source on GitHub ↗

Wrapper :code:`__init__` function in algo.

(
    algo, program_model, pyx_header, pyx_body, vd_type, md_type, pregel_combine
)

Source from the content-addressed store, hash-verified

27
28
29def wrap_init(
30 algo, program_model, pyx_header, pyx_body, vd_type, md_type, pregel_combine
31):
32 """Wrapper :code:`__init__` function in algo."""
33 algo_name = getattr(algo, "__name__")
34 module_name = algo_name + "_" + get_timestamp(with_milliseconds=False)
35
36 pyx_code = "\n\n".join(pyx_header.dump() + pyx_body.dump())
37 gs_config = {
38 "app": [
39 {
40 "algo": module_name,
41 "context_type": "labeled_vertex_data",
42 "type": (
43 "cython_pie"
44 if program_model == ProgramModel.PIE
45 else "cython_pregel"
46 ),
47 "class_name": "gs::PregelPropertyAppBase",
48 "compatible_graph": ["vineyard::ArrowFragment"],
49 "vd_type": vd_type,
50 "md_type": md_type,
51 "pregel_combine": pregel_combine,
52 }
53 ]
54 }
55
56 garfile = InMemoryZip()
57 garfile.append("{}.pyx".format(module_name), pyx_code)
58 garfile.append(".gs_conf.yaml", yaml.dump(gs_config))
59
60 def init(self):
61 pass
62
63 def call(self, graph, **kwargs):
64 app_assets = load_app(gar=garfile.read_bytes(), algo=module_name)
65 return app_assets(graph, **kwargs)
66
67 setattr(algo, "__decorated__", True) # can't decorate on a decorated class
68 setattr(algo, "_gar", garfile.read_bytes().getvalue())
69 setattr(algo, "__init__", init)
70 setattr(algo, "__call__", call)
71
72
73def pyx_codegen(

Callers 1

pyx_codegenFunction · 0.85

Calls 7

appendMethod · 0.95
read_bytesMethod · 0.95
get_timestampFunction · 0.90
InMemoryZipClass · 0.90
dumpMethod · 0.65
joinMethod · 0.45
formatMethod · 0.45

Tested by

no test coverage detected