Skip to content

Commit

Permalink
Fix serialization bug (#262)
Browse files Browse the repository at this point in the history
Closes #261

---------

Co-authored-by: Xianda Sun <[email protected]>
  • Loading branch information
miguelbiron and sunxd3 authored Dec 14, 2024
1 parent 73eb637 commit 6af805b
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 30 deletions.
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

2 comments on commit 6af805b

@sunxd3
Copy link
Member

@sunxd3 sunxd3 commented on 6af805b Dec 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/121423

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.8.1 -m "<description of version>" 6af805b949362361feff87226fc0b96a2e5be8b9
git push origin v0.8.1

Please sign in to comment.