I was expecting this to set the optimizer for a model:
# Set optimizer for this model
m1 = mxRun(mxOption(m1, "Default optimizer", "NPSOL"))
But
testthat::expect_match(m1@runstate$compute$steps[1][[1]]$engine, "NPSOL")
# Error: m1@runstate$compute$steps[1][[1]]$engine does not match 'NPSOL'. Actual value: "CSOLNP"
Is that a bug in me, mxOption(), or OpenMx?
worked examples
library(OpenMx)
manifests = c("mpg", "disp", "gear")
m1 <- mxModel("ind", type = "RAM",
manifestVars = manifests,
mxPath(from = manifests, arrows = 2),
mxPath(from = "one", to = manifests),
mxData(mtcars[,manifests], type="raw")
)
m1 = mxRun(m1)
m1@runstate$compute$steps[1][[1]]$engine
# returns CSOLNP (# PS: Is this the only way to get at engine directly?)
# toggle optimizer to NPSOL for this model
m1 = mxRun(mxOption(m1, "Default optimizer", "NPSOL"))
testthat::expect_match(m1@runstate$compute$steps[1][[1]]$engine, "NPSOL")
# Error: m1@runstate$compute$steps[1][[1]]$engine does not match 'NPSOL'. Actual value: "CSOLNP"
# try global switch
mxOption(NULL, "Default optimizer", "NPSOL")
m1 = mxRun(mxOption(m1, "Default optimizer", "NPSOL"))
testthat::expect_match(m1@runstate$compute$steps[1][[1]]$engine, "NPSOL")
# all OK
#1
Error in mxOption(m1, "Default optimizer", "NPSOL") :
Default optimizer is a global option and cannot be set on models
Log in or register to post comments
#2
library(OpenMx)
manifests = c("mpg", "disp", "gear")
m1 <- mxModel("ind", type = "RAM",
manifestVars = manifests,
mxPath(from = manifests, arrows = 2),
mxPath(from = "one", to = manifests),
mxData(mtcars[,manifests], type="raw")
)
m1 = mxRun(m1)
m1@runstate$compute$steps[1][[1]]$engine
# returns CSOLNP (# PS: Is this the only way to get at engine directly?)
# toggle optimizer to NPSOL for this model
m1 = mxRun(m1 <- mxOption(m1, "Default optimizer", "NPSOL"))
testthat::expect_match(m1@runstate$compute$steps[1][[1]]$engine, "NPSOL")
# Error: m1@runstate$compute$steps[1][[1]]$engine does not match 'NPSOL'. Actual value: "CSOLNP"
# try global switch
mxOption(NULL, "Default optimizer", "NPSOL")
m1 = mxRun(mxOption(m1, "Default optimizer", "NPSOL"))
testthat::expect_match(m1@runstate$compute$steps[1][[1]]$engine, "NPSOL")
# all OK
Log in or register to post comments
#3
Is this a necessary change, since fix with
m1 = mxRun(m1 <- mxOption(m1, "Default optimizer", "NPSOL"))
works in the released 2.0 Beta
Log in or register to post comments
#4
mxOption is the wrong way to control this in the first place. Take a look at the ifa-* tests in models/. Use a custom compute plan.
> Is this a necessary change, since fix with
> m1 = mxRun(m1 <- mxOption(m1, "Default optimizer", "NPSOL"))
> works in the released 2.0 Beta
I thought the whole point of this report was that it doesn't work and fails silently?
Log in or register to post comments
#5
m1 = mxOption(m1, "Default optimizer", "NPSOL")
I think either mxOption(m1, "Default optimizer", "NPSOL") should handle the case of setting the compute plan for a model, or the error should tell people how to do this easily.
As a start, we could submit this in MxOptions.R
if (key == "Default optimizer") {
stop(paste0(key, "is a global option and cannot be set on models",
"To switch optimizers globally, use, e.g.:\n",
"mxOption(m1, 'Default optimizer', 'CSOLNP')",
"To switch for just this model, use a custom compute plan.\n",
"See help(WHERE!!!) for an example."
))
}
Log in or register to post comments
#6
Log in or register to post comments