diff --git a/.github/workflows/wheels.yml b/.github/workflows/wheels.yml index 177126ec4c..e1630aca07 100644 --- a/.github/workflows/wheels.yml +++ b/.github/workflows/wheels.yml @@ -28,26 +28,36 @@ jobs: strategy: matrix: include: - - os: ubuntu-20.04 + - os: ubuntu-22.04 OS_TYPE: "Linux" CI_PYBIN: python3 + OS_PYTHON_VERSION: 3.10 CIBW_ENVIRONMENT: "CXX=$(which g++) OPEN_SPIEL_BUILDING_WHEEL='ON' OPEN_SPIEL_BUILD_WITH_ACPC='ON' OPEN_SPIEL_BUILD_WITH_HANABI='ON' OPEN_SPIEL_BUILD_WITH_ROSHAMBO='ON'" CIBW_BUILD: cp38-manylinux_x86_64 cp39-manylinux_x86_64 cp310-manylinux_x86_64 cp311-manylinux_x86_64 cp312-manylinux_x86_64 - os: macOS-12 OS_TYPE: "Darwin" CI_PYBIN: python3.9 + OS_PYTHON_VERSION: 3.9 CIBW_ENVIRONMENT: "OPEN_SPIEL_BUILDING_WHEEL='ON' OPEN_SPIEL_BUILD_WITH_ACPC='ON' OPEN_SPIEL_BUILD_WITH_HANABI='ON' OPEN_SPIEL_BUILD_WITH_ROSHAMBO='ON'" - CIBW_BUILD: cp38-macosx_universal2 cp39-macosx_universal2 cp310-macosx_universal2 cp310-macosx_universal2 cp311-macosx_universal2 cp312-macosx_universal2 + CIBW_BUILD: cp38-macosx_x86_64 cp39-macosx_x86_64 cp310-macosx_x86_64 cp311-macosx_x86_64 cp312-macosx_x86_64 + # Setting to the new M1 runners to build the _arm64 wheels + # https://github.blog/2023-10-02-introducing-the-new-apple-silicon-powered-m1-macos-larger-runner-for-github-actions/ + # TODO(author5): Set this to macos-13 once these runnings are no longer in beta + - os: macos-13-xlarge + OS_TYPE: "Darwin" + CI_PYBIN: python3.11 + OS_PYTHON_VERSION: 3.11 + CIBW_ENVIRONMENT: "OPEN_SPIEL_BUILDING_WHEEL='ON' OPEN_SPIEL_BUILD_WITH_ACPC='ON' OPEN_SPIEL_BUILD_WITH_HANABI='ON' OPEN_SPIEL_BUILD_WITH_ROSHAMBO='ON'" + CIBW_BUILD: cp39-macosx_arm64 cp310-macosx_arm64 cp311-macosx_arm64 cp312-macosx_arm64 env: OPEN_SPIEL_BUILDING_WHEEL: ON OPEN_SPIEL_BUILD_WITH_ACPC: ON OPEN_SPIEL_BUILD_WITH_HANABI: ON OPEN_SPIEL_BUILD_WITH_ROSHAMBO: ON OS_TYPE: ${{ matrix.OS_TYPE }} - OS_PYTHON_VERSION: "3.9" + OS_PYTHON_VERSION: ${{ matrix.OS_PYTHON_VERSION }} CI_PYBIN: ${{ matrix.CI_PYBIN }} CIBW_MANYLINUX_X86_64_IMAGE: manylinux2014 - CIBW_ARCHS_MACOS: universal2 CIBW_BUILD: ${{ matrix.CIBW_BUILD }} CIBW_SKIP: pp* CIBW_BEFORE_BUILD: python -m pip install --upgrade cmake @@ -73,6 +83,7 @@ jobs: # These are necessary to install what is necessary for the build and for the full tests below. ${CI_PYBIN} -m pip install --upgrade pip ${CI_PYBIN} -m pip --version + [[ "${OS_TYPE}" = "Darwin" ]] && ${CI_PYBIN} -m pip install pipx ${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 ${CI_PYBIN} @@ -91,6 +102,7 @@ jobs: # Basic tests are run via the CIBW_TEST_COMMAND environment variable. - name: Build bdist_wheel and run tests run: | + [[ "${OS_TYPE}" = "Darwin" ]] && xcodebuild -version ${CI_PYBIN} -m cibuildwheel --output-dir wheelhouse ls -l wheelhouse diff --git a/open_spiel/python/algorithms/cfr_br_test.py b/open_spiel/python/algorithms/cfr_br_test.py index 34ca457271..ae15aa7772 100644 --- a/open_spiel/python/algorithms/cfr_br_test.py +++ b/open_spiel/python/algorithms/cfr_br_test.py @@ -94,7 +94,9 @@ def test_cpp_and_python_cfr_br(self, game, solver_cls, else: exploitability_ = exploitability.nash_conv(game, avg_policy) - self.assertEqual(expected_exploitability[step], exploitability_) + self.assertAlmostEqual( + expected_exploitability[step], exploitability_, places=10 + ) if __name__ == "__main__": diff --git a/open_spiel/python/algorithms/cfr_test.py b/open_spiel/python/algorithms/cfr_test.py index 3ae6ebfe5b..5d881f12dc 100644 --- a/open_spiel/python/algorithms/cfr_test.py +++ b/open_spiel/python/algorithms/cfr_test.py @@ -262,14 +262,14 @@ def test_cpp_algorithms_identical_to_python_algorithm(self, game, cpp_class, # convert one to the other, so we use the exploitability as a proxy. cpp_expl = pyspiel.nash_conv(game, cpp_avg_policy) python_expl = exploitability.nash_conv(game, python_avg_policy) - self.assertEqual(cpp_expl, python_expl) + self.assertAlmostEqual(cpp_expl, python_expl, places=10) # Then we also check the CurrentPolicy, just to check it is giving the same # results too cpp_current_policy = cpp_solver.current_policy() python_current_policy = python_solver.current_policy() cpp_expl = pyspiel.nash_conv(game, cpp_current_policy) python_expl = exploitability.nash_conv(game, python_current_policy) - self.assertEqual(cpp_expl, python_expl) + self.assertAlmostEqual(cpp_expl, python_expl, places=10) class CorrDistTest(absltest.TestCase): diff --git a/open_spiel/python/pytorch/dqn.py b/open_spiel/python/pytorch/dqn.py index 487f3ffcbf..f229fc8d9a 100644 --- a/open_spiel/python/pytorch/dqn.py +++ b/open_spiel/python/pytorch/dqn.py @@ -326,7 +326,8 @@ def learn(self): illegal_actions_mask = 1 - legal_actions_mask legal_target_q_values = self._target_q_values.masked_fill( - illegal_actions_mask, ILLEGAL_ACTION_LOGITS_PENALTY) + illegal_actions_mask.bool(), ILLEGAL_ACTION_LOGITS_PENALTY + ) max_next_q = torch.max(legal_target_q_values, dim=1)[0] target = ( diff --git a/open_spiel/scripts/python_extra_deps.sh b/open_spiel/scripts/python_extra_deps.sh index 744922b736..d0448669cd 100644 --- a/open_spiel/scripts/python_extra_deps.sh +++ b/open_spiel/scripts/python_extra_deps.sh @@ -45,12 +45,6 @@ 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" - - # # Python-version dependent versions # @@ -58,11 +52,13 @@ export OPEN_SPIEL_PYTHON_PYTORCH_DEPS="torch==1.13.1" echo "Set Python version: $PY_VER" if verlt $PY_VER 3.10; then echo "Python < 3.10 detected" + export OPEN_SPIEL_PYTHON_PYTORCH_DEPS="torch==1.13.1" 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_PYTORCH_DEPS="torch==2.1.0" 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" diff --git a/open_spiel/scripts/test_wheel.sh b/open_spiel/scripts/test_wheel.sh index 28360706d7..53a5f6492e 100755 --- a/open_spiel/scripts/test_wheel.sh +++ b/open_spiel/scripts/test_wheel.sh @@ -63,9 +63,11 @@ 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 + ${PYBIN} -m pip install wheelhouse/open_spiel-*-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl + elif [[ "$OS" = "Darwin" && "$OS_PYTHON_VERSION" = "3.9" ]]; then + ${PYBIN} -m pip install wheelhouse/open_spiel-*-cp39-cp39-macosx_10_9_x86_64.whl else - ${PYBIN} -m pip install wheelhouse/open_spiel-*-cp39-cp39-macosx_10_9_universal2.whl + ${PYBIN} -m pip install wheelhouse/open_spiel-*-cp311-cp311-macosx_11_0_arm64.whl fi fi @@ -77,7 +79,7 @@ rm -rf build && mkdir build && cd build cmake -DPython3_EXECUTABLE=${PYBIN} $PROJDIR/open_spiel NPROC="nproc" -if [[ "$OS" == "darwin"* ]]; then +if [[ "$OS" == "darwin"* || "$OS" == "Darwin"* ]]; then NPROC="sysctl -n hw.physicalcpu" fi