Skip to content

Commit 89a46d9

Browse files
Add missing legal_action_space_mask default methods (#1075)
* Fix devcontainer * Add patch for missing legal_action_space_mask defaults, add test to StockTradingEnv
1 parent cf14bf0 commit 89a46d9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+139
-58
lines changed

.devcontainer/devcontainer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@
1111
"--privileged"
1212
],
1313
"dockerFile": "Dockerfile",
14-
"updateContentCommand": "julia -e 'using Pkg; Pkg.develop(path=\"src/ReinforcementLearningBase\"); Pkg.develop(path=\"src/ReinforcementLearningEnvironments\"); Pkg.develop(path=\"src/ReinforcementLearningCore\"); Pkg.develop(path=\"src/ReinforcementLearningFarm\"); Pkg.develop(path=\"src/ReinforcementLearning\");'"
14+
"updateContentCommand": "julia -e 'using Pkg; Pkg.develop(path=\"src/ReinforcementLearningBase\"); Pkg.develop(path=\"src/ReinforcementLearningEnvironments\"); Pkg.develop(path=\"src/ReinforcementLearningCore\"); Pkg.develop(path=\"src/ReinforcementLearningFarm\"); Pkg.develop(path=\".\");'"
1515
}

.github/workflows/CompatHelper.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
run: which julia
1616
continue-on-error: true
1717
- name: Install Julia, but only if it is not already available in the PATH
18-
uses: julia-actions/setup-julia@v1
18+
uses: julia-actions/setup-julia@v2
1919
with:
2020
version: '1'
2121
arch: ${{ runner.arch }}

.github/workflows/ci.yml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ jobs:
3434
- uses: actions/checkout@v4
3535
with:
3636
fetch-depth: 100
37-
- uses: julia-actions/setup-julia@v1
37+
- uses: julia-actions/setup-julia@v2
3838
with:
3939
version: ${{ matrix.version }}
4040
arch: ${{ matrix.arch }}
41-
- uses: julia-actions/cache@v1
41+
- uses: julia-actions/cache@v2
4242
- name: Get changed files
4343
id: RLBase-changed
4444
uses: tj-actions/changed-files@v42
@@ -75,11 +75,11 @@ jobs:
7575
- uses: actions/checkout@v4
7676
with:
7777
fetch-depth: 100
78-
- uses: julia-actions/setup-julia@v1
78+
- uses: julia-actions/setup-julia@v2
7979
with:
8080
version: ${{ matrix.version }}
8181
arch: ${{ matrix.arch }}
82-
- uses: julia-actions/cache@v1
82+
- uses: julia-actions/cache@v2
8383
- name: Get changed files
8484
id: RLCore-changed
8585
uses: tj-actions/changed-files@v42
@@ -121,11 +121,11 @@ jobs:
121121
- uses: actions/checkout@v4
122122
with:
123123
fetch-depth: 100
124-
- uses: julia-actions/setup-julia@v1
124+
- uses: julia-actions/setup-julia@v2
125125
with:
126126
version: ${{ matrix.version }}
127127
arch: ${{ matrix.arch }}
128-
- uses: julia-actions/cache@v1
128+
- uses: julia-actions/cache@v2
129129
- name: Get changed files
130130
id: RLFarm-changed
131131
uses: tj-actions/changed-files@v42
@@ -168,11 +168,11 @@ jobs:
168168
- uses: actions/checkout@v4
169169
with:
170170
fetch-depth: 100
171-
- uses: julia-actions/setup-julia@v1
171+
- uses: julia-actions/setup-julia@v2
172172
with:
173173
version: ${{ matrix.version }}
174174
arch: ${{ matrix.arch }}
175-
# - uses: julia-actions/cache@v1
175+
# - uses: julia-actions/cache@v2
176176
- name: Get changed files
177177
id: RLEnvironments-changed
178178
uses: tj-actions/changed-files@v42
@@ -205,7 +205,7 @@ jobs:
205205
with:
206206
fetch-depth: 0
207207
- run: python -m pip install --user matplotlib
208-
- uses: julia-actions/setup-julia@v1
208+
- uses: julia-actions/setup-julia@v2
209209
with:
210210
version: "1"
211211
- name: Build homepage

