Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
5fb0d4a
Add cibuildwheel workflow and pip bdist_wheel tests
lanctot May 10, 2021
294686c
Fix typo and missing env. var
lanctot May 10, 2021
a313ad4
Fix typo in travis_script
lanctot May 10, 2021
b979374
Fix typo
lanctot May 10, 2021
f4c464e
Use pip3 directly when under virtualenv (travis)
lanctot May 10, 2021
9dc12b7
Install extra deps in wheel env
lanctot May 10, 2021
8035a71
Add missing __init__.py for python/jax
lanctot May 10, 2021
1df4bf4
Merge branch 'master' into lanctot_cibuildwheel
lanctot Jun 6, 2021
3aff252
Update python CMakeLists for full tests names
lanctot Jun 7, 2021
5f6ebf8
Merge branch 'master' into lanctot_cibuildwheel
lanctot Jul 6, 2021
09d71da
Make workflow manually triggered
lanctot Jul 6, 2021
b98f232
Update wheels.yml
lanctot Jul 6, 2021
6f47e18
Update wheels.yml
lanctot Jul 6, 2021
ed59146
Add min MacOS version compile flag
lanctot Jul 6, 2021
dfe55ea
Add MacOS flag in CMakeLists
lanctot Jul 6, 2021
6874da2
Upgrade cibuildwheel version.
lanctot Jul 6, 2021
7b14ff7
Remove MacOS 10.15 requirement, after pybind11 PR #3077
lanctot Jul 12, 2021
761a317
Try testing via CIBW_TEST_COMMAND
lanctot Aug 3, 2021
444143d
Comment out line to test syntax issue
lanctot Aug 3, 2021
90d4a8a
Move line up one
lanctot Aug 3, 2021
ad2b603
Try escaping the curly braces
lanctot Aug 3, 2021
2f5e001
Merge branch 'master' into lanctot_cibuildwheel
lanctot Aug 3, 2021
e1a5f2b
Try test command with regular braces
lanctot Aug 3, 2021
11b97c9
Add bash prefix to command
lanctot Aug 3, 2021
83d2bb4
Add missing link to directory containing requirements.txt
lanctot Aug 3, 2021
e5a460c
Add two modes for testing wheels (full vs. basic)
lanctot Aug 3, 2021
d23880e
Fix typo for full mode
lanctot Aug 3, 2021
df4083c
Specify builds for only x86_64
lanctot Aug 3, 2021
8a02f55
Rename wheel workflow items
lanctot Aug 3, 2021
b6a7212
Move to 2.0.1 + other fixes from @henryiii comments
lanctot Aug 3, 2021
6f98102
Add comments to wheels.yml
lanctot Aug 3, 2021
5a77be2
Change wheel filename for install
lanctot Aug 4, 2021
f871136
Applying changes from internal review by @jblespiau
lanctot Aug 9, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,4 @@ jobs:
- name: Build and test
run: |
python3 --version
./open_spiel/scripts/travis_script.sh
./open_spiel/scripts/ci_script.sh
96 changes: 96 additions & 0 deletions .github/workflows/wheels.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# Builds and tests the OpenSpiel wheels using cibuildwheel.
#
# Each wheel is built via the manylinux2014 pypa Docker image on Linux and
# standard MacOS X on 10.15. Each binary wheel is built only for x86_64. Basic
# API tests are run within the Docker environment that built the wheel. Full
# tests (tests that use extra dependencies such as PyTorch, JAX, Tensorflow)
# are tested in the Github Actions CI environment (Ubuntu 20.04 and Mac OS
# 10.15).
name: wheels

on:
# Test the wheels for each PR to ensure the PR doesn't break them.
pull_request:
branches: [ master ]
# Workflow dispatch is a way to manually trigger workflows. This will be
# used to build and test the wheels manually for releases.
workflow_dispatch:
inputs:
name:
description: 'Workflow dispatch (triggered manually)'
required: false
default: 'No name specified'

