Skip to content

Commit

Permalink
Merge pull request #169 from kandeeban15/master
Browse files Browse the repository at this point in the history
Update Python Version to 3.11.3
  • Loading branch information
miyurud authored Aug 10, 2023
2 parents 645b2db + 890e668 commit 0112710
Show file tree
Hide file tree
Showing 24 changed files with 186 additions and 118 deletions.
10 changes: 5 additions & 5 deletions CMakeLists.txt
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ add_executable(JasmineGraph main.cpp src/server/JasmineGraphServer.cpp src/serve
src/frontend/core/factory/ExecutorFactory.cpp src/frontend/core/factory/ExecutorFactory.h src/frontend/core/CoreConstants.cpp
src/frontend/core/CoreConstants.h)

target_compile_options(JasmineGraph PRIVATE -std=c++11 -I/usr/include/python3.5)
target_compile_options(JasmineGraph PRIVATE -std=c++11 -I/usr/include/python3.11)

if(CMAKE_ENABLE_DEBUG)
message(STATUS "DEBUG enabled")
Expand All @@ -58,11 +58,11 @@ target_link_libraries(JasmineGraph /usr/lib/x86_64-linux-gnu/libflatbuffers.a)
target_link_libraries(JasmineGraph /usr/lib/x86_64-linux-gnu/libjsoncpp.a)
target_link_libraries(JasmineGraph /usr/local/lib/libcppkafka.so)

set(PYTHON_EXECUTABLE "/usr/bin/python3.5")
set(PYTHON_INCLUDE_DIR "/usr/include/python3.5m")
set(PYTHON_LIBRARIES "/usr/lib/x86_64-linux-gnu/libpython3.5m.so")
set(PYTHON_EXECUTABLE "/usr/bin/python3.11")
set(PYTHON_INCLUDE_DIR "/usr/include/python3.11m")
set(PYTHON_LIBRARIES "/usr/lib/x86_64-linux-gnu/libpython3.11.so")

include_directories(${PYTHON_INCLUDE_DIRS})
include_directories(${PYTHON_DIRECTORIES})
target_link_libraries(JasmineGraph ${PYTHON_LIBRARIES})
target_link_libraries(JasmineGraph m)
target_link_libraries(JasmineGraph m)
13 changes: 8 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@ RUN apt-get update
RUN apt-get install --no-install-recommends -y apt-transport-https
RUN apt-get update
RUN apt-get install --no-install-recommends -y curl gnupg2 ca-certificates software-properties-common nlohmann-json3-dev
RUN apt-get install --no-install-recommends -y git cmake build-essential sqlite3 libsqlite3-dev libssl-dev librdkafka-dev libboost-all-dev libtool libxerces-c-dev libflatbuffers-dev python3-pip

RUN apt-get install --no-install-recommends -y git cmake build-essential sqlite3 libsqlite3-dev libssl-dev librdkafka-dev libboost-all-dev libtool libxerces-c-dev libflatbuffers-dev
RUN add-apt-repository ppa:deadsnakes/ppa
RUN apt-get install --no-install-recommends -y python3.5-dev
RUN apt-get install --no-install-recommends -y python3.11-dev
RUN curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
RUN apt-get install --no-install-recommends -y libjsoncpp-dev libspdlog-dev pigz
RUN python3.11 get-pip.py

RUN curl -fsSL https://download.docker.com/linux/debian/gpg | apt-key add -
RUN add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
Expand Down Expand Up @@ -38,10 +41,10 @@ ENV JASMINEGRAPH_HOME="/home/ubuntu/software/jasminegraph"
RUN mkdir /home/ubuntu/software/jasminegraph
WORKDIR /home/ubuntu/software/jasminegraph

RUN pip install tensorflow==2.5.3
RUN pip install -U scikit-learn
COPY ./GraphSAGE ./GraphSAGE
RUN pip install -r ./GraphSAGE/requirements
RUN pip install joblib
RUN pip install threadpoolctl

COPY ./conf ./conf
COPY ./src ./src
Expand All @@ -54,4 +57,4 @@ COPY ./run-docker.sh ./run-docker.sh

RUN sh build.sh
ENTRYPOINT ["/home/ubuntu/software/jasminegraph/run-docker.sh"]
CMD ["bash"]
CMD ["bash"]
4 changes: 3 additions & 1 deletion GraphSAGE/graphsage/aggregators.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import tensorflow as tf
import tensorflow.compat.v1 as tf

