diff --git a/Project.toml b/Project.toml index 5acb519c..54925ff7 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "JuliaBUGS" uuid = "ba9fb4c0-828e-4473-b6a1-cd2560fee5bf" -version = "0.8.0" +version = "0.8.1" [deps] AbstractMCMC = "80f14c24-f653-4e6a-9b94-39d6b0f70001" diff --git a/src/model.jl b/src/model.jl index 25f3b20d..f4e009d2 100644 --- a/src/model.jl +++ b/src/model.jl @@ -245,10 +245,10 @@ function Serialization.serialize(s::Serialization.AbstractSerializer, model::BUG end function Serialization.deserialize(s::Serialization.AbstractSerializer, ::Type{<:BUGSModel}) + transformed = Serialization.deserialize(s) model_def = Serialization.deserialize(s) data = Serialization.deserialize(s) evaluation_env = Serialization.deserialize(s) - transformed = Serialization.deserialize(s) # use evaluation_env as initialization to restore the values model = compile(model_def, data, evaluation_env) return settrans(model, transformed) diff --git a/test/model.jl b/test/model.jl index dd0d88f0..ed9126bc 100644 --- a/test/model.jl +++ b/test/model.jl @@ -1,31 +1,31 @@ -# @testset "serialization" begin -# (; model_def, data) = JuliaBUGS.BUGSExamples.rats -# model = compile(model_def, data) -# serialize("m.jls", model) -# deserialized = deserialize("m.jls") -# @testset "test values are correctly restored" begin -# for vn in MetaGraphsNext.labels(model.g) -# @test isequal( -# get(model.evaluation_env, vn), get(deserialized.evaluation_env, vn) -# ) -# end - -# @test model.transformed == deserialized.transformed -# @test model.untransformed_param_length == deserialized.untransformed_param_length -# @test model.transformed_param_length == deserialized.transformed_param_length -# @test all( -# model.untransformed_var_lengths[k] == deserialized.untransformed_var_lengths[k] -# for k in keys(model.untransformed_var_lengths) -# ) -# @test all( -# model.transformed_var_lengths[k] == deserialized.transformed_var_lengths[k] for -# k in keys(model.transformed_var_lengths) -# ) -# @test Set(model.parameters) == Set(deserialized.parameters) -# # skip testing g -# @test model.model_def === deserialized.model_def -# end -# end +@testset "serialization" begin + (; model_def, data) = JuliaBUGS.BUGSExamples.rats + model = compile(model_def, data) + serialize("m.jls", model) + deserialized = deserialize("m.jls") + @testset "test values are correctly restored" begin + for vn in MetaGraphsNext.labels(model.g) + @test isequal( + get(model.evaluation_env, vn), get(deserialized.evaluation_env, vn) + ) + end + + @test model.transformed == deserialized.transformed + @test model.untransformed_param_length == deserialized.untransformed_param_length + @test model.transformed_param_length == deserialized.transformed_param_length + @test all( + model.untransformed_var_lengths[k] == deserialized.untransformed_var_lengths[k] + for k in keys(model.untransformed_var_lengths) + ) + @test all( + model.transformed_var_lengths[k] == deserialized.transformed_var_lengths[k] for + k in keys(model.transformed_var_lengths) + ) + @test Set(model.parameters) == Set(deserialized.parameters) + # skip testing g + @test model.model_def == deserialized.model_def + end +end @testset "controlling sampling behavior for conditioned variables" begin model_def = @bugs begin