jobs:
build_wheels:
name: Build wheels on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
- os: ubuntu-20.04
CIBW_ENVIRONMENT: "CXX=$(which g++) OPEN_SPIEL_BUILDING_WHEEL='ON' OPEN_SPIEL_BUILD_WITH_ACPC='ON' OPEN_SPIEL_BUILD_WITH_HANABI='ON'"
CIBW_BUILD: cp36-manylinux_x86_64 cp37-manylinux_x86_64 cp38-manylinux_x86_64 cp39-manylinux_x86_64
- os: macOS-10.15
CIBW_ENVIRONMENT: "OPEN_SPIEL_BUILDING_WHEEL='ON' OPEN_SPIEL_BUILD_WITH_ACPC='ON' OPEN_SPIEL_BUILD_WITH_HANABI='ON'"
CIBW_BUILD: cp36-macosx_x86_64 cp37-macosx_x86_64 cp38-macosx_x86_64 cp39-macosx_x86_64
env:
OPEN_SPIEL_BUILDING_WHEEL: ON
OPEN_SPIEL_BUILD_WITH_ACPC: ON
OPEN_SPIEL_BUILD_WITH_HANABI: ON
OS_PYTHON_VERSION: 3.9
CIBW_MANYLINUX_X86_64_IMAGE: manylinux2014
CIBW_BUILD: ${{ matrix.CIBW_BUILD }}
CIBW_SKIP: cp27-* pp*
CIBW_BEFORE_BUILD: python -m pip install --upgrade cmake
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These should be specified in pyproject.toml normally, then everyone who builds this from an SDist will benefit. Though I see you are running .install.sh and ./open_spiel/scripts/python_extra_deps.sh - at least for Python, the environment is isolated, you will not be using things installed via pip inside the wheel build process. It's not even running on the same version of Python that you are running cibuildwheel with.

Now it might be picking up build produces from the environment, but those must be done inside CIBW_BEFORE_ALL or tool.cibuildwheel.before-all (TOML). For example, on Linux, these are built on the host rather than in the docker container if you run them in a step.

CIBW_BEFORE_TEST: python -m pip install --upgrade pip
CIBW_TEST_COMMAND: /bin/bash {project}/open_spiel/scripts/test_wheel.sh basic {project}
CIBW_ENVIRONMENT: ${{ matrix.CIBW_ENVIRONMENT }}

steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2

