Skip to content

Commit

Permalink
[Tutorial] Add sse tutorial & MXNet Tutorial CI (dmlc#252)
Browse files Browse the repository at this point in the history
* add sse tutorial

* add mxnet tutorial ci

* fix ci

* fix ci

* fix ci

* fix ci

* fix ci

* fix ci

* Fix ci

* Fix ci

* Fix ci

* fix ci

* fix ci

* fix ci

* fix ci

* fix ci

* fix ci

* Fix CI

Fix CI image

* permission fix

* fix a bug in the code.

* small fix

* fix doc

* fix ci

* shorten the iters

* fix

* remove extra file

* add load_backend api to dynamically switch to another backend

* try fix

* fix tutorial

* fix tutorial

* fix bug in tutorial
  • Loading branch information
VoVAllen authored and jermainewang committed Dec 5, 2018
1 parent f4a9a45 commit cd907cd
Show file tree
Hide file tree
Showing 10 changed files with 610 additions and 22 deletions.
29 changes: 23 additions & 6 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -40,27 +40,34 @@ def mxnet_unit_test(dev) {
def example_test(dev) {
withEnv(["DGL_LIBRARY_PATH=${env.WORKSPACE}/build", "PYTHONPATH=${env.WORKSPACE}/python"]) {
dir ("tests/scripts") {
sh "./task_example_test.sh ${dev}"
sh "bash task_example_test.sh ${dev}"
}
}
}

def pytorch_tutorials() {
withEnv(["DGL_LIBRARY_PATH=${env.WORKSPACE}/build", "PYTHONPATH=${env.WORKSPACE}/python"]) {
dir ("tests/scripts") {
sh "./task_tutorial_test.sh"
sh "bash task_pytorch_tutorial_test.sh"
}
}
}

def mxnet_tutorials() {
withEnv(["DGL_LIBRARY_PATH=${env.WORKSPACE}/build", "PYTHONPATH=${env.WORKSPACE}/python"]) {
dir("tests/scripts") {
sh "bash task_mxnet_tutorial_test.sh"
}
}
}
pipeline {
agent none
stages {
stage("Lint Check") {
agent { docker { image "dgllib/dgl-ci-lint" } }
steps {
init_git_submodule()
sh "tests/scripts/task_lint.sh"
sh "bash tests/scripts/task_lint.sh"
}
}
stage("Build") {
Expand Down Expand Up @@ -144,9 +151,19 @@ pipeline {
}
}
stage("Doc") {
agent { docker { image "dgllib/dgl-ci-cpu" } }
steps {
pytorch_tutorials()
parallel {
stage("TH Tutorial") {
agent { docker { image "dgllib/dgl-ci-cpu" } }
steps {
pytorch_tutorials()
}
}
stage("MX Tutorial") {
agent { docker { image "dgllib/dgl-ci-mxnet-cpu" } }
steps {
mxnet_tutorials()
}
}
}
}
}
Expand Down
11 changes: 3 additions & 8 deletions docs/source/api/python/sampler.rst
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
.. apisampler
Sampling subgraphs from a large graph
=====================================
Graph samplers
==============

.. currentmodule:: dgl.contrib.sampling

NeighborSampler
---------------

A function that generates a subgraph loader for sampling subgraphs.
.. autofunction:: dgl.contrib.sampling.sampler.NeighborSampler
2 changes: 1 addition & 1 deletion python/dgl/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from . import backend
# One has to manually import dgl.data; fixes #125
#from . import data
from . import function
Expand All @@ -10,6 +9,7 @@
from ._ffi.base import DGLError, __version__

from .base import ALL
from .backend import load_backend
from .batched_graph import *
from .graph import DGLGraph
from .subgraph import DGLSubGraph
Expand Down
8 changes: 5 additions & 3 deletions python/dgl/backend/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ def _missing_api(*args, **kwargs):
' the DGLBACKEND environment.' % (api, mod_name))
return _missing_api

def _load_backend():
mod_name = os.environ.get('DGLBACKEND', 'pytorch').lower()
def load_backend(mod_name):
mod = importlib.import_module('.%s' % mod_name, __name__)
thismod = sys.modules[__name__]
for api in backend.__dict__.keys():
if api.startswith('__'):
# ignore python builtin attributes
continue
if api == 'data_type_dict':
# load data type
if api not in mod.__dict__:
Expand All @@ -41,7 +43,7 @@ def _load_backend():
else:
setattr(thismod, api, _gen_missing_api(api, mod_name))

_load_backend()
load_backend(os.environ.get('DGLBACKEND', 'pytorch').lower())

def is_enabled(api):
"""Return true if the api is enabled by the current backend.
Expand Down
8 changes: 6 additions & 2 deletions python/dgl/contrib/sampling/sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,11 @@ def NeighborSampler(g, batch_size, expand_factor, num_hops=1,
neighbor_type='in', node_prob=None, seed_nodes=None,
shuffle=False, num_workers=1, max_subgraph_size=None,
return_seed_id=False):
'''
'''Create a sampler that samples neighborhood.
.. note:: This method currently only supports MXNet backend. Set
"DGLBACKEND" environment variable to "mxnet".
This creates a subgraph data loader that samples subgraphs from the input graph
with neighbor sampling. This simpling method is implemented in C and can perform
sampling very efficiently.
Expand Down Expand Up @@ -127,7 +131,7 @@ def NeighborSampler(g, batch_size, expand_factor, num_hops=1,
Returns
-------
A subgraph loader that returns a list of batched subgraphs and a dictionary of
additional infomration about the subgraphs.
additional information about the subgraphs.
'''
return NSSubgraphLoader(g, batch_size, expand_factor, num_hops, neighbor_type, node_prob,
seed_nodes, shuffle, num_workers, max_subgraph_size, return_seed_id)
Empty file modified tests/scripts/task_example_test.sh
100755 → 100644
Empty file.
2 changes: 1 addition & 1 deletion tests/scripts/task_lint.sh
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
#!/bin/bash

# cpplint
echo 'Checking code style of C++ codes...'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pip3 install -r requirements.txt || fail "installing requirements"

# Test
export MPLBACKEND=Agg
for f in $(find . -name "*.py")
for f in $(find . -name "*_mx.py")
do
echo "Running tutorial ${f} ..."
python3 $f || fail "run ${f}"
Expand Down
23 changes: 23 additions & 0 deletions tests/scripts/task_pytorch_tutorial_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash
# The working directory for this script will be "tests/scripts"

TUTORIAL_ROOT="../../tutorials"

function fail {
echo FAIL: $@
exit -1
}

pushd ${TUTORIAL_ROOT} > /dev/null
# Install requirements
pip3 install -r requirements.txt || fail "installing requirements"

# Test
export MPLBACKEND=Agg
for f in $(find . -name "*.py" ! -name "*_mx.py")
do
echo "Running tutorial ${f} ..."
python3 $f || fail "run ${f}"
done

popd > /dev/null
Loading

0 comments on commit cd907cd

Please sign in to comment.