Understanding the IBM Watson Statement

IBM Watson Machine Learning (IBM WML or WML for short) is an IBM product that is available as part of IBM Cloud Pac for Data. Within IBM WML, code is packaged as "services". One can invoke a WML service from a task script.

Note:

Note that the WML service must already be deployed on an IBM Cloud Pak for Data deployment space. To invoke it, you will need:

  • An API Key

  • The URL of the WML server

  • The ID of the WML deployment space

  • The ID of the WML deployment job

The invocation of the WML service is performed through a dedicated Optimization Server worker task named "WatsonML Connector". For more details, please refer to Chapter Implementing Worker Tasks.

As a consequence, the invocation of the WML service in a task script is done with an ExecuteOptimizationServerTaskStatement, as in this example:

    .addStatement(ExecuteOptimizationServerTaskStatement.forTaskId(StringExpression.of("WatsonML Connector"))
        .withInput("wmlUrl", StringExpression.of("The URL of the WML server"))
        .withInput("spaceId", StringExpression.of("The ID of the WML deployment space"))
        .withInput("deploymentId", StringExpression.of("The ID of the WML deployment job"))
        .withInput("inputCollector", ScenarioDataExpression.of(VariableAccessExpression.of("scenarioId")))
        .withInput("outputTables", ListExpression.of(StringExpression.of("Schedule"), StringExpression.of("SolutionSummary")))
        .withOutputScenario("outputCollector", VariableAccessExpression.of("scenarioId"),
            ListExpression.of(StringExpression.of("Schedule"), StringExpression.of("SolutionSummary")))
    )

In this example:

  • The Optimization Server task named "WatsonML Connector" is called.

  • The characteristics of the WML service is passed to this task though the wmlUrl, spaceId, and deploymentId inputs.

  • Two additional inputs are provided, namely inputCollector and outputTables, which contain the data of a scenario and the list of tables in the scenario that may be modified by the WML service, respectively.

  • The modified scenario is taken from the task outputCollector output.

For more details, please refer to Section Understanding Optimization Server Statements.

When the task that contains the above statement is executed, an Optimization Server worker process that implements the WatsonML Connector worker task must be running. This can be done by running the corresponding Docker image using the file deployment/docker/app/docker-compose-wml-worker.yml.

This requires setting the value of your API Key in an environment variable named IBM_WML_API_KEY, which is typically achieved using the following commands:

$ export IBM_WML_API_KEY=your-api-key
$ cd deployment/docker/app
$ docker compose -f docker-compose-wml-worker.yml up -d