- name: Install
run: |
pwd
uname -a
which python
which g++
g++ --version
python --version
chmod +x install.sh
# This is needed to grab OpenSpiel dependencies.
./install.sh
# These are necessary to install what is necessary for the build and for the full tests below.
python -m pip install --upgrade pip
python -m pip --version
python -m pip install --upgrade setuptools
python -m pip install --upgrade -r requirements.txt -q
source ./open_spiel/scripts/python_extra_deps.sh
python -m pip install --upgrade $OPEN_SPIEL_PYTHON_JAX_DEPS $OPEN_SPIEL_PYTHON_PYTORCH_DEPS $OPEN_SPIEL_PYTHON_TENSORFLOW_DEPS $OPEN_SPIEL_PYTHON_MISC_DEPS
python -m pip install twine
python -m pip install cibuildwheel==2.0.1
- name: Build sdist
run: |
pipx run build --sdist
twine check dist/*.tar.gz

# Build all the wheels and run the basic tests (within the docker images)
# Basic tests are run via the CIBW_TEST_COMMAND environment variable.
- name: Build bdist_wheel and run tests
run: |
python -m cibuildwheel --output-dir wheelhouse
ls -l wheelhouse

# Install the built wheel and run the full tests on this host. The full
# tests include all the ones that use the machine learning libraries,
# such as Tensorflow, PyTorch, and JAX.
- name: Install bdist_wheel and full tests
run: ./open_spiel/scripts/test_wheel.sh full `pwd`

- uses: actions/upload-artifact@v2
with:
path: |
dist/*.tar.gz
./wheelhouse/*.whl
3 changes: 3 additions & 0 deletions open_spiel/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ openspiel_optional_dependency(OPEN_SPIEL_ENABLE_TENSORFLOW AUTO
openspiel_optional_dependency(OPEN_SPIEL_ENABLE_PYTHON_MISC OFF
"Enable miscellaneous Python dependencies.")

openspiel_optional_dependency(OPEN_SPIEL_BUILDING_WHEEL OFF
"Building a Python wheel?")


# Needed to disable Abseil tests.
set (BUILD_TESTING OFF)
Expand Down
50 changes: 37 additions & 13 deletions open_spiel/python/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
find_package(Python3 COMPONENTS Interpreter Development)
if (OPEN_SPIEL_BUILDING_WHEEL)
# When building a wheel, need to use this. See:
# https://github.com/joerick/cibuildwheel/issues/639#issuecomment-817872369
message(NOTICE "Building Wheel Detected. Finding Python Interpeter Development.Module")
find_package(Python3 COMPONENTS Interpreter Development.Module REQUIRED)
# find_package(Python3 COMPONENTS Interpreter Development)
unset(OPEN_SPIEL_PYTHONPATH)
if(DEFINED ENV{PYTHONPATH})
set (OPEN_SPIEL_PYTHONPATH $ENV{PYTHONPATH})
endif()
else()
message(NOTICE "Not building wheel. Finding Python normally...")
find_package(Python3 COMPONENTS Interpreter Development)
set(OPEN_SPIEL_PYTHONPATH ${CMAKE_CURRENT_BINARY_DIR}:${CMAKE_CURRENT_SOURCE_DIR}/../..;)
endif()

message(NOTICE "Python executable: ${Python3_EXECUTABLE}")
message(NOTICE "Python include dirs: ${Python3_INCLUDE_DIRS}")
include_directories(SYSTEM ${Python3_INCLUDE_DIRS})
Expand Down Expand Up @@ -257,29 +272,38 @@ if (OPEN_SPIEL_ENABLE_PYTHON_MISC)
)
endif()

# Create python tests.
# Tests that are excluded when running via the installed wheel.
# Some bundle data not shipped with the wheel (e.g. playthroughs)
set(WHEEL_EXCLUDED_PYTHON_TESTS
algorithms/response_graph_ucb_test.py
games/tic_tac_toe_test.py
../integration_tests/playthrough_test.py)

# Create a python test.
foreach(py_test_file IN LISTS PYTHON_TESTS)
add_test(NAME ${py_test_file} COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/${py_test_file})
if (NOT (OPEN_SPIEL_BUILDING_WHEEL AND ${py_test_file} IN_LIST WHEEL_EXCLUDED_PYTHON_TESTS))
add_test(NAME python/${py_test_file} COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/${py_test_file})

# We need two elements in the python path: CURRENT_BINARY_DIR to pick up
# pyspiel.so, and CURRENT_SOURCE_DIR for the Python source files. We use
# CURRENT_SOURCE_DIR/../.. so that the Python module imports are of the form:
# from open_spiel.python import rl_environment.
set_property(TEST ${py_test_file}
PROPERTY ENVIRONMENT
PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}:${CMAKE_CURRENT_SOURCE_DIR}/../..;
TEST_SRCDIR=${CMAKE_CURRENT_SOURCE_DIR}/../..)
# We need two elements in the python path: CURRENT_BINARY_DIR to pick up
# pyspiel.so, and CURRENT_SOURCE_DIR for the Python source files. We use
# CURRENT_SOURCE_DIR/../.. so that the Python module imports are of the form:
# from open_spiel.python import rl_environment.
set_property(TEST python/${py_test_file}
PROPERTY ENVIRONMENT
PYTHONPATH=${OPEN_SPIEL_PYTHONPATH}
TEST_SRCDIR=${CMAKE_CURRENT_SOURCE_DIR}/../..)
endif()
endforeach(py_test_file)

# Additional tests (running examples as tests)
# We don't generate these automatically because we may want custom parameters.
if (OPEN_SPIEL_ENABLE_JAX)
if (OPEN_SPIEL_ENABLE_JAX AND NOT OPEN_SPIEL_BUILDING_WHEEL)
add_test(NAME python_examples_bridge_supervised_learning
COMMAND ${Python3_EXECUTABLE}
${CMAKE_CURRENT_SOURCE_DIR}/examples/bridge_supervised_learning.py
--iterations 10
--eval_every 5
--data_path ${CMAKE_CURRENT_SOURCE_DIR}/examples/data/bridge)
--data_path ${CMAKE_CURRENT_SOURCE_DIR}/examples/data/bridge)
set_property(TEST python_examples_bridge_supervised_learning
PROPERTY ENVIRONMENT
PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}:${CMAKE_CURRENT_SOURCE_DIR}/../..;
Expand Down
15 changes: 15 additions & 0 deletions open_spiel/python/jax/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright 2019 DeepMind Technologies Ltd. All rights reserved.
#
# 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.


Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,16 @@ if [[ "$OS" = "Linux" && "$OS_PYTHON_VERSION" = "3.9" ]]; then
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.9 1
fi

source ./open_spiel/scripts/python_extra_deps.sh
PYBIN=${PYBIN:-"python3"}
PYBIN=`which $PYBIN`

sudo -H pip3 install --upgrade pip
sudo -H pip3 install --upgrade setuptools

if [ ! $TRAVIS_USE_NOX -eq 0 ]; then
# Build and run tests using nox
[[ "$OPEN_SPIEL_ENABLE_JAX" = "ON" ]] && sudo -H pip3 install --upgrade $OPEN_SPIEL_PYTHON_JAX_DEPS
[[ "$OPEN_SPIEL_ENABLE_PYTORCH" = "ON" ]] && sudo -H pip3 install --upgrade $OPEN_SPIEL_PYTHON_PYTORCH_DEPS
[[ "$OPEN_SPIEL_ENABLE_TENSORFLOW" = "ON" ]] && sudo -H pip3 install --upgrade $OPEN_SPIEL_PYTHON_TENSORFLOW_DEPS
[[ "$OPEN_SPIEL_ENABLE_PYTHON_MISC" = "ON" ]] && sudo -H pip3 install --upgrade $OPEN_SPIEL_PYTHON_MISC_DEPS
sudo -H pip3 install nox
PWD=`pwd` # normally defined, but just in case!
PYTHONPATH="$PYTHONPATH:$PWD:$PWD/build:$PWD/build/python" nox -s tests
exit 0
fi
source ./open_spiel/scripts/python_extra_deps.sh

sudo -H pip3 install --force-reinstall virtualenv==20.0.23
${PYBIN} -m pip install --upgrade pip
${PYBIN} -m pip install --upgrade setuptools
${PYBIN} -m pip install --force-reinstall virtualenv==20.0.23

virtualenv -p python3 ./venv
virtualenv -p ${PYBIN} ./venv
source ./venv/bin/activate

python3 --version
Expand Down
78 changes: 78 additions & 0 deletions open_spiel/scripts/test_wheel.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#!/bin/bash

# Copyright 2019 DeepMind Technologies Ltd. All rights reserved.
#
# 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.

# This file is called by the wheels workflow .github/workflows/wheels.yml.
set -e
set -x

if [ "$2" = "" ];
then
echo "Usage: test_wheel <mode (full|basic)> <project main dir>"
echo ""
echo "Basic mode tests only the python functionaly (no ML libraries)"
echo "Full mode installs the extra ML libraries and the wheel. (requires Python >= 3.7 for JAX)."
exit -1
fi

MODE=$1
PROJDIR=$2

uname -a

OS=`uname -a | awk '{print $1}'`
if [[ "$MODE" = "full" && "$OS" = "Linux" && "$OS_PYTHON_VERSION" = "3.9" ]]; then
echo "Linux detected and Python 3.9 requested. Installing Python 3.9 and setting as default."
sudo apt-get install python3.9 python3.9-dev
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.9 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.9 1
fi

PYBIN=${PYBIN:-"python"}
PYBIN=`which $PYBIN`

$PYBIN -m pip install --upgrade setuptools
$PYBIN -m pip install --upgrade -r $PROJDIR/requirements.txt -q

if [[ "$MODE" = "full" ]]; then
echo "Full mode. Installing ML libraries."
source $PROJDIR/open_spiel/scripts/python_extra_deps.sh
$PYBIN -m pip install --upgrade $OPEN_SPIEL_PYTHON_JAX_DEPS $OPEN_SPIEL_PYTHON_PYTORCH_DEPS $OPEN_SPIEL_PYTHON_TENSORFLOW_DEPS $OPEN_SPIEL_PYTHON_MISC_DEPS
fi

if [[ "$MODE" = "full" ]]; then
if [[ "$OS" = "Linux" ]]; then
${PYBIN} -m pip install wheelhouse/open_spiel-*-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
else
${PYBIN} -m pip install wheelhouse/open_spiel-*-cp39-cp39-macosx_10_9_x86_64.whl
fi
fi

export OPEN_SPIEL_BUILDING_WHEEL="ON"
export OPEN_SPIEL_BUILD_WITH_HANABI="ON"
export OPEN_SPIEL_BUILD_WITH_ACPC="ON"

rm -rf build && mkdir build && cd build
cmake -DPython3_EXECUTABLE=${PYBIN} $PROJDIR/open_spiel

NPROC="nproc"
if [[ "$OS" == "darwin"* ]]; then
NPROC="sysctl -n hw.physicalcpu"
fi

MAKE_NUM_PROCS=$(${NPROC})
let TEST_NUM_PROCS=4*${MAKE_NUM_PROCS}

ctest -j$TEST_NUM_PROCS --output-on-failure -R "^python/*" ../open_spiel