-
Notifications
You must be signed in to change notification settings - Fork 373
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into rjy-ising-model
- Loading branch information
Showing
34 changed files
with
1,431 additions
and
270 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
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,45 @@ | ||
from ditk import logging | ||
from ding.model import DQN | ||
from ding.policy import DQNPolicy | ||
from ding.envs import DingEnvWrapper, BaseEnvManagerV2 | ||
from ding.data import DequeBuffer | ||
from ding.config import compile_config | ||
from ding.framework import task | ||
from ding.framework.context import OnlineRLContext | ||
from ding.framework.middleware import OffPolicyLearner, StepCollector, interaction_evaluator, data_pusher, \ | ||
eps_greedy_handler, CkptSaver, nstep_reward_enhancer, final_ctx_saver | ||
from ding.utils import set_pkg_seed | ||
from dizoo.frozen_lake.config.frozen_lake_dqn_config import main_config, create_config | ||
from dizoo.frozen_lake.envs import FrozenLakeEnv | ||
|
||
|
||
def main(): | ||
logging.getLogger().setLevel(logging.INFO) | ||
main_config.policy.nstep = 5 | ||
cfg = compile_config(main_config, create_cfg=create_config, auto=True) | ||
with task.start(async_mode=False, ctx=OnlineRLContext()): | ||
collector_env = BaseEnvManagerV2( | ||
env_fn=[lambda: FrozenLakeEnv(cfg=cfg.env) for _ in range(cfg.env.collector_env_num)], cfg=cfg.env.manager | ||
) | ||
evaluator_env = BaseEnvManagerV2( | ||
env_fn=[lambda: FrozenLakeEnv(cfg=cfg.env) for _ in range(cfg.env.evaluator_env_num)], cfg=cfg.env.manager | ||
) | ||
set_pkg_seed(cfg.seed, use_cuda=cfg.policy.cuda) | ||
|
||
model = DQN(**cfg.policy.model) | ||
buffer_ = DequeBuffer(size=cfg.policy.other.replay_buffer.replay_buffer_size) | ||
policy = DQNPolicy(cfg.policy, model=model) | ||
|
||
task.use(interaction_evaluator(cfg, policy.eval_mode, evaluator_env)) | ||
task.use(eps_greedy_handler(cfg)) | ||
task.use(StepCollector(cfg, policy.collect_mode, collector_env)) | ||
task.use(nstep_reward_enhancer(cfg)) | ||
task.use(data_pusher(cfg, buffer_)) | ||
task.use(OffPolicyLearner(cfg, policy.learn_mode, buffer_)) | ||
task.use(CkptSaver(policy, cfg.exp_name, train_freq=100)) | ||
task.use(final_ctx_saver(cfg.exp_name)) | ||
task.run() | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
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
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
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
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
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
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
Oops, something went wrong.