Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend python_extra_deps to depend on Python version #1137

Merged
merged 9 commits into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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/wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ jobs:
${CI_PYBIN} -m pip --version
${CI_PYBIN} -m pip install --upgrade setuptools
${CI_PYBIN} -m pip install --upgrade -r requirements.txt -q
source ./open_spiel/scripts/python_extra_deps.sh
source ./open_spiel/scripts/python_extra_deps.sh ${CI_PYBIN}
${CI_PYBIN} -m pip install --no-cache-dir --upgrade $OPEN_SPIEL_PYTHON_JAX_DEPS
${CI_PYBIN} -m pip install --no-cache-dir --upgrade $OPEN_SPIEL_PYTHON_PYTORCH_DEPS
${CI_PYBIN} -m pip install --no-cache-dir --upgrade $OPEN_SPIEL_PYTHON_TENSORFLOW_DEPS
Expand Down
36 changes: 17 additions & 19 deletions open_spiel/python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -265,14 +265,13 @@ set(PYTHON_TESTS ${PYTHON_TESTS}
# Add Jax tests if it is enabled.
if (OPEN_SPIEL_ENABLE_JAX)
set (PYTHON_TESTS ${PYTHON_TESTS}
# Disable JAX tests temporarily
#jax/deep_cfr_jax_test.py
#jax/dqn_jax_test.py
#jax/nfsp_jax_test.py
#jax/opponent_shaping_jax_test.py
#jax/policy_gradient_jax_test.py
#algorithms/rnad/rnad_test.py
#mfg/algorithms/fictitious_play_test.py
jax/deep_cfr_jax_test.py
jax/dqn_jax_test.py
jax/nfsp_jax_test.py
jax/opponent_shaping_jax_test.py
jax/policy_gradient_jax_test.py
algorithms/rnad/rnad_test.py
mfg/algorithms/fictitious_play_test.py
)
endif()

Expand Down Expand Up @@ -367,15 +366,14 @@ 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 AND NOT OPEN_SPIEL_BUILDING_WHEEL)
# Disable JAX tests temporarily
#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)
#set_property(TEST python_examples_bridge_supervised_learning
# PROPERTY ENVIRONMENT
# PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}:${CMAKE_CURRENT_SOURCE_DIR}/../..;
# TEST_SRCDIR=${CMAKE_CURRENT_SOURCE_DIR}/../..)
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)
set_property(TEST python_examples_bridge_supervised_learning
PROPERTY ENVIRONMENT
PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}:${CMAKE_CURRENT_SOURCE_DIR}/../..;
TEST_SRCDIR=${CMAKE_CURRENT_SOURCE_DIR}/../..)
endif()
2 changes: 1 addition & 1 deletion open_spiel/scripts/ci_script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ PYBIN=${PYBIN:-"python"}
PYBIN=${PYBIN:-"python3"}
PYBIN=`which $PYBIN`

source ./open_spiel/scripts/python_extra_deps.sh
source ./open_spiel/scripts/python_extra_deps.sh $PYBIN

${PYBIN} -m pip install --upgrade pip
${PYBIN} -m pip install --upgrade setuptools
Expand Down
3 changes: 3 additions & 0 deletions open_spiel/scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,9 @@ if [[ "$OSTYPE" == "linux-gnu" ]]; then
PYTHON_PKGS="python3-dev python3-pip python3-setuptools python3-wheel python3-tk python3-venv"
if [[ "$OS_PYTHON_VERSION" == "3.11" ]]; then
# Need to special-case this until it's installed by default.
# https://vegastack.com/tutorials/how-to-install-python-3-11-on-ubuntu-22-04/
echo "Adding Python 3.11 ppa repos"
sudo add-apt-repository ppa:deadsnakes/ppa
PYTHON_PKGS="python3.11 python3.11-dev python3-pip python3-setuptools python3-wheel python3-tk python3.11-venv"
fi
EXT_DEPS="virtualenv clang cmake curl $PYTHON_PKGS"
Expand Down
48 changes: 45 additions & 3 deletions open_spiel/scripts/python_extra_deps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,49 @@
#
# To enable specific tests, please use the environment variables found in
# scripts/global_variables.sh
export OPEN_SPIEL_PYTHON_JAX_DEPS="jax==0.4.6 jaxlib==0.4.6 dm-haiku==0.0.10 optax==0.1.7 chex==0.1.7 rlax==0.1.5 distrax==0.1.3"

