Skip to content

Commit

Permalink
Fix lunar lander dependency issues (#367)
Browse files Browse the repository at this point in the history
## Description

<!-- Provide a brief description of the PR's purpose here. -->

We have been running into some issues with lunar lander not running
properly on Colab due to dependency issues. We also had some dependency
issues with swig (see #366).

Regarding swig, I found that it was difficult to get the examples to
work properly with swig because we were not using a virtual environment,
so the different Python versions were being confused -- hence we would
get errors like "Module not found" when trying to use swig. To remedy
this problem, I have started #367 to run all PR jobs in a Conda env.
This PR uses a Conda env only for the examples job.

## TODO

<!-- Notable points that this PR has either accomplished or will
accomplish. -->

- [x] Upgrade to gymnasium 0.29.1 due to Jax-jumpy issues -> gymnasium
0.27.0 depended on jax-jumpy, which resulted in installation errors
because jax-jumpy was not fully production-ready
- [x]  Fix ordering of Dask imports
- [x] Re-run tutorial on Colab to get times; update tutorial times
accordingly
- [x] Run on Colab and fix deprecation warnings -> looks like there were
no warnings
- [x] Try running locally in Python 3.10 -> Colab CPU seems really slow
compared to local CPU, but this makes sense
- [x]  Fix deps in lunar lander example
- [x] Make example.sh script run multiple pip install commands

## Questions

<!-- Any concerns or points of confusion? -->

## Status

- [x] I have read the guidelines in

[CONTRIBUTING.md](https://github.com/icaros-usc/pyribs/blob/master/CONTRIBUTING.md)
- [x] I have formatted my code using `yapf`
- [x] I have tested my code by running `pytest`
- [x] I have linted my code with `pylint`
- [x] I have added a one-line description of my change to the changelog
in
      `HISTORY.md`
- [x] This PR is ready to go
  • Loading branch information
btjanaka committed Sep 10, 2023
1 parent d818f43 commit 8a5be85
Show file tree
Hide file tree
Showing 6 changed files with 179 additions and 150 deletions.
19 changes: 9 additions & 10 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -113,30 +113,29 @@ jobs:
examples:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
# SWIG should not be installed so that we can test that lunar lander is
# installing SWIG properly. See https://github.com/icaros-usc/pyribs/pull/366
- name: Remove swig
run: sudo rm -rf /usr/bin/swig
- name: Set up Python 3.8
uses: actions/setup-python@v4
run: sudo apt-get remove swig
- uses: actions/checkout@v4
- uses: conda-incubator/setup-miniconda@v2
with:
python-version: "3.8"
- name: Upgrade pip
run: python -m pip install --upgrade pip
python-version: 3.8
- name: Install deps
shell: bash -el {0}
run: pip install .[visualize]
- name: Test Examples
shell: bash -el {0}
run: bash tests/examples.sh
tutorials:
runs-on: ubuntu-latest
steps:
# We use Python 3.10 instead of 3.8 here since Google Colab uses 3.10.
- uses: actions/checkout@v4
# SWIG should not be installed so that we can test that lunar lander is
# installing SWIG properly. See https://github.com/icaros-usc/pyribs/pull/366
- name: Remove swig
run: sudo rm -rf /usr/bin/swig
run: sudo apt-get remove swig
# We use Python 3.10 instead of 3.8 here since Google Colab uses 3.10.
- uses: actions/checkout@v4
- name: Set up Python 3.10
uses: actions/setup-python@v4
with:
Expand Down
5 changes: 3 additions & 2 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,9 @@ max-nested-blocks=5
max-line-length=80

# Regexp for a line that is allowed to be longer than the limit. The first group
# (before the `|`) matches URLs, and the second matches Sphinx links.
ignore-long-lines=(^\s*(# )?<?https?://\S+>?$)|(^\s*<.*>`_.?$)
# (before the `|`) matches URLs, the second matches Sphinx links, the third
# matches pip install commands.
ignore-long-lines=(^\s*(# )?<?https?://\S+>?$)|(^\s*<.*>`_.?$)|(^\s*pip install .*)

# Allow the body of an if to be on the same line as the test if there is no
# else.
Expand Down
2 changes: 1 addition & 1 deletion HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

- Use dask instead of multiprocessing for lunar lander tutorial ({pr}`346`)
- pip install swig before gymnasium[box2d] in lunar lander tutorial ({pr}`346`)
- Fix lunar lander dependency issues ({pr}`366`)
- Fix lunar lander dependency issues ({pr}`366`, {pr}`377`)

#### Improvements

Expand Down
6 changes: 4 additions & 2 deletions examples/lunar_lander.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
"""Uses CMA-ME to train agents with linear policies in Lunar Lander.
Install the following dependencies before running this example:
pip install ribs[visualize] tqdm fire gymnasium[box2d]==0.27.0 moviepy>=1.0.0 dask>=2.0.0 distributed>=2.0.0 bokeh>=2.0.0
Install the following dependencies before running this example -- swig must be
installed before box2d can be installed, hence it is a separate command:
pip install swig
pip install ribs[visualize] tqdm fire gymnasium[box2d]==0.29.1 moviepy>=1.0.0 dask>=2.0.0 distributed>=2.0.0 bokeh>=2.0.0
This script uses the same setup as the tutorial, but it also uses Dask instead
of Python's multiprocessing to parallelize evaluations on a single machine and
Expand Down
7 changes: 5 additions & 2 deletions tests/examples.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@ if [ ! -d "${TMPDIR}" ]; then
fi

function install_deps() {
install_cmd=$(grep "pip install" "$1")
$install_cmd
# Loop through all instances of `pip install` in the script and run the
# installation commands.
grep '^\s*pip install' "$1" | while read -r install_cmd ; do
$install_cmd
done
}

# Single-threaded for consistency.
Expand Down

0 comments on commit 8a5be85

Please sign in to comment.