-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added script demonstrating how to restore a policy
- Loading branch information
Michael Panchenko
committed
Aug 14, 2024
1 parent
36993fa
commit 31d3294
Showing
1 changed file
with
32 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from pathlib import Path | ||
from typing import cast | ||
|
||
from armscan_env.wrapper import ArmscanEnvFactory | ||
|
||
from tianshou.highlevel.env import EnvMode | ||
from tianshou.highlevel.experiment import Experiment | ||
|
||
# Place your path here | ||
saved_experiment_dir = Path("log/random-actions/42/20240814-150513") | ||
|
||
if __name__ == "__main__": | ||
restored_experiment = Experiment.from_directory(str(saved_experiment_dir), restore_policy=True) | ||
|
||
restored_policy = restored_experiment.create_experiment_world().policy | ||
# this can be now used to perform actions, you can also use a notebook | ||
|
||
env_factory: ArmscanEnvFactory = cast(ArmscanEnvFactory, restored_experiment.env_factory) | ||
# TODO @Carlo: modify here to set different volumes | ||
env_factory.name2volume = env_factory.name2volume | ||
|
||
# Create env manually and run policy on it | ||
restored_env = env_factory.create_env(mode=EnvMode.WATCH) | ||
obs, info = restored_env.reset() | ||
for _ in range(5): | ||
obs, *_ = restored_env.step(restored_policy.compute_action(obs)) | ||
|
||
# Or use the restored experiment to run the policy | ||
restored_experiment.config.train = False | ||
restored_experiment.config.watch = True | ||
restored_experiment.config.persistence_enabled = False | ||
restored_experiment.run() |