{"id":23647087,"url":"https://github.com/wey-gu/nebula-dgl","last_synced_at":"2025-08-31T22:32:28.805Z","repository":{"id":46099259,"uuid":"512651598","full_name":"wey-gu/nebula-dgl","owner":"wey-gu","description":"NebulaGraph DGL(Deep Graph Library) Integration Package. (WIP)","archived":false,"fork":false,"pushed_at":"2024-03-14T11:05:26.000Z","size":89,"stargazers_count":37,"open_issues_count":8,"forks_count":3,"subscribers_count":4,"default_branch":"main","last_synced_at":"2024-12-20T12:48:10.778Z","etag":null,"topics":["dgl","gcn","gnn","graph-algorithms","graph-data","graph-neural-network","hacktoberfest","nebula-graph","nebulagraph","networkx"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wey-gu.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2022-07-11T07:08:30.000Z","updated_at":"2024-10-08T07:06:29.000Z","dependencies_parsed_at":"2024-03-14T12:26:38.287Z","dependency_job_id":"5b4bb9cc-51f7-4d22-965b-f673489532be","html_url":"https://github.com/wey-gu/nebula-dgl","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wey-gu%2Fnebula-dgl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wey-gu%2Fnebula-dgl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wey-gu%2Fnebula-dgl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wey-gu%2Fnebula-dgl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wey-gu","download_url":"https://codeload.github.com/wey-gu/nebula-dgl/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":231633141,"owners_count":18403402,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dgl","gcn","gnn","graph-algorithms","graph-data","graph-neural-network","hacktoberfest","nebula-graph","nebulagraph","networkx"],"created_at":"2024-12-28T13:49:18.634Z","updated_at":"2024-12-28T13:49:19.176Z","avatar_url":"https://github.com/wey-gu.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# nebula-dgl\n\n[![pdm-managed](https://img.shields.io/badge/pdm-managed-blueviolet)](https://pdm.fming.dev) [![License](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](LICENSE)\n\nnebula-dgl is the Lib for NebulaGraph integration with Deep Graph Library (DGL).\n\n\u003e nebula-dgl is still WIP, there is a demo project [here](https://github.com/wey-gu/NebulaGraph-Fraud-Detection-GNN/) .\n\n# Guide\n\n## Installation\n\n### Install from PyPi\n\n```bash\npython3 -m pip install nebula-dgl\npython3 -m pip install dgl dglgo -f https://data.dgl.ai/wheels/repo.html\n```\n\n### Install from codebase for dev\n```bash\npython3 -m pip install nebula3-python\npython3 -m pip install dgl dglgo -f https://data.dgl.ai/wheels/repo.html\n\n# build and install\npython3 -m pip install .\n```\n\n## Playground\n\nClone this repository to your local directory first.\n\n```bash\ngit clone https://github.com/wey-gu/nebula-dgl.git\ncd nebula-dgl\n```\n\n0. Deploy NebulaGraph playground with Nebula-UP:\n\nInstall NebulaGraph:\n\n```bash\ncurl -fsSL nebula-up.siwei.io/install.sh | bash\n```\n\nLoad example data:\n\n```bash\n~/.nebula-up/load-basketballplayer-dataset.sh\n```\n\n1. Create a jupyter notebook in same docker network: `nebula-net`\n\n```bash\ndocker run -it --name dgl -p 8888:8888 --network nebula-net \\\n    -v \"$PWD\":/home/jovyan/work jupyter/datascience-notebook \\\n    start-notebook.sh --NotebookApp.token='secret'\n```\nNow you can either:\n\n- access the notebook at http://localhost:8888/lab/tree/work?token=secret and create a new notebook.\n\nOr:\n\n- run ipython with the container:\n\n```bash\ndocker exec -it dgl ipython\ncd work\n```\n\n\n2. Install nebula-dgl in notebook:\n\nInstall nebula-dgl:\n\n```\n!python3 -m pip install python3 -m pip install nebula3-python==3.4.0\n!python3 -m pip install dgl dglgo -f https://data.dgl.ai/wheels/repo.html\n!python3 -m pip install .\n```\n\n3. Try with a homogeneous graph:\n\n```python\nimport yaml\nimport networkx as nx\n\nfrom nebula_dgl import NebulaLoader\n\n\nnebula_config = {\n    \"graph_hosts\": [\n                ('graphd', 9669),\n                ('graphd1', 9669),\n                ('graphd2', 9669)\n            ],\n    \"nebula_user\": \"root\",\n    \"nebula_password\": \"nebula\",\n}\n\n# scan loader(mostly for training)\n\nwith open('example/homogeneous_graph.yaml', 'r') as f:\n    feature_mapper = yaml.safe_load(f)\n\nnebula_loader = NebulaLoader(nebula_config, feature_mapper)\nhomo_dgl_graph = nebula_loader.load()\n\n# or query based(mostly for small graph when inference)\n\nquery = \"\"\"\nMATCH p=()-[:follow]-\u003e() RETURN p\n\"\"\"\nnebula_loader = NebulaLoader(nebula_config, feature_mapper, query=query, query_space=\"basketballplayer\")\nhomo_dgl_graph = nebula_loader.load()\n\nnx_g = homo_dgl_graph.to_networkx()\nnx.draw(nx_g, with_labels=True, pos=nx.spring_layout(nx_g))\n```\n\nResult:\n\n![nx_draw](https://user-images.githubusercontent.com/1651790/181154556-c25532f9-33ff-4cc8-85d9-62cb559d7f1a.png)\n\n4. Compute the degree centrality of the graph:\n\n```python\nnx.degree_centrality(nx_g)\n```\nResult:\n\n```python\n{0: 0.0,\n 1: 0.04,\n 2: 0.02,\n 3: 0.02,\n 4: 0.06,\n 5: 0.06,\n 6: 0.04,\n 7: 0.24,\n 8: 0.16,\n 9: 0.0,\n 10: 0.02,\n 11: 0.04,\n 12: 0.04,\n 13: 0.04,\n 14: 0.1,\n 15: 0.04,\n 16: 0.0,\n 17: 0.1,\n 18: 0.04,\n 19: 0.04,\n 20: 0.0,\n 21: 0.0,\n 22: 0.04,\n 23: 0.02,\n 24: 0.02,\n 25: 0.04,\n 26: 0.06,\n 27: 0.0,\n 28: 0.02,\n 29: 0.0,\n 30: 0.04,\n 31: 0.12,\n 32: 0.04,\n 33: 0.22,\n 34: 0.14,\n 35: 0.1,\n 36: 0.04,\n 37: 0.14,\n 38: 0.1,\n 39: 0.02,\n 40: 0.14,\n 41: 0.08,\n 42: 0.1,\n 43: 0.12,\n 44: 0.12,\n 45: 0.08,\n 46: 0.1,\n 47: 0.02,\n 48: 0.04,\n 49: 0.12,\n 50: 0.06}\n ```\n\n## NebulaGraph to DGL\n\n```python\nfrom nebula_dgl import NebulaLoader\n\n\nnebula_config = {\n    \"graph_hosts\": [\n                ('graphd', 9669),\n                ('graphd1', 9669),\n                ('graphd2', 9669)\n            ],\n    \"nebula_user\": \"root\",\n    \"nebula_password\": \"nebula\"\n}\n\n# load feature_mapper from yaml file\nwith open('example/nebula_to_dgl_mapper.yaml', 'r') as f:\n    feature_mapper = yaml.safe_load(f)\n\nnebula_loader = NebulaLoader(nebula_config, feature_mapper)\ndgl_graph = nebula_loader.load()\n\n```\n\n## Play homogeneous graph algorithms in networkx\n\n```python\n\nimport networkx\n\nwith open('example/homogeneous_graph.yaml', 'r') as f:\n    feature_mapper = yaml.safe_load(f)\n\nnebula_loader = NebulaLoader(nebula_config, feature_mapper)\nhomo_dgl_graph = nebula_loader.load()\nnx_g = homo_dgl_graph.to_networkx()\n\n# plot it\nnetworkx.draw(nx_g, with_lables=True)\n\n# get degree\nnetworkx.degree(nx_g)\n\n# get degree centrality\nnetworkx.degree_centrality(nx_g)\n```\n\n\n## Multi-Part Loader for NebulaGraph\n\n1. For now, the Multi-Part Loader is slow like sequence scan, need to profile the performance.\n\n```python\nimport yaml\nimport networkx as nx\nimport matplotlib.pyplot as plt\n\nfrom nebula_dgl import NebulaReducedLoader\n\n\nnebula_config = {\n    \"graph_hosts\": [\n                ('127.0.0.1', 9669)\n            ],\n    \"nebula_user\": \"root\",\n    \"nebula_password\": \"nebula\",\n}\n\nwith open('example/homogeneous_graph.yaml', 'r') as f:\n    feature_mapper = yaml.safe_load(f)\n\n# you only need change the following line: from NebulaLoader to NebulaReducedLoader\n# Easy for you to use the multi-part loader \nnebula_reduced_loader = NebulaReducedLoader(nebula_config, feature_mapper)\nhomo_dgl_graph = nebula_reduced_loader.load()\nnx_g = homo_dgl_graph.to_networkx()\nnx.draw(nx_g, with_labels=True, pos=nx.spring_layout(nx_g))\nplt.savefig(\"multi_graph.png\")\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwey-gu%2Fnebula-dgl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwey-gu%2Fnebula-dgl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwey-gu%2Fnebula-dgl/lists"}