Project.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ authors = ["Johanni Brea <[email protected]>", "Jun Tian <tianjun.c
44
version = "0.11.0"
55

66
[deps]
7-
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
87
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
98
ReinforcementLearningBase = "e575027e-6cd6-5018-9292-cdc6200d2b44"
109
ReinforcementLearningCore = "de1b191a-4ae0-4afa-a27b-92d07f46b2d6"

docs/homepage/blog/a_practical_introduction_to_RL.jl/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15415,7 +15415,7 @@ <h2 id="Environments">Environments<a class="anchor-link" href="#Environments">&#
1541515415
<div class="text_cell_render border-box-sizing rendered_html">
1541615416

1541715417
<pre><code>RLBase.action_space(env::MultiArmBanditsEnv) = Base.OneTo(length(env.true_values))
15418-
RLBase.state(env::MultiArmBanditsEnv) = 1
15418+
RLBase.state(env::MultiArmBanditsEnv, ::Observation, ::DefaultPlayer) = 1
1541915419
RLBase.state_space(env::MultiArmBanditsEnv) = Base.OneTo(1)
1542015420
RLBase.is_terminated(env::MultiArmBanditsEnv) = env.is_terminated
1542115421
RLBase.reward(env::MultiArmBanditsEnv) = env.reward

docs/src/How_to_write_a_customized_environment.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ Here `RLBase` is just an alias for `ReinforcementLearningBase`.
6868

6969
```@repl customized_env
7070
RLBase.reward(env::LotteryEnv) = env.reward
71-
RLBase.state(env::LotteryEnv) = !isnothing(env.reward)
71+
RLBase.state(env::LotteryEnv, ::Observation, ::DefaultPlayer) = !isnothing(env.reward)
7272
RLBase.state_space(env::LotteryEnv) = [false, true]
7373
RLBase.is_terminated(env::LotteryEnv) = !isnothing(env.reward)
7474
RLBase.reset!(env::LotteryEnv) = env.reward = nothing
@@ -181,7 +181,7 @@ RLCore.forward(p.learner.approximator, false)
181181

182182
OK, now we know where the problem is. But how to fix it?
183183

184-
An initial idea is to rewrite the `RLBase.state(env::LotteryEnv)` function to
184+
An initial idea is to rewrite the `RLBase.state(env::LotteryEnv, ::Observation, ::DefaultPlayer)` function to
185185
force it return an `Int`. That's workable. But in some cases, we may be using
186186
environments written by others and it's not very easy to modify the code
187187
directly. Fortunatelly, some environment wrappers are provided to help us

src/ReinforcementLearningBase/NEWS.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
### ReinforcementLearningBase.jl Release Notes
22

3+
#### v0.13.1
4+
5+
- Don't call `legal_action_space_mask` methods when `ActionStyle` is `MinimalActionSet`
6+
7+
#### v0.13.0
8+
9+
- Breaking release compatible with RL.jl v0.11
10+
311
#### v0.12.0
412

513
- Transition to `RLCore.forward`, `RLBase.act!`, `RLBase.plan!` and `Base.push!` syntax instead of functional objects for hooks, policies and environments

src/ReinforcementLearningBase/Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "ReinforcementLearningBase"
22
uuid = "e575027e-6cd6-5018-9292-cdc6200d2b44"
33
authors = ["Johanni Brea <[email protected]>", "Jun Tian <[email protected]>"]
4-
version = "0.13.0"
4+
version = "0.13.1"
55

66
[deps]
77
AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c"

src/ReinforcementLearningBase/src/interface.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ For environments of [`MINIMAL_ACTION_SET`](@ref), the result is the same with
487487
@multi_agent_env_api legal_action_space(env::AbstractEnv, player=current_player(env)) =
488488
legal_action_space(ActionStyle(env), env, player)
489489

490-
legal_action_space(::MinimalActionSet, env, player::AbstractPlayer) = action_space(env)
490+
legal_action_space(::MinimalActionSet, env::AbstractEnv, player::AbstractPlayer) = action_space(env)
491491

492492
"""
493493
legal_action_space_mask(env, player=current_player(env)) -> AbstractArray{Bool}
@@ -497,6 +497,9 @@ Required for environments of [`FULL_ACTION_SET`](@ref). As a default implementat
497497
the subset [`legal_action_space`](@ref).
498498
"""
499499
@multi_agent_env_api legal_action_space_mask(env::AbstractEnv, player=current_player(env)) =
500+
legal_action_space_mask(ActionStyle(env), env, player)
501+
502+
legal_action_space_mask(::FullActionSet, env::AbstractEnv, player=current_player(env)) =
500503
map(action_space(env, player)) do action
501504
action in legal_action_space(env, player)
502505
end

src/ReinforcementLearningBase/test/interface.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ struct TestEnv <: RLBase.AbstractEnv
44
state::Int
55
end
66

7-
function RLBase.state(env::TestEnv, ::Observation{Any}, ::DefaultPlayer)
7+
function RLBase.state(env::TestEnv, ::Observation, ::DefaultPlayer)
88
return env.state
99
end
1010

0 commit comments

Comments
 (0)