from layers import Layer, Dense
from inits import glorot, zeros

tf.disable_v2_behavior()

class MeanAggregator(Layer):
"""
Aggregates via mean followed by matmul and non-linearity.
Expand Down
4 changes: 3 additions & 1 deletion GraphSAGE/graphsage/inits.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import tensorflow as tf
import tensorflow.compat.v1 as tf
import numpy as np

tf.disable_v2_behavior()

# DISCLAIMER:
# Parts of this code file are derived from
# https://github.com/tkipf/gcn
Expand Down
3 changes: 2 additions & 1 deletion GraphSAGE/graphsage/layers.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from __future__ import division
from __future__ import print_function

import tensorflow as tf
import tensorflow.compat.v1 as tf

from inits import zeros

tf.disable_v2_behavior()
flags = tf.app.flags
FLAGS = flags.FLAGS

Expand Down
3 changes: 2 additions & 1 deletion GraphSAGE/graphsage/metrics.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import tensorflow as tf
import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()

# DISCLAIMER:
# Parts of this code file were originally forked from
Expand Down
42 changes: 21 additions & 21 deletions GraphSAGE/graphsage/minibatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ def __init__(self, G, G_local,id2idx,
**kwargs):

self.G = G
self.nodes = G.nodes()
self.nodes = list(G.nodes())
self.local_nodes = G_local.nodes()
self.central_nodes = list(set(G.nodes())-set(G_local.nodes()))
self.central_nodes = list(set(list(G.nodes()))-set(G_local.nodes()))
self.id2idx = id2idx
self.placeholders = placeholders
self.batch_size = batch_size
self.max_degree = max_degree
self.batch_num = 0

self.nodes = np.random.permutation(G.nodes())
self.nodes = np.random.permutation(list(G.nodes()))
self.adj, self.deg = self.construct_adj()
self.test_adj = self.construct_test_adj()
if context_pairs is None:
Expand All @@ -52,12 +52,12 @@ def __init__(self, G, G_local,id2idx,
else:
self.train_edges = self.val_edges = self.edges

print(len([n for n in G.nodes() if not G.node[n]['test'] and not G.node[n]['val']]), 'train nodes')
print(len([n for n in G.nodes() if G.node[n]['test'] or G.node[n]['val']]), 'test nodes')
print(len([n for n in list(G.nodes()) if not G.nodes[n]['test'] and not G.nodes[n]['val']]), 'train nodes')
print(len([n for n in list(G.nodes()) if G.nodes[n]['test'] or G.nodes[n]['val']]), 'test nodes')
self.val_set_size = len(self.val_edges)

def _n2v_prune(self, edges):
is_val = lambda n : self.G.node[n]["val"] or self.G.node[n]["test"]
is_val = lambda n : self.G.nodes[n]["val"] or self.G.nodes[n]["test"]
return [e for e in edges if not is_val(e[1])]

def _remove_isolated(self, edge_list):
Expand All @@ -67,11 +67,11 @@ def _remove_isolated(self, edge_list):
count = 0
for n1, n2 in edge_list:
count +=1
if not n1 in self.G.node or not n2 in self.G.node:
if not n1 in list(self.G.nodes()) or not n2 in list(self.G.nodes()):
missing += 1
continue
if (self.G.node[n1]['test'] and self.G.node[n2]['test']) \
or (self.G.node[n1]['val'] and self.G.node[n2]['val']):
if (self.G.nodes[n1]['test'] and self.G.nodes[n2]['test']) \
or (self.G.nodes[n1]['val'] and self.G.nodes[n2]['val']):
continue
else:
new_edge_list.append((n1,n2))
Expand All @@ -82,8 +82,8 @@ def construct_adj(self):
adj = len(self.id2idx)*np.ones((len(self.id2idx)+1, self.max_degree))
deg = np.zeros((len(self.id2idx),))

for nodeid in self.G.nodes():
if self.G.node[nodeid]['test'] or self.G.node[nodeid]['val']:
for nodeid in list(self.G.nodes()):
if self.G.nodes[nodeid]['test'] or self.G.nodes[nodeid]['val']:
continue
neighbors = np.array([self.id2idx[neighbor]
for neighbor in self.G.neighbors(nodeid)
Expand All @@ -100,7 +100,7 @@ def construct_adj(self):

def construct_test_adj(self):
adj = len(self.id2idx)*np.ones((len(self.id2idx)+1, self.max_degree))
for nodeid in self.G.nodes():
for nodeid in list(self.G.nodes()):
neighbors = np.array([self.id2idx[neighbor]
for neighbor in self.G.neighbors(nodeid)])
if len(neighbors) == 0:
Expand Down Expand Up @@ -183,8 +183,8 @@ def label_val(self):
train_edges = []
val_edges = []
for n1, n2 in self.G.edges():
if (self.G.node[n1]['val'] or self.G.node[n1]['test']
or self.G.node[n2]['val'] or self.G.node[n2]['test']):
if (self.G.nodes[n1]['val'] or self.G.nodes[n1]['test']
or self.G.nodes[n2]['val'] or self.G.nodes[n2]['test']):
val_edges.append((n1,n2))
else:
train_edges.append((n1,n2))
Expand Down Expand Up @@ -217,7 +217,7 @@ def __init__(self, G, id2idx,
**kwargs):

self.G = G
self.nodes = G.nodes()
self.nodes = list(G.nodes())
self.id2idx = id2idx
self.placeholders = placeholders
self.batch_size = batch_size
Expand All @@ -229,11 +229,11 @@ def __init__(self, G, id2idx,
self.adj, self.deg = self.construct_adj()
self.test_adj = self.construct_test_adj()

self.val_nodes = [n for n in self.G.nodes() if self.G.node[n]['val']]
self.test_nodes = [n for n in self.G.nodes() if self.G.node[n]['test']]
self.val_nodes = [n for n in list(self.G.nodes()) if self.G.nodes[n]['val']]
self.test_nodes = [n for n in list(self.G.nodes()) if self.G.nodes[n]['test']]

self.no_train_nodes_set = set(self.val_nodes + self.test_nodes)
self.train_nodes = set(G.nodes()).difference(self.no_train_nodes_set)
self.train_nodes = set(list(G.nodes())).difference(self.no_train_nodes_set)
# don't train on nodes that only have edges to test set
self.train_nodes = [n for n in self.train_nodes if self.deg[id2idx[n]] > 0]

Expand All @@ -251,8 +251,8 @@ def construct_adj(self):
adj = len(self.id2idx)*np.ones((len(self.id2idx)+1, self.max_degree))
deg = np.zeros((len(self.id2idx),))

for nodeid in self.G.nodes():
if self.G.node[nodeid]['test'] or self.G.node[nodeid]['val']:
for nodeid in list(self.G.nodes()):
if self.G.nodes[nodeid]['test'] or self.G.nodes[nodeid]['val']:
continue
neighbors = np.array([self.id2idx[neighbor]
for neighbor in self.G.neighbors(nodeid)
Expand All @@ -269,7 +269,7 @@ def construct_adj(self):

def construct_test_adj(self):
adj = len(self.id2idx)*np.ones((len(self.id2idx)+1, self.max_degree))
for nodeid in self.G.nodes():
for nodeid in list(self.G.nodes()):
neighbors = np.array([self.id2idx[neighbor]
for neighbor in self.G.neighbors(nodeid)])
if len(neighbors) == 0:
Expand Down
3 changes: 2 additions & 1 deletion GraphSAGE/graphsage/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from collections import namedtuple

import tensorflow as tf
import tensorflow.compat.v1 as tf
import math

import layers as layers
Expand All @@ -9,6 +9,7 @@
from prediction import BipartiteEdgePredLayer
from aggregators import MeanAggregator, MaxPoolingAggregator, MeanPoolingAggregator, SeqAggregator, GCNAggregator

tf.disable_v2_behavior()
flags = tf.app.flags
FLAGS = flags.FLAGS

Expand Down
3 changes: 2 additions & 1 deletion GraphSAGE/graphsage/neigh_samplers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

from layers import Layer

import tensorflow as tf
import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()
flags = tf.app.flags
FLAGS = flags.FLAGS

Expand Down
3 changes: 2 additions & 1 deletion GraphSAGE/graphsage/prediction.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@

from inits import zeros
from layers import Layer
import tensorflow as tf
import tensorflow.compat.v1 as tf

tf.disable_v2_behavior()
flags = tf.app.flags
FLAGS = flags.FLAGS

Expand Down
3 changes: 2 additions & 1 deletion GraphSAGE/graphsage/supervised_models.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import tensorflow as tf
import tensorflow.compat.v1 as tf

import models as models
import layers as layers
from aggregators import MeanAggregator, MaxPoolingAggregator, MeanPoolingAggregator, SeqAggregator, GCNAggregator

tf.disable_v2_behavior()
flags = tf.app.flags
FLAGS = flags.FLAGS

Expand Down
5 changes: 3 additions & 2 deletions GraphSAGE/graphsage/supervised_train.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import os
import time
import tensorflow as tf
import tensorflow.compat.v1 as tf
import numpy as np
import sklearn
from sklearn import metrics
Expand All @@ -16,6 +16,7 @@

os.environ["CUDA_DEVICE_ORDER"]="PCI_BUS_ID"

tf.disable_v2_behavior()
# Set random seed
seed = 123
np.random.seed(seed)
Expand All @@ -25,7 +26,7 @@
flags = tf.app.flags
FLAGS = flags.FLAGS

tf.app.flags.DEFINE_boolean('log_device_placement', False,
flags.DEFINE_boolean('log_device_placement', False,
"""Whether to log device placement.""")
#core params..
flags.DEFINE_string('model', 'graphsage_mean', 'model names. See README for possible values.')
Expand Down
16 changes: 9 additions & 7 deletions GraphSAGE/graphsage/unsupervised_train.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import os
import time
import tensorflow as tf
import tensorflow.compat.v1 as tf
import numpy as np
import datetime

Expand All @@ -14,16 +14,18 @@

os.environ["CUDA_DEVICE_ORDER"]="PCI_BUS_ID"

tf.disable_v2_behavior()

# Set random seed
seed = 123
np.random.seed(seed)
tf.set_random_seed(seed)
tf.random.set_random_seed(seed)

# Settings
flags = tf.app.flags
FLAGS = flags.FLAGS

tf.app.flags.DEFINE_boolean('log_device_placement', False,
flags.DEFINE_boolean('log_device_placement', False,
"""Whether to log device placement.""")
#core params..
flags.DEFINE_string('model', 'graphsage_mean', 'model names. See README for possible values.')
Expand Down Expand Up @@ -66,7 +68,7 @@

def log_dir():

log_dir = FLAGS.base_log_dir + "/jasminegraph-local_trained_model_store/"
log_dir = FLAGS.base_log_dir + "jasminegraph-local_trained_model_store/"
log_dir += "{graph_id:s}_model_{train_worker:s}".format(
graph_id = FLAGS.train_prefix.split("/")[-1],
train_worker = FLAGS.train_worker
Expand Down Expand Up @@ -414,9 +416,9 @@ def train(train_data, G_local,test_data=None):

if FLAGS.model == "n2v":
# stopping the gradient for the already trained nodes
train_ids = tf.constant([[id_map[n]] for n in G.nodes_iter() if not G.node[n]['val'] and not G.node[n]['test']],
train_ids = tf.constant([[id_map[n]] for n in G.nodes_iter() if not G._node[n]['val'] and not G._node[n]['test']],
dtype=tf.int32)
test_ids = tf.constant([[id_map[n]] for n in G.nodes_iter() if G.node[n]['val'] or G.node[n]['test']],
test_ids = tf.constant([[id_map[n]] for n in G.nodes_iter() if G._node[n]['val'] or G._node[n]['test']],
dtype=tf.int32)
update_nodes = tf.nn.embedding_lookup(model.context_embeds, tf.squeeze(test_ids))
no_update_nodes = tf.nn.embedding_lookup(model.context_embeds,tf.squeeze(train_ids))
Expand All @@ -427,7 +429,7 @@ def train(train_data, G_local,test_data=None):

# run random walks
from graphsage.utils import run_random_walks
nodes = [n for n in G.nodes_iter() if G.node[n]["val"] or G.node[n]["test"]]
nodes = [n for n in G.nodes_iter() if G._node[n]["val"] or G._node[n]["test"]]
start_time = time.time()
pairs = run_random_walks(G, nodes, num_walks=50)
walk_time = time.time() - start_time
Expand Down
Loading

0 comments on commit 0112710

Please sign in to comment.