Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move UnicodePlots to extension #1088

Merged
merged 14 commits into from
Jan 13, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Refactor UnicodePlots integration into extension
jeremiahpslewis committed Dec 18, 2024
commit 573fb1cef8c783668b9aaa5ad12180de607730b4
9 changes: 6 additions & 3 deletions src/ReinforcementLearningCore/Project.toml
Original file line number Diff line number Diff line change
@@ -4,7 +4,6 @@ version = "0.15.4"

[deps]
AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c"
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
CircularArrayBuffers = "9de3a189-e0c0-4e15-ba3b-b14b9fb0aec1"
Crayons = "a8cc5b0e-0ffa-5ad4-8c14-923d3ee1735f"
@@ -21,11 +20,15 @@ ReinforcementLearningTrajectories = "6486599b-a3cd-4e92-a99a-2cea90cc8c3c"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
TimerOutputs = "a759f4b9-e2f1-59dc-863e-4aeb61b1ea8f"

[weakdeps]
UnicodePlots = "b8865327-cd53-5732-bb35-84acbb429228"

[extensions]
UnicodePlotsExt = "UnicodePlots"

[compat]
AbstractTrees = "0.3, 0.4"
Adapt = "3, 4"
ChainRulesCore = "1"
CircularArrayBuffers = "0.1.12"
Crayons = "4"
@@ -57,4 +60,4 @@ UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"
cuDNN = "02a925ec-e4fe-4b08-9a7e-0d78e3d38ccd"

[targets]
test = ["CommonRLInterface", "CUDA", "cuDNN", "DomainSets", "Metal", "Preferences", "ReinforcementLearningEnvironments", "Test", "UUIDs"]
test = ["CommonRLInterface", "CUDA", "cuDNN", "DomainSets", "Metal", "Preferences", "ReinforcementLearningEnvironments", "Test", "UnicodePlots", "UUIDs"]
18 changes: 18 additions & 0 deletions src/ReinforcementLearningCore/ext/UnicodePlotsExt.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module UnicodePlotsExt
using ReinforcementLearningCore
using UnicodePlots: lineplot, lineplot!

function Base.show(io::IO, hook::TotalRewardPerEpisode{true, F}) where {F<:Number}
if length(hook.rewards) > 0
println(io, lineplot(
hook.rewards,
title="Total reward per episode",
xlabel="Episode",
ylabel="Score",
))
else
println(io, typeof(hook))
end
return
end
end
15 changes: 0 additions & 15 deletions src/ReinforcementLearningCore/src/core/hooks.jl
Original file line number Diff line number Diff line change
@@ -10,7 +10,6 @@ export AbstractHook,
DoEveryNSteps,
DoOnExit

using UnicodePlots: lineplot, lineplot!
using Statistics: mean, std
using CircularArrayBuffers: CircularVectorBuffer
import ReinforcementLearningBase: RLBase
@@ -172,20 +171,6 @@ function Base.push!(hook::TotalRewardPerEpisode,
return
end

function Base.show(io::IO, hook::TotalRewardPerEpisode{true, F}) where {F<:Number}
if length(hook.rewards) > 0
println(io, lineplot(
hook.rewards,
title="Total reward per episode",
xlabel="Episode",
ylabel="Score",
))
else
println(io, typeof(hook))
end
return
end

function Base.push!(hook::TotalRewardPerEpisode{true, F},
::PostExperimentStage,
agent::AbstractPolicy,
1 change: 1 addition & 0 deletions src/ReinforcementLearningCore/test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Test
using UnicodePlots
using UUIDs
using Preferences