From c22fe2036e69dd14d4a8a2bd79e45ddbb39709e9 Mon Sep 17 00:00:00 2001 From: Tor Erlend Fjelde Date: Mon, 18 Sep 2023 21:21:03 +0100 Subject: [PATCH] added skip for summaries with nothing in deserializtaion iterator --- src/Deserialization/deserialization.jl | 6 ++++++ test/test_hparams.jl | 15 +++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/src/Deserialization/deserialization.jl b/src/Deserialization/deserialization.jl index 4284fc7..16335b1 100644 --- a/src/Deserialization/deserialization.jl +++ b/src/Deserialization/deserialization.jl @@ -187,6 +187,12 @@ function Base.iterate(iter::SummaryDeserializingIterator, state=1) (tag, summary), i_state = res + # This can happen in certain cases, e.g. if hyperparameters have been recorded. + if summary.value === nothing + # Hence, we just skip it. + return Base.iterate(iter, state + 1) + end + typ = summary_type(summary) if typ === :histo val = deserialize_histogram_summary(summary) diff --git a/test/test_hparams.jl b/test/test_hparams.jl index 17b959e..46ec760 100644 --- a/test/test_hparams.jl +++ b/test/test_hparams.jl @@ -88,4 +88,19 @@ end decoded_v = hv.kind.value @test expected_hparams_config[k] == decoded_v end +end + +@testset "Reading with hparams present (#137)" begin + # https://github.com/JuliaLogging/TensorBoardLogger.jl/issues/137 + lg = TBLogger(joinpath(mktempdir(), "logs")) + TensorBoardLogger.write_hparams!( + lg, + Dict("hi" => 1.0), + ["x/val"] + ) + with_logger(lg) do + @info "x" val=3.0 + end + hist = convert(MVHistory, lg) + @test haskey(hist, "x/val") end \ No newline at end of file