createWorksetBasedOnRun {openMpp} | R Documentation |
Create new workset as SUBSET of model parameters based on parameters from existing model run
createWorksetBasedOnRun(dbCon, defRs, baseRunId, setDef, ...)
dbCon |
database connection |
defRs |
model definition: database rows describing model input parameters and output tables |
baseRunId |
id of model run results, must be positive integer |
setDef |
if not NA then workset description data frame:
|
... |
list of parameters value and (optional) value notes. Each element is also a list of $name, $subCount, $defaultSubId, $subId, $value, $txt:
|
That call allow you to create new working set of model parameters as combination of existing parameters from previous model run and some new parameters passed through ... argument(s)
Workset is a working set of model input parameters and can be a full set, which include values of all model parameters or subset and include only some parameters.
Each model must have "default" workset. Default workset is a first workset of the model with set_id = min(set_id) for that model. Default workset always include ALL model parameters (it is a full set).
If you want to create new workset as a full set of model parameters
then you must pass ALL model parameters into createWorksetBasedOnRun
through ... argument list.
If you already have result of model run in your database
and want to modify only some input parameters (subset) then call createWorksetBasedOnRun
in order to create workset using parameters from previous model run and supply some new values.
You can create subset of model parameters ONLY based on existing run results. Otherwise you have to pass ALL (full set) of parameters in order to create workset.
Each workset has unique set id (positive integer) and unique name.
To find set id by name use getWorksetIdByName
call.
Working set must be read-only to run the model, so, typically you want to call setReadonlyWorkset
after createWorksetBasedOnRun
.
Parameter(s) can have can have multiple sub-values (by default only one value, no sub-values). If you want to have multiple sub-values then $subCount must be >1 (default =1). If parameter has multiple sub-values then you can specify sub-value id as $subId (default =0). Also you can specify default sub-value id for that workset parameter as $defaultSubId (default =0).
You must use getModel
function in order to find model definition defRs
.
Return id of new working set or 0L on error
To run examples you must have modelOne database modelOne.sqlite in current directory
amc1999
OpenM++ documentation: https://github.com/openmpp/openmpp.github.io/wiki
getModel
getFirstRunId
getLastRunId
getDefaultWorksetId
getWorksetIdByName
createWorkset
copyWorksetParameterFromRun
setReadonlyWorkset
setReadonlyDefaultWorkset
updateWorksetParameter
# StartingSeed parameter have two sub-values # seedSubVal <- list( name = "StartingSeed", subCount = 2L, # two sub-values for that parameter defaultSubId = 1L, # default sub-value id for that parameter subId = 0L, # sub-value id =0 value = 100L # sub-value[0] = 100 ) # # name, description and notes for this set of model parameters # name MUST be unique # inputSet <- data.frame( name = "myOtherData", lang = "EN", descr = "new set of parameters", note = "new set of parameters with updated salary by age", stringsAsFactors = FALSE ) theDb <- dbConnect(RSQLite::SQLite(), "modelOne.sqlite", synchronous = "full") invisible(dbGetQuery(theDb, "PRAGMA busy_timeout = 86400")) # recommended # get model by name: use such call if you have only one version of the model defRs <- getModel(theDb, "modelOne") # # pass new value for StartingSeed parameter # for all other parameters use previous model run with id = 101 # setId <- createWorksetBasedOnRun(theDb, defRs, 101L, inputSet, seedSubVal) if (setId <= 0L) stop("workset creation failed: ", defRs$modelDic$model_name, " ", defRs$modelDic$model_digest) # # add seed parameter sub-value =1 # seedSubVal <- list(name = "StartingSeed", subId = 1L, value = 200L) setId <- updateWorksetParameter(theDb, defRs, setId, seedSubVal) if (setId <= 0L) stop("failed to update workset parameter: ", seedSubVal$name) # # copy ageSex parameter value from model run with id = 102 # copyWorksetParameterFromRun(theDb, defRs, setId, 102L, list(name = "ageSex")) # make workset read-only in order to run the model setReadonlyWorkset(theDb, defRs, TRUE, setId) dbDisconnect(theDb) # # you can run the model now with new salaryAge parameter value and ageSex value from other run results #