-
Notifications
You must be signed in to change notification settings - Fork 0
Use Oms to prepare model input
OpenM++ provides multiple different ways to supply input parameters and run the models as described at:
You don't have to do any programming or database operations in order to provide model input parameters, you can:
- provide parameter value as command line argument
- run model with default workset (default "scenario")
- use workset name ("scenario" name) to run the model
- use ini-file to provide model parameters
- supply parameter values as csv-file(s)
Also following API available for advanced parameter manipulation and output results processing:
- JSON web-service to use with any modern framework (.NET, JavaScript, Python, etc.)
- Go library and tools
- OpenMpp R package and R usage examples
Current page describe an usage of openM++ JSON web-service (oms) in order to prepare, examine and modify model input parameters. There are two terms are used in text below: "workset" and "base run". Please see Model Run Cycle: How model finds input parameters page for details.
Workset is a set of model input parameters in database which we can use to run the model. Each workset has unique name. Each model must have "default workset", which is a first set of model input parameters. Model user can create, modify and delete worksets.
Each model run started from creating full copy of model input parameters in database, which are used for that particular model run. Because usually only small portion of model parameters are changing between model runs it is convenient to create new workset (new "scenario") based on input parameters of previous model run, which is called "base run". In that case we only need to supply few modified parameter values and the rest is coming from "base run" parameters.
Below we are using oms web-service to prepare model input.
Most examples are created with browser output and curl
to avoid any unnecessary programing languages details.
You can start oms web-service on Windows:
C:
cd \SomeDir\openmpp_win_20190508\
bin\oms.exe -oms.ApiOnly
Or Linux:
cd openmpp_debian_20190508/
bin/oms -oms.ApiOnly
If your models are not in models/bin
sub-folder then use:
bin/oms -oms.ApiOnly -oms.ModelDir ../my_model_dir
Please see Oms web-service page for more details.
We need to know model name at least, or better model digest to find or modify model input parameters. Open your favorite browser and type:
http://localhost:4040/api/model-list
Result can look like:
[
{
"ModelId": 1,
"Name": "modelOne",
"Digest": "_201208171604590148_",
"Type": 0,
"Version": "1.0",
"CreateDateTime": "2012-08-17 16:04:59.0148",
"DefaultLangCode": "EN"
},
{
"ModelId": 101,
"Name": "RiskPaths",
"Digest": "db6e5168c74a73a4f5b194cb2a793444",
"Type": 0,
"Version": "3.0.0.0",
"CreateDateTime": "2018-12-14 18:36:05.0272",
"DefaultLangCode": "EN"
}
]
Go to:
http://localhost:4040/api/model/modelOne/workset-list
[
{
"ModelName": "modelOne",
"ModelDigest": "_201208171604590148_",
"Name": "Default",
"BaseRunDigest": "",
"IsReadonly": true,
"UpdateDateTime": "2013-05-29 23:55:07.1234",
"Txt": [],
"Param": []
},
........
]
First workset is a default set of model input parameters. You can explore more it at
http://localhost:4040/api/model/modelOne/workset/Default/text
and look at each parameter values, for example:
http://localhost:4040/api/model/modelOne/workset/Default/parameter/StartingSeed/value
[
{
"Dims": [],
"IsNull": false,
"Value": 8191,
"SubId": 0
}
]
Or
http://localhost:4040/api/model/modelOne/workset/Default/parameter/ageSex/value
[
{"Dims":["10-20","M"],"IsNull":false,"Value":0.1,"SubId":0}
,{"Dims":["10-20","F"],"IsNull":false,"Value":0.2,"SubId":0}
,{"Dims":["20-30","M"],"IsNull":false,"Value":0.3,"SubId":0}
,{"Dims":["20-30","F"],"IsNull":false,"Value":0.4,"SubId":0}
,{"Dims":["30-40","M"],"IsNull":false,"Value":0.5,"SubId":0}
,{"Dims":["30-40","F"],"IsNull":false,"Value":0.6,"SubId":0}
,{"Dims":["40+","M"],"IsNull":false,"Value":0.7,"SubId":0}
,{"Dims":["40+","F"],"IsNull":false,"Value":0.8,"SubId":0}
]
To see the history of model runs:
http://localhost:4040/api/model/modelOne/run-list
[
{
"ModelName": "modelOne",
"ModelDigest": "_201208171604590148_",
"Name": "Default",
"SubCount": 1,
"SubStarted": 1,
"SubCompleted": 1,
"CreateDateTime": "2019-01-10 18:36:13.0655",
"Status": "s",
"UpdateDateTime": "2019-01-10 18:36:13.0669",
"Digest": "6fbad822cb9ae42deea1ede626890711",
"Txt": [],
"Opts": {},
"Param": [],
"Progress": []
},
........
{
"ModelName": "modelOne",
"ModelDigest": "_201208171604590148_",
"Name": "Parameter sub-values 2 from csv",
"SubCount": 2,
"SubStarted": 2,
"SubCompleted": 2,
"CreateDateTime": "2019-01-10 18:36:13.0745",
"Status": "s",
"UpdateDateTime": "2019-01-10 18:36:13.0762",
"Digest": "ac72e96b549638d31acaf6ee965b23c2",
"Txt": [],
"Opts": {},
"Param": [],
"Progress": []
},
........
]
Model run can be uniquely identified by run digest, for example above:
- digest:
"ac72e96b549638d31acaf6ee965b23c2"
, run name: "Parameter sub-values 2 from csv" - digest:
"6fbad822cb9ae42deea1ede626890711"
, run name: "Default"
Run name may not be unique, but in examples below we going to use name just to improve readability.
To see the parameter value from particular model run:
http://localhost:4040/api/model/modelOne/run/Default/parameter/StartingSeed/value
[
{
"Dims": [],
"IsNull": false,
"Value": 1023,
"SubId": 0
}
]
Or
http://localhost:4040/api/model/modelOne/run/Default/parameter/baseSalary/value
[
{
"Dims": [],
"IsNull": false,
"Value": "Full",
"SubId": 0
}
]
Profile is a set of key-value options, similar to ini-file, which can be used to run the model. Each profile can be identified by profile name. It may be more convenient to use profiles instead of ini-files because profiles are stored in database and you don't need to deal with multiple files in order to publish and run the model in cloud.
To create profile named seed-1-base-full
with values of StartingSeed
and baseSalary
parameters :
curl -v -X PATCH -H "Content-Type: application/json" \
"http://localhost:4040/api/model/modelOne/profile" \
-d \
'{ "Name": "seed-1-base-full",
"Opts": {
"OpenM.StartingSeed": "1023",
"OpenM.baseSalary": "Full"
}
}'
Above curl command line is Linux specific, on Windows you must use ^ instead of \ for multi-line input and also double "quotes" and " instead of single 'quotes'.
To view model profile:
http://localhost:4040/api/model/modelOne/profile/seed-1-base-full
{
"Name": "seed-1-base-full",
"Opts": {
"OpenM.StartingSeed": "1023",
"OpenM.baseSalary": "Full"
}
}
To modify profile value:
curl -v -X POST http://localhost:4040/api/model/modelOne/profile/seed-1-base-full/key/Parameter.StartingSeed/value/4095
You can create multiple profiles similar to above in order to run the model with different StartingSeed
and baseSalary
parameter values:
modelOne -OpenM.Profile seed-1-base-full
modelOne -OpenM.Profile seed-1-base-part
modelOne -OpenM.Profile seed-2-base-full
modelOne -OpenM.Profile seed-2-base-part
It is the same as supply parameter values on command line:
modelOne -Parameter.StartingSeed 1023 -Parameter.baseSalary Full
modelOne -Parameter.StartingSeed 1023 -Parameter.baseSalary Part
modelOne -Parameter.StartingSeed 2047 -Parameter.baseSalary Full
modelOne -Parameter.StartingSeed 2047 -Parameter.baseSalary Part
Above model runs are using profile or command line values of StartingSeed
and baseSalary
and all other parameters
are coming from "default" workset (default set of input parameters, a.k.a. default "scenario").
If you already run the model then database contains run results in output tables and copy of input parameters of that model run. We can use previous run parameters as "base" for our new workset, modify only some of it and run our model again.
1. To create New-Set
of model parameters based on model run named "Default" with digest "6fbad822cb9ae42deea1ede626890711":
curl -v -X PUT \
-F 'workset={
"ModelName": "modelOne",
"Name": "New-Set",
"BaseRunDigest": "6fbad822cb9ae42deea1ede626890711",
"Txt": [
{ "LangCode": "EN", "Descr": "My new set of input parameters" }
],
"Param": [
{
"Name": "StartingSeed",
"SubCount": 1,
"Txt": [
{ "LangCode": "EN", "Note": "Starting seed new value" }
],
"Value": [
{"Dims": [], "IsNull": false, "Value": 8191, "SubId": 0}
]
},
{
"Name": "ageSex",
"SubCount": 1,
"Txt": [],
"Value": [
{"Dims": ["10-20","M"], "IsNull": false, "Value": 0.1, "SubId": 0},
{"Dims": ["10-20","F"], "IsNull": false, "Value": 0.2, "SubId": 0},
{"Dims": ["20-30","M"], "IsNull": false, "Value": 0.3, "SubId": 0},
{"Dims": ["20-30","F"], "IsNull": false, "Value": 0.4, "SubId": 0},
{"Dims": ["30-40","M"], "IsNull": false, "Value": 0.5, "SubId": 0},
{"Dims": ["30-40","F"], "IsNull": false, "Value": 0.6, "SubId": 0},
{"Dims": ["40+","M"], "IsNull": false, "Value": 0.7, "SubId": 0},
{"Dims": ["40+","F"], "IsNull": false, "Value": 0.8, "SubId": 0}
]
}
]
}' \
http://localhost:4040/api/workset-create
That New-Set
conatins new values for StartingSeed
and ageSex
parameters. All other input values are identical to previous "Default" model run input.
Each input set of model parameters (each workset) must have unique name. Different models can have worksets with same name,
i.e. each model can have workset with name "Default". If workset with the same name New-Set
already exist then this method return an error.
You don't have to create workset based on previous model run, you can omit BaseRunDigest
and include all parameter values in the new workset.
However it may be difficult for complex model with hundreds input parameters.
If you already run the model then database contains run results in output tables and copy of input parameters of that model run. We can use previous run parameters as "base" for our new workset, modify only some of it and run our model again.
1. To create new MyFirstSet
of model parameters based on model run named "Default" with digest "6fbad822cb9ae42deea1ede626890711":
curl -v -X PUT \
-F 'workset={
"ModelName": "modelOne",
"Name": "MyFirstSet",
"BaseRunDigest": "6fbad822cb9ae42deea1ede626890711",
"Txt": [
{ "LangCode": "EN", "Descr": "My first set of input parameters" }
]
}' \
http://localhost:4040/api/workset-replace
That workset does not yet include any new parameter values, all input is identical to previous "Default" model run input. In order to modify parameter values we first need to copy into our new workset from any model run, any other workset or upload as csv-file.
2. Copy parameter StartingSeed
value into MyFirstSet
workset from Default-4
model run:
curl -v -X PUT http://localhost:4040/api/model/modelOne/workset/MyFirstSet/copy/parameter/StartingSeed/from-run/Default-4
3. Copy parameter baseSalary
value into MyFirstSet
workset from modelOne_other
workset:
curl -v -X PUT http://localhost:4040/api/model/modelOne/workset/MyFirstSet/copy/parameter/baseSalary/from-workset/modelOne_other
4. Upload parameter ageSex
values into MyFirstSet
workset from my_age_sex.csv
csv file:
curl -v -X PATCH \
-F 'workset={
"ModelName": "modelOne",
"Name": "MyFirstSet",
"Param": [
{ "Name": "ageSex", "SubCount": 1 }
]
}' \
-F 'parameter-csv=@my_age_sex.csv;filename=ageSex.csv' \
http://localhost:4040/api/workset-merge
where content of my_age_sex.csv is:
sub_id,dim0,dim1,param_value
0,10-20,M,11
0,10-20,F,12
0,20-30,M,13
0,20-30,F,14
0,30-40,M,15
0,30-40,F,16
0,40+,M,17
0,40+,F,18
It is also possible to modify some part of parameter values.
For example, ageSex
parameter above is 4*3 matrix and if want to modify values:
[30-40, M] = 0.15
[30-40, F] = 0.16
then:
curl -v -X PATCH -H "Content-Type: application/json" \
http://localhost:4040/api/model/modelOne/workset/MyFirstSet/parameter/ageSex/new/value \
-d '[
{"Dims": ["30-40", "M"], "IsNull": false, "SubId":0, "Value": 0.15},
{"Dims": ["30-40", "F"], "IsNull": false, "SubId":0, "Value": 0.16}
]'
Finally our "MyFirstSet" input set contains new values for 3 parameters: StartingSeed, baseSalary, ageSex
,
which different from previous "base run" parameters. And now we can run our model with that new workset:
modelOne -OpenM.SetName MyFirstSet
It is also possible to delete parameter from workset, delete entire workset in order to cleanup database and perform some other operations. Please see Oms: openM++ web-service API for details.
Modeling task consists of multiple sets of input data and can be run in batch mode. There is an example of modeling task at Run RiskPaths model from R page where we creating 800 sets of input data to study Childlessness by varying
- Age baseline for first union formation
- Relative risks of union status on first pregnancy After preparing such modeling task we can submit RiskPath model to high performance cluster (HPC) grid or in cloud where model will read 800 input sets and produce 800 model run outputs.
It is also possible to create or modify or delete modeling task without R, using Oms JSON web-service from programming language of your choice.
In order to do this we need first to prepare our input worksets as described above and after that we can create modeling task.
For example, if we have two worksets: MyFirstSet, MySecondSet
then we can create task:
curl -v -X PUT -H "Content-Type: application/json" \
http://localhost:4040/api/task-new \
-d '{
"ModelName": "modelOne",
"Name": "MyTask",
"Txt": [{
"LangCode": "EN",
"Descr": "Task to vary 3 parameters",
"Note": "Study effect of 3 parameters on output results"
}
],
"Set": [
"MyFirstSet",
"MySecondSet"
]
}'
You can see the list of modeling tasks:
http://localhost:4040/api/model/modelOne/task-list
examine task metadata, input sets or task run history:
http://localhost:4040/api/model/modelOne/task/MyTask/text
http://localhost:4040/api/model/modelOne/task/MyTask/sets
http://localhost:4040/api/model/modelOne/task/MyTask/runs
It is also possible to delete or modify task.
For example, if you want to add MyThirdSet
set of parameters to the task above:
curl -v -X PATCH -H "Content-Type: application/json" \
http://localhost:4040/api/task \
-d '{
"ModelName": "modelOne",
"Name": "MyTask",
"Set": [
"MyThirdSet"
]
}'
After that task will contain 3 input worksets:
http://localhost:4040/api/model/modelOne/task/MyTask/sets
{
"ModelName": "modelOne",
"ModelDigest": "_201208171604590148_",
"Name": "MyTask",
"Txt": [],
"Set": [
"MyFirstSet",
"MySecondSet",
"MyThirdSet"
],
"TaskRun": []
}
Now you can run the model with that task:
modelOne -OpenM.SubValues 16 -OpenM.TaskName MyTask -OpenM.TaskRunName MyTask-sub16
and examine history of modeling task run:
http://localhost:4040/api/model/modelOne/task/MyTask/runs
{
"ModelName": "modelOne",
"ModelDigest": "_201208171604590148_",
"Name": "MyTask",
"Txt": [],
"Set": [],
"TaskRun": [
{
"Name": "MyTask-sub16",
"SubCount": 16,
"CreateDateTime": "2019-01-16 04:38:53.0298",
"Status": "s",
"UpdateDateTime": "2019-01-16 04:38:53.0461",
"TaskRunSet": [
{
"Run": {
"Name": "MyTask_sub16_MyFirstSet_2019_01_16_04_38_53_0304_111",
"SubCompleted": 16,
"CreateDateTime": "2019-01-16 04:38:53.0304",
"Status": "s",
"Digest": "1cece5a11d522b6225d7f9cb5afda39a"
},
"SetName": "MyFirstSet"
},
{
"Run": {
"Name": "MyTask_sub16_MySecondSet_2019_01_16_04_38_53_0357_112",
"SubCompleted": 16,
"CreateDateTime": "2019-01-16 04:38:53.0357",
"Status": "s",
"Digest": "4a55cd6614f8f7be439c0776b2a473ab"
},
"SetName": "MySecondSet"
},
{
"Run": {
"Name": "MyTask_sub16_MyThirdSet_2019_01_16_04_38_53_0410_113",
"SubCompleted": 16,
"CreateDateTime": "2019-01-16 04:38:53.0410",
"Status": "s",
"Digest": "d112237f501317422943880eca54d07b"
},
"SetName": "MyThirdSet"
}
]
}
]
- Windows: Quick Start for Model Users
- Windows: Quick Start for Model Developers
- Linux: Quick Start for Model Users
- Linux: Quick Start for Model Developers
- MacOS: Quick Start for Model Users
- MacOS: Quick Start for Model Developers
- Model Run: How to Run the Model
- MIT License, Copyright and Contribution
- Model Code: Programming a model
- Windows: Create and Debug Models
- Linux: Create and Debug Models
- MacOS: Create and Debug Models
- MacOS: Create and Debug Models using Xcode
- Modgen: Convert case-based model to openM++
- Modgen: Convert time-based model to openM++
- Modgen: Convert Modgen models and usage of C++ in openM++ code
- Model Localization: Translation of model messages
- How To: Set Model Parameters and Get Results
- Model Run: How model finds input parameters
- Model Output Expressions
- Model Run Options and ini-file
- OpenM++ Compiler (omc) Run Options
- OpenM++ ini-file format
- UI: How to start user interface
- UI: openM++ user interface
- UI: Create new or edit scenario
- UI: Upload input scenario or parameters
- UI: Run the Model
- UI: Use ini-files or CSV parameter files
- UI: Compare model run results
- UI: Aggregate and Compare Microdata
- UI: Filter run results by value
- UI: Disk space usage and cleanup
- UI Localization: Translation of openM++
-
Highlight: hook to self-scheduling or trigger attribute
-
Highlight: The End of Start
-
Highlight: Enumeration index validity and the
index_errors
option -
Highlight: Simplified iteration of range, classification, partition
-
Highlight: Parameter, table, and attribute groups can be populated by module declarations
- Oms: openM++ web-service
- Oms: openM++ web-service API
- Oms: How to prepare model input parameters
- Oms: Cloud and model runs queue
- Use R to save output table into CSV file
- Use R to save output table into Excel
- Run model from R: simple loop in cloud
- Run RiskPaths model from R: advanced run in cloud
- Run RiskPaths model in cloud from local PC
- Run model from R and save results in CSV file
- Run model from R: simple loop over model parameter
- Run RiskPaths model from R: advanced parameters scaling
- Run model from Python: simple loop over model parameter
- Run RiskPaths model from Python: advanced parameters scaling
- Windows: Use Docker to get latest version of OpenM++
- Linux: Use Docker to get latest version of OpenM++
- RedHat 8: Use Docker to get latest version of OpenM++
- Quick Start for OpenM++ Developers
- Setup Development Environment
- 2018, June: OpenM++ HPC cluster: Test Lab
- Development Notes: Defines, UTF-8, Databases, etc.
- 2012, December: OpenM++ Design
- 2012, December: OpenM++ Model Architecture, December 2012
- 2012, December: Roadmap, Phase 1
- 2013, May: Prototype version
- 2013, September: Alpha version
- 2014, March: Project Status, Phase 1 completed
- 2016, December: Task List
- 2017, January: Design Notes. Subsample As Parameter problem. Completed
GET Model Metadata
- GET model list
- GET model list including text (description and notes)
- GET model definition metadata
- GET model metadata including text (description and notes)
- GET model metadata including text in all languages
GET Model Extras
GET Model Run results metadata
- GET list of model runs
- GET list of model runs including text (description and notes)
- GET status of model run
- GET status of model run list
- GET status of first model run
- GET status of last model run
- GET status of last completed model run
- GET model run metadata and status
- GET model run including text (description and notes)
- GET model run including text in all languages
GET Model Workset metadata: set of input parameters
- GET list of model worksets
- GET list of model worksets including text (description and notes)
- GET workset status
- GET model default workset status
- GET workset including text (description and notes)
- GET workset including text in all languages
Read Parameters, Output Tables or Microdata values
- Read parameter values from workset
- Read parameter values from workset (enum id's)
- Read parameter values from model run
- Read parameter values from model run (enum id's)
- Read output table values from model run
- Read output table values from model run (enum id's)
- Read output table calculated values from model run
- Read output table calculated values from model run (enum id's)
- Read output table values and compare model runs
- Read output table values and compare model runs (enun id's)
- Read microdata values from model run
- Read microdata values from model run (enum id's)
- Read aggregated microdata from model run
- Read aggregated microdata from model run (enum id's)
- Read microdata run comparison
- Read microdata run comparison (enum id's)
GET Parameters, Output Tables or Microdata values
- GET parameter values from workset
- GET parameter values from model run
- GET output table expression(s) from model run
- GET output table calculated expression(s) from model run
- GET output table values and compare model runs
- GET output table accumulator(s) from model run
- GET output table all accumulators from model run
- GET microdata values from model run
- GET aggregated microdata from model run
- GET microdata run comparison
GET Parameters, Output Tables or Microdata as CSV
- GET csv parameter values from workset
- GET csv parameter values from workset (enum id's)
- GET csv parameter values from model run
- GET csv parameter values from model run (enum id's)
- GET csv output table expressions from model run
- GET csv output table expressions from model run (enum id's)
- GET csv output table accumulators from model run
- GET csv output table accumulators from model run (enum id's)
- GET csv output table all accumulators from model run
- GET csv output table all accumulators from model run (enum id's)
- GET csv calculated table expressions from model run
- GET csv calculated table expressions from model run (enum id's)
- GET csv model runs comparison table expressions
- GET csv model runs comparison table expressions (enum id's)
- GET csv microdata values from model run
- GET csv microdata values from model run (enum id's)
- GET csv aggregated microdata from model run
- GET csv aggregated microdata from model run (enum id's)
- GET csv microdata run comparison
- GET csv microdata run comparison (enum id's)
GET Modeling Task metadata and task run history
- GET list of modeling tasks
- GET list of modeling tasks including text (description and notes)
- GET modeling task input worksets
- GET modeling task run history
- GET status of modeling task run
- GET status of modeling task run list
- GET status of modeling task first run
- GET status of modeling task last run
- GET status of modeling task last completed run
- GET modeling task including text (description and notes)
- GET modeling task text in all languages
Update Model Profile: set of key-value options
- PATCH create or replace profile
- DELETE profile
- POST create or replace profile option
- DELETE profile option
Update Model Workset: set of input parameters
- POST update workset read-only status
- PUT create new workset
- PUT create or replace workset
- PATCH create or merge workset
- DELETE workset
- POST delete multiple worksets
- DELETE parameter from workset
- PATCH update workset parameter values
- PATCH update workset parameter values (enum id's)
- PATCH update workset parameter(s) value notes
- PUT copy parameter from model run into workset
- PATCH merge parameter from model run into workset
- PUT copy parameter from workset to another
- PATCH merge parameter from workset to another
Update Model Runs
- PATCH update model run text (description and notes)
- DELETE model run
- POST delete model runs
- PATCH update run parameter(s) value notes
Update Modeling Tasks
Run Models: run models and monitor progress
Download model, model run results or input parameters
- GET download log file
- GET model download log files
- GET all download log files
- GET download files tree
- POST initiate entire model download
- POST initiate model run download
- POST initiate model workset download
- DELETE download files
- DELETE all download files
Upload model runs or worksets (input scenarios)
- GET upload log file
- GET all upload log files for the model
- GET all upload log files
- GET upload files tree
- POST initiate model run upload
- POST initiate workset upload
- DELETE upload files
- DELETE all upload files
Download and upload user files
- GET user files tree
- POST upload to user files
- PUT create user files folder
- DELETE file or folder from user files
- DELETE all user files
User: manage user settings
Model run jobs and service state
- GET service configuration
- GET job service state
- GET disk usage state
- POST refresh disk space usage info
- GET state of active model run job
- GET state of model run job from queue
- GET state of model run job from history
- PUT model run job into other queue position
- DELETE state of model run job from history
Administrative: manage web-service state
- POST a request to refresh models catalog
- POST a request to close models catalog
- POST a request to close model database
- POST a request to delete the model
- POST a request to open database file
- POST a request to cleanup database file
- GET the list of database cleanup log(s)
- GET database cleanup log file(s)
- POST a request to pause model run queue
- POST a request to pause all model runs queue
- PUT a request to shutdown web-service