Skip to content

Commit 7103ee1

Browse files
paldayararslan
andauthored
add finally block for restoring original model in profiling (#795)
* add finally block for restoring original model in profiling * version bump + NEWS * scope is hard * test * bump macos runner version * Update src/profile/profile.jl Co-authored-by: Alex Arslan <[email protected]> --------- Co-authored-by: Alex Arslan <[email protected]>
1 parent 2f92408 commit 7103ee1

File tree

5 files changed

+37
-18
lines changed

5 files changed

+37
-18
lines changed

.github/workflows/minimum.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
matrix:
2323
julia-version: [min]
2424
julia-arch: [x64]
25-
os: [ubuntu-22.04, macos-12, windows-2019]
25+
os: [ubuntu-22.04, macos-13, windows-2019]
2626
steps:
2727
- uses: actions/checkout@v4
2828
- uses: julia-actions/setup-julia@v2

NEWS.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
MixedModels v4.27.1 Release Notes
2+
==============================
3+
- `profile` now includes a `finally` block to restore the original model even if an error occurs before profiling is complete [#795]
4+
15
MixedModels v4.27.0 Release Notes
26
==============================
37
- `saveoptsum` and `restoreoptsum!` now support `GeneralizedLinearMixedModel`s [#791]
@@ -575,3 +579,4 @@ Package dependencies
575579
[#783]: https://github.com/JuliaStats/MixedModels.jl/issues/783
576580
[#785]: https://github.com/JuliaStats/MixedModels.jl/issues/785
577581
[#791]: https://github.com/JuliaStats/MixedModels.jl/issues/791
582+
[#795]: https://github.com/JuliaStats/MixedModels.jl/issues/795

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "MixedModels"
22
uuid = "ff71e718-51f3-5ec2-a782-8ffcbfa3c316"
33
author = ["Phillip Alday <[email protected]>", "Douglas Bates <[email protected]>", "Jose Bayoan Santiago Calderon <[email protected]>"]
4-
version = "4.27.0"
4+
version = "4.27.1"
55

66
[deps]
77
Arrow = "69666777-d1a9-59fb-9406-91d4454c9d45"

src/profile/profile.jl

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -35,23 +35,30 @@ value of ζ exceeds `threshold`.
3535
function profile(m::LinearMixedModel; threshold=4)
3636
isfitted(m) || refit!(m)
3737
final = copy(m.optsum.final)
38-
tc = TableColumns(m)
39-
val = profileσ(m, tc; threshold) # FIXME: defer creating the splines until the whole table is constructed
40-
objective!(m, final) # restore the parameter estimates
41-
for s in filter(s -> startswith(string(s), 'β'), keys(first(val.tbl)))
42-
profileβj!(val, tc, s; threshold)
43-
end
44-
copyto!(m.optsum.final, final)
45-
m.optsum.fmin = objective!(m, final)
46-
for s in filter(s -> startswith(string(s), 'θ'), keys(first(val.tbl)))
47-
profileθj!(val, s, tc; threshold)
38+
profile = try
39+
tc = TableColumns(m)
40+
val = profileσ(m, tc; threshold) # FIXME: defer creating the splines until the whole table is constructed
41+
objective!(m, final) # restore the parameter estimates
42+
for s in filter(s -> startswith(string(s), 'β'), keys(first(val.tbl)))
43+
profileβj!(val, tc, s; threshold)
44+
end
45+
copyto!(m.optsum.final, final)
46+
m.optsum.fmin = objective!(m, final)
47+
for s in filter(s -> startswith(string(s), 'θ'), keys(first(val.tbl)))
48+
profileθj!(val, s, tc; threshold)
49+
end
50+
profileσs!(val, tc)
51+
MixedModelProfile(m, Table(val.tbl), val.fwd, val.rev)
52+
catch ex
53+
@error "Exception occurred in profiling; aborting..."
54+
rethrow()
55+
finally
56+
objective!(m, final) # restore the parameter estimates
57+
copyto!(m.optsum.final, final)
58+
m.optsum.fmin = objective(m)
59+
m.optsum.sigma = nothing
4860
end
49-
profileσs!(val, tc)
50-
objective!(m, final) # restore the parameter estimates
51-
copyto!(m.optsum.final, final)
52-
m.optsum.fmin = objective(m)
53-
m.optsum.sigma = nothing
54-
return MixedModelProfile(m, Table(val.tbl), val.fwd, val.rev)
61+
return profile
5562
end
5663

5764
"""

test/pls.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -725,6 +725,13 @@ end
725725
# very loose tolerance for unstable fit
726726
# but this is a convenient test of rankUpdate!(::UniformBlockDiagonal)
727727
@test isapprox(m.θ, θnlopt; atol=5e-2)
728+
729+
@testset "profile" begin
730+
# TODO: actually handle the case here so that it doesn't error and
731+
# create a separate test of the error handling code
732+
@test_logs((:error, "Exception occurred in profiling; aborting..."),
733+
@test_throws Exception profile(last(models(:oxide))))
734+
end
728735
end
729736

730737
@testset "Rank deficient" begin

0 commit comments

Comments
 (0)