Decision Optimization

Decision Optimization

Delivers prescriptive analytics capabilities and decision intelligence to improve decision-making.

 View Only

Use code snippets in Decision Optimization experiments to help build your model in watsonx.ai and Cloud Pak for Data

By Shirley de Jonk posted Thu March 06, 2025 09:14 AM

  

When creating models in the Build model view of a Decision Optimization experiment, have you ever wished that you didn't have to type in the same basic code that is needed for all models?

Well now you can use code snippets in Decision Optimization experiments in watsonx.ai as a Service or Cloud Pak for Data as a Service, so that you don't have to type in all the code from scratch.

When you create a model in an experiment, you start by definining your tables in the Prepare Data view. For example, the following image shows some of the data tables that are defined for a Supply and Demand Planning model. There are 12 input data tables in this example scenario.


When you then move to the Build model view to create for example an OPL model, you then have to create OPL tuples for all of your tables to define the input data structures. This is quite tedious as you must make sure you use the same column names as your data tables. Similarly, to create a Python model, you have to define data frames using the exact column names.

However with code snippets this task is now simplified! The exact column names are already provided with the right syntax to define your data structures in a code snippet. You can copy all or parts of the code snippet or insert the whole code snippet into your model. This helps to speed-up coding and thus model building.
 
For both Python and OPL models,  click the Code snippet icon in the menu bar in your experiment scenario, and a code snippet pane opens where you can choose from the available code snippets.  

OPL example

The following image shows the tuples that are provided automatically when you select the OPL input tuples code snippet in the Build model view for the previous supply and demand example with 12 input data tables in the Prepare Data view.



As you can see here, with several tables, having these code snippets generated for you is very useful and time saving because the correct column names etc are automatically provided. The tuple prefix can be modified so that you can define the naming convention of your tuples, before adding them to your model. All you have to do is verify the type. For example, you might want to define a tuple with integer type instead of float. The type can be modified in the code snippet pane or in the model after you have included the code snippet.


Python example
The following image shows the data frames that are provided automatically when you select the Data frames code snippet in the Build model view for the same supply and demand example with 12 input data tables in the Prepare Data view.

Again you can see here, with several tables, having these code snippets generated for you is very useful and time saving because the correct column names etc are automatically provided in the data frame definition statements.

For Python models, you can also select a Progress Listener code snippet to add to your model so that you can monitor the solution progress when you solve the model.

Model skeleton code snippets are also provided for both OPL and Python models. More code snippets are being developed, and are coming soon, so watch this space!

For more information, see the watsonx.ai as a Service documentation or the Cloud Pak for Data as a Service documentation.


#watsonx.ai
#CloudPakforData#Decisionoptimization#Watsonstudio




0 comments
16 views

Permalink