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

Add a test timeout #779

Merged
merged 29 commits into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
41d4d17
Add a test timeout.
ernestum Sep 8, 2023
243db63
Add a test timeout.
ernestum Sep 8, 2023
ce1f8c6
Skip ray tests on windows.
ernestum Sep 8, 2023
86f877d
Remove path limit in Windows environment
ZiyueWang25 Oct 1, 2023
1a3323f
From unit-test-windows -> dependencies-windows
ZiyueWang25 Oct 1, 2023
afdba28
Merge remote-tracking branch 'origin/master' into add_test_timeout
ZiyueWang25 Oct 1, 2023
7eb9dbc
Update tutorial notebooks
ZiyueWang25 Oct 2, 2023
a83df13
Merge branch 'notebook_fix' into add_test_timeout
ZiyueWang25 Oct 2, 2023
1e3370d
Revert "Merge branch 'notebook_fix' into add_test_timeout"
ZiyueWang25 Oct 2, 2023
08bd76a
Update tutorial notebooks
ZiyueWang25 Oct 2, 2023
423ff85
Remove output from 3_train_gail.ipynb
ZiyueWang25 Oct 2, 2023
3f19d95
Merge branch 'notebook_fix' into add_test_timeout
ZiyueWang25 Oct 2, 2023
26a730e
Adjust rl_kwargs to pass sqil performance test
ZiyueWang25 Oct 2, 2023
1d927af
customize rl parameters for different algo in test
ZiyueWang25 Oct 2, 2023
224ed28
Increase timeout to 5 min and shorten a NB runtime
ZiyueWang25 Oct 2, 2023
cddc094
Resolve np randint high bound issue
ZiyueWang25 Oct 2, 2023
f88dc0f
Increase the notebook timeout from 5 mins to 9
ZiyueWang25 Oct 2, 2023
9aa5c47
add github issue number for tracking
ZiyueWang25 Oct 3, 2023
96cf438
rename env to venv, add seed
ZiyueWang25 Oct 3, 2023
e91513f
change name to "enable long path" for clarity
ZiyueWang25 Oct 3, 2023
b199b98
reformat notebook
ZiyueWang25 Oct 3, 2023
d5026b6
reformat notebook use black-jupyter
ZiyueWang25 Oct 3, 2023
fdc1c03
Remove MuJoCo install
AdamGleave Oct 4, 2023
99cd7fd
Invalidate MacOS cache
AdamGleave Oct 4, 2023
74fa89a
Revert "Invalidate MacOS cache"
AdamGleave Oct 4, 2023
776c535
Invalidate Windows dependencies
AdamGleave Oct 4, 2023
3e70bb0
Revert "reformat notebook use black-jupyter"
ZiyueWang25 Oct 4, 2023
3a2a8e2
Revert "reformat notebook"
ZiyueWang25 Oct 4, 2023
c2a5d13
reformat 4_train_airl notebook only
ZiyueWang25 Oct 4, 2023
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
12 changes: 10 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:
- v10win-dependencies-{{ checksum "setup.py" }}-{{ checksum "ci/build_and_activate_venv.ps1" }}
- v11win-dependencies-{{ checksum "setup.py" }}-{{ checksum "ci/build_and_activate_venv.ps1" }}

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

- run:
name: install imitation
command: |
.\venv\Scripts\activate
pip install --upgrade --force-reinstall --no-deps .
shell: powershell.exe

- run:
name: print installed packages
command: |
.\venv\Scripts\activate
pip freeze --all
shell: powershell.exe

- run:
ZiyueWang25 marked this conversation as resolved.
Show resolved Hide resolved
name: enable long path
command: |
New-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem" `
-Name "LongPathsEnabled" -Value 1 -PropertyType DWORD -Force
shell: powershell.exe

