快速入门

本指南将帮助您快速上手在本地机器上使用GraphScope进行图交互任务。

安装

GIE作为GraphScope的核心组件运行。因此,您需要先安装GraphScope才能使用GIE。

GraphScope需要以下软件版本:

  • Python 3.9 ~ 3.11

  • JDK 11 (JDK 8和20版本均存在已知兼容性问题)

  • gcc 7.1+ 或 Apple Clang

并且已在以下64位操作系统上进行测试:

  • Ubuntu 18.04 或更高版本

  • CentOS 7 或更高版本

  • macOS 12(Intel/Apple silicon)或更高版本,支持Intel芯片和Apple M1芯片

如果您的环境满足上述要求,您可以通过pip轻松安装GraphScope:

python3 -m pip install graphscope --upgrade

提示

如果下载速度非常慢,可以尝试使用pip的镜像站点。

python3 -m pip install graphscope --upgrade \
    -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host=mirrors.aliyun.com

然而,GraphScope对某些软件包有特定版本要求,因此在安装过程中可能会遇到冲突和错误。为此,我们强烈建议您在Python 3.9的纯净虚拟环境中安装GraphScope

我们建议您参考官方指南了解Python虚拟环境,以下是逐步操作说明:

# Create a new virtual environment
python3.9 -m venv tutorial-env
# Activate the virtual environment
source tutorial-env/bin/activate
# Install GraphScope
python3.9 -m pip install graphscope
# Use GraphScope
python3.9
>>> import graphscope as gs
>>> ......

在本地运行GraphScope交互式引擎

在本地机器上使用graphscope包运行交互式查询非常简单。首先,在Python会话中导入graphscope,然后加载modern图数据集,该数据集在Tinkerpop演示中被广泛使用。

import graphscope as gs
from graphscope.dataset.modern_graph import load_modern_graph

gs.set_option(show_log=True)

# load the modern graph as example.
graph = load_modern_graph()

# Hereafter, you can use the `graph` object to create an `interactive` query session
g = gs.interactive(graph)
# then `execute` any supported gremlin query (by default)
q1 = g.execute('g.V().count()')
print(q1.all().result())   # should print [6]

q2 = g.execute('g.V().hasLabel(\'person\')')
print(q2.all().result())  # should print [[v[2], v[3], v[0], v[1]]]

# or `execute` any supported Cypher query, by passing `lang="cypher"`
q3 = g.execute("MATCH (n) RETURN count(n)", lang="cypher")
print(q3.records[0][0])  # should print 6

您可能会看到类似的内容:

...
... [INFO][coordinator:453]: Built interactive frontend xxx.xxx.xxx.xxx:pppp for graph xxx
[6]
...
[v[2], v[3], v[0], v[1]]
...

打印的数字是6,这是modern图中的顶点数量。

为GIE实例自定义配置

您可以传递额外的键值对来自定义GIE的启动配置,例如:

# set total execution time for a query to 3000s
g = gs.interactive(graph, params={'query.execution.timeout.ms': 3000000})

下一步是什么

如上例所示,在本地机器上使用GraphScope通过Gremlin和Cypher查询语言进行交互式图查询非常简单。

除了上述本地机器入口外,我们还准备了以下主题供您参考。