Skip to content

Commit

Permalink
Merge branch 'master' into benchmarking-docs
Browse files Browse the repository at this point in the history
  • Loading branch information
AdamGleave committed May 10, 2023
2 parents 4c4445c + ebdb42b commit b1a5d76
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 7 deletions.
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ commands:
# Download and cache dependencies
- restore_cache:
keys:
- v9win-dependencies-{{ checksum "setup.py" }}-{{ checksum "ci/build_and_activate_venv.ps1" }}
- v10win-dependencies-{{ checksum "setup.py" }}-{{ checksum "ci/build_and_activate_venv.ps1" }}

- run:
name: install python and binary dependencies
Expand Down Expand Up @@ -168,7 +168,7 @@ commands:
- save_cache:
paths:
- .\venv
key: v9win-dependencies-{{ checksum "setup.py" }}-{{ checksum "ci/build_and_activate_venv.ps1" }}
key: v10win-dependencies-{{ checksum "setup.py" }}-{{ checksum "ci/build_and_activate_venv.ps1" }}

- run:
name: install imitation
Expand Down
6 changes: 4 additions & 2 deletions ci/build_and_activate_venv.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ If ($venv -eq $null) {

virtualenv -p python3.8 $venv
& $venv\Scripts\activate
# Note: We need to install setuptools==66.1.1 to allow installing gym==0.21.0.
python -m pip install --upgrade pip setuptools==66.1.1
# Note: We need to install these versions of setuptools and wheel to allow installing gym==0.21.0 on Windows.
# See https://github.com/freqtrade/freqtrade/issues/8376
# TODO(GH#707): remove pin once upgraded Gym
python -m pip install --upgrade pip wheel==0.38.4 setuptools==65.5.1
pip install ".[docs,parallel,test]"
8 changes: 8 additions & 0 deletions ci/build_and_activate_venv.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,12 @@ virtualenv -p ${python_version} ${venv}
source ${venv}/bin/activate
# Note: We need to install setuptools==66.1.1 to allow installing gym==0.21.0.
python -m pip install --upgrade pip setuptools==66.1.1

# If platform is linux, install pytorch CPU version.
# This will prevent installing the CUDA version in the pip install ".[docs,parallel,test]" command.
# The CUDA version is a couple of gigabytes larger than the CPU version.
# Since we don't need the CUDA version for testing, we can save some time by not installing it.
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
pip install torch --index-url https://download.pytorch.org/whl/cpu
fi
pip install ".[docs,parallel,test]"
2 changes: 2 additions & 0 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# specific version needed for gym==0.21.0
setuptools==65.5.0
2 changes: 2 additions & 0 deletions readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ build:

python:
install:
# TODO(GH#707): remove docs/requirements.txt once Gym upgraded
- requirements: docs/requirements.txt
- method: pip
path: .
extra_requirements:
Expand Down
13 changes: 10 additions & 3 deletions src/imitation/testing/expert_trajectories.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import math
import pathlib
import pickle
import shutil
import warnings
from os import PathLike
from pathlib import Path
Expand Down Expand Up @@ -73,10 +74,10 @@ def lazy_generate_expert_trajectories(
environment_cache_path = pathlib.Path(cache_path) / hfsb3.EnvironmentName(env_id)
environment_cache_path.mkdir(parents=True, exist_ok=True)

trajectories_path = environment_cache_path / "rollout.npz"
trajectories_path = environment_cache_path / "rollout"

# Note: we cast to str here because FileLock doesn't support pathlib.Path.
with FileLock(str(environment_cache_path / "rollout.npz.lock")):
with FileLock(str(environment_cache_path / "rollout.lock")):
try:
trajectories = data_serialize.load_with_rewards(trajectories_path)
except (FileNotFoundError, pickle.PickleError) as e: # pragma: no cover
Expand All @@ -96,7 +97,13 @@ def lazy_generate_expert_trajectories(
return trajectories[:num_trajectories]
else: # pragma: no cover
# If it is not enough, just throw away the cache and generate more.
trajectories_path.unlink()
if trajectories_path.is_dir():
# rmtree won't remove directory on Windows
# until the last handle to the directory is closed
del trajectories
shutil.rmtree(trajectories_path)
else:
trajectories_path.unlink()
return lazy_generate_expert_trajectories(
cache_path,
env_id,
Expand Down
Binary file modified tests/testdata/expert_models/cartpole_0/policies/final/model.zip
Binary file not shown.

0 comments on commit b1a5d76

Please sign in to comment.