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

Fix serialization bug #262

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
2 changes: 1 addition & 1 deletion src/model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
56 changes: 28 additions & 28 deletions test/model.jl
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Loading