Skip to content

Commit

Permalink
Use Format.jl instead of Formatting.jl (#211)
Browse files Browse the repository at this point in the history
  • Loading branch information
ScottPJones authored Mar 13, 2024
1 parent 5439be8 commit 2ecda9a
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 19 deletions.
6 changes: 3 additions & 3 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "AlphaZero"
uuid = "8ed9eb0b-7496-408d-8c8b-2119aeea02cd"
authors = ["Jonathan Laurent <[email protected]>"]
version = "0.5.4"
version = "0.5.5"

[deps]
ArgParse = "c7e460c6-2fb9-53a9-8c5b-16f535851c63"
Expand All @@ -15,7 +15,7 @@ Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
ExprTools = "e2ba6199-217a-4e67-a87a-7c52f15ade04"
Flux = "587475ba-b771-5e3f-ad9e-33799f191a9c"
Formatting = "59287772-0a20-5a39-b81b-1366585eb4c0"
Format = "1fa38f19-a742-5d3f-a2b9-30dd87b9d5f8"
JSON3 = "0f8b85d8-7281-11e9-16c2-39a750bddbf1"
Knet = "1902f260-5fb4-5aff-8c31-6271790ab950"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Expand All @@ -42,7 +42,7 @@ Distributions = "0.24.18, 0.25"
Documenter = "0.26.3, 0.27"
ExprTools = "= 0.1.3, 0.1"
Flux = "0.12.2, 0.13"
Formatting = "0.4.2"
Format = "1.3"
JSON3 = "1.8.1"
Knet = "1.4.8"
LoggingExtras = "0.4.7, 1"
Expand Down
4 changes: 2 additions & 2 deletions games/connect-four/scripts/pons_benchmark.jl
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ const BENCHMARKS = load_benchmarks(BENCHMARKS_DIR)
using AlphaZero
using .Examples.ConnectFour: GameSpec, Solver, Training
using ProgressMeter
using Formatting
using Format
using Statistics: mean

const gspec = GameSpec()
Expand Down Expand Up @@ -139,7 +139,7 @@ function test_player(make_player, oracle)
err = test_player_on(make_player, oracle, bench, p)
push!(errs, err)
err_str =
println("($(bench.stage), $(bench.difficulty)): $(fmt(".2f", 100 * err))%")
println("($(bench.stage), $(bench.difficulty)): $(pyfmt(".2f", 100 * err))%")
end
return errs
end
Expand Down
4 changes: 2 additions & 2 deletions src/AlphaZero.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
module AlphaZero

import Distributed
using Formatting
using Format
using Base: @kwdef
using DataStructures: CircularBuffer
using Distributions: Categorical, Dirichlet
Expand Down Expand Up @@ -187,4 +187,4 @@ module AlphaZero
end


end
end
2 changes: 1 addition & 1 deletion src/trace.jl
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function debug_trace(gspec::AbstractGameSpec, t::Trace)
game = GI.init(gspec, t.states[i])
GI.render(game)
for (a, p) in zip(GI.available_actions(game), t.policies[i])
print("$(GI.action_string(gspec, a)): $(fmt(".3f", p)) ")
print("$(GI.action_string(gspec, a)): $(pyfmt(".3f", p)) ")
end
println("")
println("Obtained reward of: $(t.rewards[i]).")
Expand Down
6 changes: 3 additions & 3 deletions src/ui/explorer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ end
#####

function print_state_statistics(gspec, stats::StateStats)
prob = Log.ColType(nothing, x -> fmt(".1f", 100 * x) * "%")
val = Log.ColType(nothing, x -> fmt("+.2f", x))
prob = Log.ColType(nothing, x -> pyfmt(".1f", 100 * x) * "%")
val = Log.ColType(nothing, x -> pyfmt("+.2f", x))
bigint = Log.ColType(nothing, n -> format(ceil(Int, n), commas=true))
alabel = Log.ColType(nothing, identity)
btable = Log.Table([
Expand Down Expand Up @@ -305,4 +305,4 @@ end

function explore(player::AbstractPlayer, gspec::AbstractGameSpec; args...)
return explore(player, GI.init(gspec), args...)
end
end
4 changes: 2 additions & 2 deletions src/ui/log.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module Log
export Logger

using Crayons
using Formatting: fmt
using Format: pyfmt
import ProgressMeter

const INDENT_STEP = 2
Expand Down Expand Up @@ -130,7 +130,7 @@ end

set_columns(tab, cols) = Table(cols, tab.header_style, tab.comments_style)

fixed_width(str, width) = fmt(">$(width)s", first(str, width))
fixed_width(str, width) = pyfmt(">$(width)s", first(str, width))

intersperse(sep, words) = reduce((x, y) -> x * sep * y, words)

Expand Down
8 changes: 4 additions & 4 deletions src/ui/session.jl
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ AlphaZero.AlphaZeroPlayer(s::Session; args...) = AlphaZero.AlphaZeroPlayer(s.env
##### Utilities for printing reports
#####

const NUM_COL = Log.ColType(7, x -> fmt(".4f", x))
const NUM_COL = Log.ColType(7, x -> pyfmt(".4f", x))
const BIGINT_COL = Log.ColType(10, n -> format(ceil(Int, n), commas=true))

const LEARNING_STATUS_TABLE = Log.Table([
Expand Down Expand Up @@ -401,7 +401,7 @@ end
function print_report(logger::Logger, report::Report.SelfPlay)
sspeed = format(round(Int, report.samples_gen_speed), commas=true)
Log.print(logger, "Generating $(sspeed) samples per second on average")
avgdepth = fmt(".1f", report.average_exploration_depth)
avgdepth = pyfmt(".1f", report.average_exploration_depth)
Log.print(logger, "Average exploration depth: $avgdepth")
memf = format(report.mcts_memory_footprint, autoscale=:metric, precision=2)
Log.print(logger, "MCTS memory footprint per worker: $(memf)B")
Expand Down Expand Up @@ -433,7 +433,7 @@ function print_report(
nn_replaced=false,
ternary_outcome=false)

r = fmt("+.2f", report.avgr)
r = pyfmt("+.2f", report.avgr)
if ternary_outcome
n = length(report.rewards)
stats = Benchmark.TernaryOutcomeStatistics(report)
Expand All @@ -449,7 +449,7 @@ function print_report(
push!(details, "network replaced")
end
details = isempty(details) ? "" : " (" * join(details, ", ") * ")"
red = fmt(".1f", 100 * report.redundancy)
red = pyfmt(".1f", 100 * report.redundancy)
msg = "Average reward: $r$details, redundancy: $red%"
Log.print(logger, msg)
end
Expand Down
4 changes: 2 additions & 2 deletions src/ui/ui.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module UserInterface
import JSON3
using Base: @kwdef
using Statistics: mean
using Formatting: format, fmt
using Format: format, pyfmt
using Crayons: @crayon_str
using Colors: @colorant_str
using ProgressMeter
Expand All @@ -30,4 +30,4 @@ module UserInterface
include("json.jl")
include("session.jl")

end
end

0 comments on commit 2ecda9a

Please sign in to comment.