Skip to content

Commit 2cdce61

Browse files
paldaydmbates
andauthored
experimental harness for PRIMA (#799)
* experimental harness for PRIMA --------- Co-authored-by: Douglas Bates <[email protected]>
1 parent f7b2017 commit 2cdce61

File tree

7 files changed

+63
-4
lines changed

7 files changed

+63
-4
lines changed

NEWS.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
MixedModels v4.29.0 Release Notes
2+
==============================
3+
- Testbed for experimental support for using PRIMA as an optimization backend introduced via the experimental `prfit!` function. [#799]
4+
15
MixedModels v4.28.0 Release Notes
26
==============================
37
- `GeneralizedLinearMixedModel` now attempts to fall back to very constrained variance values when the default initial values result in a non positive semidefinite covariance matrix. [#792]
@@ -585,3 +589,4 @@ Package dependencies
585589
[#791]: https://github.com/JuliaStats/MixedModels.jl/issues/791
586590
[#792]: https://github.com/JuliaStats/MixedModels.jl/issues/792
587591
[#795]: https://github.com/JuliaStats/MixedModels.jl/issues/795
592+
[#799]: https://github.com/JuliaStats/MixedModels.jl/issues/799

Project.toml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ StructTypes = "856f2bd8-1eba-4b0a-8007-ebc267875bd4"
3030
Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"
3131
TypedTables = "9d95f2ec-7b3d-5a63-8d20-e2491e220bb9"
3232

33+
[weakdeps]
34+
PRIMA = "0a7d04aa-8ac2-47b3-b7a7-9dbd6ad661ed"
35+
36+
[extensions]
37+
MixedModelsPRIMAExt = ["PRIMA"]
38+
3339
[compat]
3440
Aqua = "0.8"
3541
Arrow = "1, 2"
@@ -46,6 +52,7 @@ LinearAlgebra = "1"
4652
Markdown = "1"
4753
MixedModelsDatasets = "0.1"
4854
NLopt = "0.6, 1"
55+
PRIMA = "0.2"
4956
PooledArrays = "0.5, 1"
5057
PrecompileTools = "1"
5158
ProgressMeter = "1.7"
@@ -63,16 +70,17 @@ Suppressor = "0.2"
6370
Tables = "1"
6471
Test = "1"
6572
TypedTables = "1"
66-
julia = "1.8"
73+
julia = "1.10"
6774

6875
[extras]
6976
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
7077
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
7178
ExplicitImports = "7d51a73a-1435-4ff3-83d9-f097790105c7"
7279
InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
80+
PRIMA = "0a7d04aa-8ac2-47b3-b7a7-9dbd6ad661ed"
7381
StableRNGs = "860ef19b-820b-49d6-a774-d7a799459cd3"
7482
Suppressor = "fd094767-a336-5f1f-9728-57cf17d0bbfb"
7583
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
7684

7785
[targets]
78-
test = ["Aqua", "DataFrames", "ExplicitImports", "InteractiveUtils", "StableRNGs", "Suppressor", "Test"]
86+
test = ["Aqua", "DataFrames", "ExplicitImports", "InteractiveUtils", "PRIMA", "StableRNGs", "Suppressor", "Test"]

ext/MixedModelsPRIMAExt.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module MixedModelsPRIMAExt
2+
3+
using MixedModels: MixedModels, LinearMixedModel, objective!
4+
using PRIMA: PRIMA
5+
6+
function MixedModels.prfit!(m::LinearMixedModel)
7+
PRIMA.bobyqa!(objective!(m), copy(m.optsum.initial); xl=m.optsum.lowerbd)
8+
return m
9+
end
10+
11+
end # module

src/MixedModels.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ include("grouping.jl")
205205
include("mimeshow.jl")
206206
include("serialization.jl")
207207
include("profile/profile.jl")
208+
include("prima.jl")
208209

209210
# COV_EXCL_START
210211
@setup_workload begin

src/prima.jl

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
"""
3+
prfit!(m::LinearMixedModel)
4+
5+
Fit a mixed model using the [PRIMA](https://github.com/libprima/PRIMA.jl) implementation
6+
of the BOBYQA optimizer.
7+
8+
!!! warning "Experimental feature"
9+
This function is an experimental feature that will go away in the future.
10+
Do **not** rely on it, unless you are willing to pin the precise MixedModels.jl
11+
version. The purpose of the function is to provide the MixedModels developers
12+
a chance to explore the performance of the PRIMA implementation without the large
13+
and potentially breaking changes it would take to fully replace the current NLopt
14+
backend with a PRIMA backend or a backend supporting a range of optimizers.
15+
16+
!!! note "Package extension"
17+
In order to reduce the dependency burden, all methods of this function are
18+
implemented in a package extension and are only defined when PRIMA.jl is loaded
19+
by the user.
20+
"""
21+
function prfit! end

test/prima.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using PRIMA
2+
using MixedModels: prfit!
3+
using MixedModels: dataset
4+
5+
include("modelcache.jl")
6+
7+
# model = first(models(:sleepstudy))
8+
9+
@testset "formula($model)" for model in models(:sleepstudy)
10+
prmodel = prfit!(LinearMixedModel(formula(model), dataset(:sleepstudy)))
11+
12+
@test isapprox(loglikelihood(model), loglikelihood(prmodel))
13+
end

test/runtests.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ using Test
77
import InteractiveUtils: versioninfo
88
import LinearAlgebra: BLAS
99

10-
using Base: splat # necessary for Julia 1.8 compat
11-
1210
# there seem to be processor-specific issues and knowing this is helpful
1311
@info sprint(versioninfo)
1412
@info BLAS.get_config()
@@ -45,3 +43,5 @@ include("mime.jl")
4543
include("optsummary.jl")
4644
include("predict.jl")
4745
include("sigma.jl")
46+
47+
@testset "PRIMA" include("prima.jl")

0 commit comments

Comments
 (0)