# This script depends on the Python version, which it gets from $PYBIN or
# $CI_PYBIN passed in as $1. If it's not defined, Python 3.9 is assumed.

PY_VER="3.9"
if [ "$1" != "" ]; then
PY_VER=`$1 --version | awk '{print $2}'`
if [ "$PY_VER" = "" ]; then
PY_VER="3.9"
fi
fi

verlte() {
stuff=`echo -e "$1\n$2" | sort -V | head -n1`
[ "$1" = "$stuff" ]
}

verlt() {
[ "$1" = "$2" ] && return 1 || verlte $1 $2
}

#
# Python extra deps that work across all supported versions
#
export OPEN_SPIEL_PYTHON_PYTORCH_DEPS="torch==1.13.1"
export OPEN_SPIEL_PYTHON_TENSORFLOW_DEPS="numpy==1.23.5 tensorflow==2.13.1 tensorflow-probability==0.19.0 tensorflow_datasets==4.9.2 keras==2.13.1"
export OPEN_SPIEL_PYTHON_MISC_DEPS="IPython==5.8.0 networkx==2.4 matplotlib==3.5.2 mock==4.0.2 nashpy==0.0.19 scipy==1.10.1 testresources==2.0.1 cvxopt==1.3.1 cvxpy==1.2.0 ecos==2.0.10 osqp==0.6.2.post5 clu==0.0.6 flax==0.5.3"


#
# Python-version dependent versions
#

echo "Set Python version: $PY_VER"
if verlt $PY_VER 3.10; then
echo "Python < 3.10 detected"
export OPEN_SPIEL_PYTHON_JAX_DEPS="jax==0.4.6 jaxlib==0.4.6 dm-haiku==0.0.10 optax==0.1.7 chex==0.1.7 rlax==0.1.5 distrax==0.1.3"
export OPEN_SPIEL_PYTHON_TENSORFLOW_DEPS="numpy==1.23.5 tensorflow==2.13.1 tensorflow-probability==0.19.0 tensorflow_datasets==4.9.2 keras==2.13.1"
export OPEN_SPIEL_PYTHON_MISC_DEPS="IPython==5.8.0 networkx==2.4 matplotlib==3.5.2 mock==4.0.2 nashpy==0.0.19 scipy==1.10.1 testresources==2.0.1 cvxopt==1.3.1 cvxpy==1.2.0 ecos==2.0.10 osqp==0.6.2.post5 clu==0.0.6 flax==0.5.3"
else
echo "Python >= 3.10 detected"
export OPEN_SPIEL_PYTHON_JAX_DEPS="jax==0.4.20 jaxlib==0.4.20 dm-haiku==0.0.10 optax==0.1.7 chex==0.1.84 rlax==0.1.6 distrax==0.1.4"
export OPEN_SPIEL_PYTHON_TENSORFLOW_DEPS="numpy==1.26.1 tensorflow==2.14.0 tensorflow-probability==0.22.1 tensorflow_datasets==4.9.2 keras==2.14.0"
export OPEN_SPIEL_PYTHON_MISC_DEPS="IPython==5.8.0 networkx==3.2 matplotlib==3.5.2 mock==4.0.2 nashpy==0.0.19 scipy==1.11.3 testresources==2.0.1 cvxopt==1.3.1 cvxpy==1.4.1 ecos==2.0.10 osqp==0.6.2.post5 clu==0.0.6 flax==0.5.3"
fi



2 changes: 1 addition & 1 deletion open_spiel/scripts/test_wheel.sh
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ $PYBIN -m pip install --upgrade -r $PROJDIR/requirements.txt -q

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