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

Add tolerances in deserialization #703

Merged
merged 7 commits into from
Aug 8, 2023
Merged
Changes from 1 commit
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
8 changes: 6 additions & 2 deletions src/serialization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

Read, check, and restore the `optsum` field from a JSON stream or filename.
"""
function restoreoptsum!(m::LinearMixedModel{T}, io::IO; atol::Real=0, rtol::Real=atol>0 ? 0 : √eps(T)) where {T}
function restoreoptsum!(
m::LinearMixedModel{T}, io::IO; atol::Real=0, rtol::Real=atol > 0 ? 0 : √eps(T)
palday marked this conversation as resolved.
Show resolved Hide resolved
) where {T}
dict = JSON3.read(io)
ops = m.optsum
okay =
Expand All @@ -22,7 +24,9 @@ function restoreoptsum!(m::LinearMixedModel{T}, io::IO; atol::Real=0, rtol::Real
copyto!(ops.initial, dict.initial)
copyto!(ops.final, dict.final)
for (v, f) in (:initial => :finitial, :final => :fmin)
if !isapprox(objective(updateL!(setθ!(m, getfield(ops, v)))), getfield(ops, f); rtol, atol)
if !isapprox(
objective(updateL!(setθ!(m, getfield(ops, v)))), getfield(ops, f); rtol, atol
)
throw(ArgumentError("model m at $v does not give stored $f"))
end
end
Expand Down
Loading