test_redis_graph.py 1.1 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
#!/usr/bin/env python
# -*- coding: utf-8 -*-
########################################################################
#
# Copyright (c) 2019 Baidu.com, Inc. All Rights Reserved
#
# File: test_redis_graph.py
# Author: suweiyue(suweiyue@baidu.com)
# Date: 2019/08/19 16:28:18
#
########################################################################
"""
    Comment.
"""
from __future__ import division
from __future__ import absolute_import
from __future__ import print_function
from __future__ import unicode_literals

import sys

import numpy as np
import tqdm
from pgl.redis_graph import RedisGraph

if __name__ == '__main__':
    host, port = sys.argv[1].split(':')
    port = int(port)
    redis_configs = [{"host": host, "port": port}, ]
    graph = RedisGraph("reddit-graph", redis_configs, num_parts=64)
    #nodes = np.arange(0, 100)
    #for i in range(0, 100):
    for l in tqdm.tqdm(sys.stdin):
        l_sp = l.rstrip().split('\t')
        if len(l_sp) != 2:
            continue
        i, j = int(l_sp[0]), int(l_sp[1])
        nodes = graph.sample_predecessor(np.array([i]), 10000)
        assert j in nodes