Skip to content
This repository was archived by the owner on May 6, 2021. It is now read-only.

Commit 5665e1d

Browse files
authored
Add default checks (#191)
* add default checks * simplify condition
1 parent 0cc7c7e commit 5665e1d

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

src/policies/agents/agent.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,17 @@ functor(x::Agent) = (policy = x.policy,), y -> @set x.policy = y.policy
2323

2424
(agent::Agent)(env) = agent.policy(env)
2525

26+
function check(agent::Agent, env::AbstractEnv)
27+
if ActionStyle(env) === FULL_ACTION_SET && !haskey(agent.trajectory, :legal_actions_mask)
28+
@warn "The env[$(nameof(env))] is of FULL_ACTION_SET, but I can not find a trace named :legal_actions_mask in the trajectory"
29+
end
30+
check(agent.policy, env)
31+
end
32+
33+
#####
34+
# update!
35+
#####
36+
2637
function (agent::Agent)(stage::AbstractStage, env::AbstractEnv)
2738
update!(agent.trajectory, agent.policy, env, stage)
2839
update!(agent.policy, agent.trajectory, env, stage)

src/policies/q_based_policies/q_based_policy.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,19 @@ RLBase.prob(p::QBasedPolicy, env, ::FullActionSet) =
3333
RLBase.update!(p::QBasedPolicy, trajectory::AbstractTrajectory) =
3434
update!(p.learner, trajectory)
3535

36+
function check(p::QBasedPolicy, env::AbstractEnv)
37+
A = action_space(env)
38+
if (A isa AbstractVector && A == 1:length(A)) ||
39+
(A isa Tuple && A == Tuple(1:length(A)))
40+
# this is expected
41+
else
42+
@warn "Applying a QBasedPolicy to an environment with a unknown action space. Maybe convert the environment with `discrete2standard_discrete` in ReinforcementLearningEnvironments.jl first or redesign the environment."
43+
end
44+
45+
check(p.learner, env)
46+
check(p.explorer, env)
47+
end
48+
3649
#####
3750
# TabularRandomPolicy
3851
#####

0 commit comments

Comments
 (0)