restore-pytest-cache:
description: "Restore .pytest_cache from CircleCI cache."
steps:
Expand Down
2 changes: 1 addition & 1 deletion docs/tutorials/3_train_gail.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@
")\n",
"\n",
"# train the learner and evaluate again\n",
"gail_trainer.train(800_000)\n",
"gail_trainer.train(200_000)\n",
"env.seed(SEED)\n",
"learner_rewards_after_training, _ = evaluate_policy(\n",
" learner, env, 100, return_episode_rewards=True\n",
Expand Down
26 changes: 13 additions & 13 deletions docs/tutorials/4_train_airl.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
"metadata": {},
"outputs": [],
"source": [
"import seals # noqa: F401 # needed to load \"seals/\" environments\n",
"import numpy as np\n",
"import gymnasium as gym\n",
"from imitation.policies.serialize import load_policy\n",
"from imitation.util.util import make_vec_env\n",
"from imitation.data.wrappers import RolloutInfoWrapper\n",
Expand All @@ -34,11 +34,11 @@
"FAST = True\n",
"\n",
"if FAST:\n",
" N_RL_TRAIN_STEPS = 800_000\n",
" N_RL_TRAIN_STEPS = 300_000\n",
"else:\n",
" N_RL_TRAIN_STEPS = 2_000_000\n",
"\n",
"env = make_vec_env(\n",
"venv = make_vec_env(\n",
" \"seals/CartPole-v0\",\n",
" rng=np.random.default_rng(SEED),\n",
" n_envs=8,\n",
Expand All @@ -50,7 +50,7 @@
" \"ppo-huggingface\",\n",
" organization=\"HumanCompatibleAI\",\n",
" env_name=\"seals-CartPole-v0\",\n",
" venv=env,\n",
" venv=venv,\n",
")"
]
},
Expand All @@ -71,7 +71,7 @@
"\n",
"rollouts = rollout.rollout(\n",
" expert,\n",
" env,\n",
" venv,\n",
" rollout.make_sample_until(min_timesteps=None, min_episodes=60),\n",
" rng=np.random.default_rng(SEED),\n",
")"
Expand Down Expand Up @@ -101,7 +101,7 @@
"\n",
"\n",
"learner = PPO(\n",
" env=env,\n",
" env=venv,\n",
" policy=MlpPolicy,\n",
" batch_size=64,\n",
" ent_coef=0.0,\n",
Expand All @@ -113,28 +113,28 @@
" seed=SEED,\n",
")\n",
"reward_net = BasicShapedRewardNet(\n",
" observation_space=env.observation_space,\n",
" action_space=env.action_space,\n",
" observation_space=venv.observation_space,\n",
" action_space=venv.action_space,\n",
" normalize_input_layer=RunningNorm,\n",
")\n",
"airl_trainer = AIRL(\n",
" demonstrations=rollouts,\n",
" demo_batch_size=2048,\n",
" gen_replay_buffer_capacity=512,\n",
" n_disc_updates_per_round=16,\n",
" venv=env,\n",
" venv=venv,\n",
" gen_algo=learner,\n",
" reward_net=reward_net,\n",
")\n",
"\n",
"env.reset(seed=SEED)\n",
"venv.seed(SEED)\n",
"learner_rewards_before_training, _ = evaluate_policy(\n",
" learner, env, 100, return_episode_rewards=True\n",
" learner, venv, 100, return_episode_rewards=True\n",
")\n",
"airl_trainer.train(N_RL_TRAIN_STEPS)\n",
"env.seed(SEED)\n",
"venv.seed(SEED)\n",
"learner_rewards_after_training, _ = evaluate_policy(\n",
" learner, env, 100, return_episode_rewards=True\n",
" learner, venv, 100, return_episode_rewards=True\n",
")"
]
},
Expand Down
6 changes: 4 additions & 2 deletions docs/tutorials/5a_train_preference_comparisons_with_cnn.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"source": [
"import torch as th\n",
"import gymnasium as gym\n",
"from gym.wrappers import TimeLimit\n",
"from gymnasium.wrappers import TimeLimit\n",
"import numpy as np\n",
"\n",
"from seals.util import AutoResetWrapper\n",
Expand Down Expand Up @@ -64,7 +64,9 @@
"\n",
"# For real training, you will want a vectorized environment with 8 environments in parallel.\n",
"# This can be done by passing in n_envs=8 as an argument to make_vec_env.\n",
"venv = make_vec_env(constant_length_asteroids, env_kwargs={\"num_steps\": 100})\n",
"# The seed needs to be set to 1 for reproducibility and also to avoid win32\n",
"# np.random.randint high bound error.\n",
"venv = make_vec_env(constant_length_asteroids, env_kwargs={\"num_steps\": 100}, seed=1)\n",
"venv = VecFrameStack(venv, n_stack=4)\n",
"\n",
"reward_net = CnnRewardNet(\n",
Expand Down
2 changes: 1 addition & 1 deletion docs/tutorials/8a_train_sqil_sac.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
"SEED = 42\n",
"\n",
"venv = make_vec_env(\n",
" \"seals/HalfCheetah-v0\",\n",
" \"seals/HalfCheetah-v1\",\n",
" rng=np.random.default_rng(seed=SEED),\n",
")\n",
"\n",
Expand Down
4 changes: 4 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ filterwarnings =
markers =
expensive: mark a test as expensive (deselect with '-m "not expensive"')

# Terminate the test just before CircleCI's 10-minute timeout so we see the test failure
# instead of a timeout.
timeout = 590

[coverage:run]
source = imitation
include=
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"pytest~=7.1.2",
"pytest-cov~=3.0.0",
"pytest-notebook==0.8.0",
"pytest-timeout~=2.1.0",
"pytest-xdist~=2.5.0",
"scipy~=1.9.0",
"wandb==0.12.21",
Expand Down
16 changes: 10 additions & 6 deletions tests/algorithms/test_sqil.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,18 +246,22 @@ def test_sqil_performance_continuous(
pendulum_single_venv: vec_env.VecEnv,
rl_algo_class: Type[off_policy_algorithm.OffPolicyAlgorithm],
):
rl_kwargs = dict(
learning_starts=500,
learning_rate=0.001,
gamma=0.95,
seed=42,
)
if rl_algo_class == ddpg.DDPG:
rl_kwargs["gamma"] = 0.99
ZiyueWang25 marked this conversation as resolved.
Show resolved Hide resolved
rl_kwargs["learning_starts"] = 100
_test_sqil_performance(
rng,
pytestconfig,
pendulum_single_venv,
"Pendulum-v1",
rl_algo_class=rl_algo_class,
rl_kwargs=dict(
learning_starts=500,
learning_rate=0.001,
gamma=0.95,
seed=42,
),
rl_kwargs=rl_kwargs,
)


Expand Down
1 change: 1 addition & 0 deletions tests/scripts/test_scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -853,6 +853,7 @@ def test_train_rl_cnn_policy(tmpdir: str, rng):
}


@pytest.mark.skipif(sys.platform.startswith("win"), reason="Ray is buggy on windows.")
@pytest.mark.parametrize("config_updates", PARALLEL_CONFIG_UPDATES)
def test_parallel(config_updates, tmpdir):
"""Hyperparam tuning smoke test."""
Expand Down
4 changes: 3 additions & 1 deletion tests/test_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ def test_run_tutorial_notebooks(nb_path) -> None: # pragma: no cover
nb_path: Path to the notebook to test.
"""
nb = ptnb.notebook.load_notebook(nb_path)
result = ptnb.execution.execute_notebook(nb, cwd=TUTORIALS_DIR, timeout=120)
# TODO(GH#793): Shorten timeout and ensure the notebook can still show desired
# improvement.
result = ptnb.execution.execute_notebook(nb, cwd=TUTORIALS_DIR, timeout=540)
assert result.exec_error is None


Expand Down
Loading