|
| 1 | +import shutil |
| 2 | +import subprocess |
| 3 | +from pathlib import Path |
| 4 | + |
| 5 | +import pandas as pd |
| 6 | + |
| 7 | + |
| 8 | +def test_pbt_sac_example(): |
| 9 | + if Path("./tmp/sac_pbt").exists(): |
| 10 | + shutil.rmtree(Path("./tmp/sac_pbt")) |
| 11 | + subprocess.call( |
| 12 | + [ |
| 13 | + "python", |
| 14 | + "examples/sb3_rl_agent.py", |
| 15 | + "--config-name=sac_pbt", |
| 16 | + "-m", |
| 17 | + "algorithm.total_timesteps=1000", |
| 18 | + "hydra.sweeper.sweeper_kwargs.optimizer_kwargs.config_interval=500", |
| 19 | + ] |
| 20 | + ) |
| 21 | + assert Path("./tmp/sac_pbt").exists(), "Run directory not created" |
| 22 | + assert Path("./tmp/sac_pbt/runhistory.csv").exists(), "Run history file not created" |
| 23 | + runhistory = pd.read_csv("./tmp/sac_pbt/runhistory.csv") |
| 24 | + assert not runhistory.empty, "Run history is empty" |
| 25 | + assert len(runhistory) == 4, "Run history should contain 4 entries" |
| 26 | + shutil.rmtree(Path("./tmp/sac_pbt")) |
| 27 | + |
| 28 | + |
| 29 | +def test_pb2_sac_example(): |
| 30 | + if Path("./tmp/sac_pb2").exists(): |
| 31 | + shutil.rmtree(Path("./tmp/sac_pb2")) |
| 32 | + subprocess.call( |
| 33 | + [ |
| 34 | + "python", |
| 35 | + "examples/sb3_rl_agent.py", |
| 36 | + "--config-name=sac_pb2", |
| 37 | + "-m", |
| 38 | + "algorithm.total_timesteps=1000", |
| 39 | + "hydra.sweeper.sweeper_kwargs.optimizer_kwargs.config_interval=500", |
| 40 | + ] |
| 41 | + ) |
| 42 | + assert Path("./tmp/sac_pb2").exists(), "Run directory not created" |
| 43 | + assert Path("./tmp/sac_pb2/runhistory.csv").exists(), "Run history file not created" |
| 44 | + runhistory = pd.read_csv("./tmp/sac_pb2/runhistory.csv") |
| 45 | + assert not runhistory.empty, "Run history is empty" |
| 46 | + assert len(runhistory) == 4, "Run history should contain 4 entries" |
| 47 | + shutil.rmtree(Path("./tmp/sac_pb2")) |
0 commit comments