Skip to content

Commit

Permalink
Enable Python side wrapper (#4)
Browse files Browse the repository at this point in the history
* enable python

* update

* run-test script
  • Loading branch information
hkvision authored and zhichao-li committed Mar 30, 2018
1 parent 652826f commit fb5cc12
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 25 deletions.
31 changes: 8 additions & 23 deletions pyzoo/dev/prepare_env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,37 +16,22 @@

SCRIPT_DIR=$(dirname ${BASH_SOURCE[0]})
echo "SCRIPT_DIR": $SCRIPT_DIR
export DL_PYTHON_HOME="$(cd ${SCRIPT_DIR}/../../; pwd)"
export DL_PYTHON_HOME="$(cd ${SCRIPT_DIR}/../; pwd)"

export BIGDL_HOME="$(cd ${SCRIPT_DIR}/../../..; pwd)"
export ZOO_HOME="$(cd ${SCRIPT_DIR}/../..; pwd)"

echo "BIGDL_HOME: $BIGDL_HOME"
echo "ZOO_HOME: $ZOO_HOME"
echo "SPARK_HOME": $SPARK_HOME
echo "DL_PYTHON_HOME": $DL_PYTHON_HOME

if [ -z ${SPARK_HOME+x} ]; then echo "SPARK_HOME is unset"; exit 1; else echo "SPARK_HOME is set to '$SPARK_HOME'"; fi

export PYSPARK_ZIP=`find $SPARK_HOME/python/lib -type f -iname '*.zip' | tr "\n" ":"`

export PYTHONPATH=$PYTHONPATH:$PYSPARK_ZIP:$DL_PYTHON_HOME:$DL_PYTHON_HOME/:$DL_PYTHON_HOME/test/dev:$BIGDL_HOME/spark/dl/src/main/resources/spark-bigdl.conf
export PYTHONPATH=$PYTHONPATH:$PYSPARK_ZIP:$DL_PYTHON_HOME:$DL_PYTHON_HOME/

export BIGDL_CLASSPATH=$(find $BIGDL_HOME/spark/dl/target/ -name "*with-dependencies.jar" | head -n 1)
echo "BIGDL_CLASSPATH": $BIGDL_CLASSPATH
export ZOO_CLASSPATH=$(find $ZOO_HOME/zoo/target/ -name "*with-dependencies.jar" | head -n 1)
echo "ZOO_CLASSPATH": $ZOO_CLASSPATH

if [[ ($SPARK_HOME == *"2.2.0"*) || ($SPARK_HOME == *"2.1.1"*) || ($SPARK_HOME == *"1.6.4"*) ]]; then
export PYTHON_EXECUTABLES=("python2.7" "python3.5" "python3.6")
else
export PYTHON_EXECUTABLES=("python2.7" "python3.5")
fi

function run_notebook() {
notebook_path=$1
target_notebook_path=${DL_PYTHON_HOME}/tmp_${PYTHON_EXECUTABLE}.ipynb
echo "Change kernel to $PYTHON_EXECUTABLE"
sed "s/\"python.\"/\"$PYTHON_EXECUTABLE\"/g" $notebook_path > ${target_notebook_path}
jupyter nbconvert --to notebook --execute \
--ExecutePreprocessor.timeout=360 --output ${DL_PYTHON_HOME}/tmp_out.ipynb \
$target_notebook_path
}

export -f run_notebook
export BIGDL_CLASSPATH=$ZOO_CLASSPATH
echo "BIGDL_CLASSPATH": $BIGDL_CLASSPATH
33 changes: 33 additions & 0 deletions pyzoo/test/dev/run-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env bash

#
# Copyright 2016 The BigDL Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

SCRIPT_DIR=$(dirname ${BASH_SOURCE[0]})

ENV_SCRIPT_DIR="$(cd ${SCRIPT_DIR}/../../dev/; pwd)"

. $ENV_SCRIPT_DIR/prepare_env.sh

cd "`dirname $0`"

python -m pytest -v --doctest-modules ../../../pyzoo/zoo \

exit_status=$?
if [ $exit_status -ne 0 ];
then
exit $exit_status
fi
19 changes: 19 additions & 0 deletions pyzoo/zoo/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#
# Copyright 2018 The Zoo Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

from bigdl.util.common import JavaCreator

JavaCreator.add_creator_class("com.intel.analytics.zoo.pipeline.api.keras.python.PythonZooKeras")
5 changes: 3 additions & 2 deletions pyzoo/zoo/pipeline/api/keras/layers/layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,22 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#

from bigdl.nn.keras.layer import *

if sys.version >= '3':
long = int
unicode = str


class KerasCreator(JavaValue):
class ZooKerasLayer(KerasLayer):
def jvm_class_constructor(self):
name = "createZooKeras" + self.__class__.__name__
print("creating: " + name)
return name


class Dense(KerasLayer):
class Dense(ZooKerasLayer):
"""
A densely-connected NN layer.
The most common input is 2D.
Expand Down

0 comments on commit fb5cc12

Please sign in to comment.