decision_optimization_client.Client

class decision_optimization_client.Client

Bases: object

The class to access Experiments in Decision Optimization.

To use the client in Cloud Pak For Data:

from decision_optimization_client import Client
client = Client()

To use the client in Cloud Pak For Data as a Service:

from decision_optimization_client import Client
client = Client(pc=pc) # with pc being the project context

or if you want to access another project:

from decision_optimization_client import Client
client = Client(project_id="project id string",
                authorization="bearer authorization token")

Then use the following method to retrieve one or more experiments:

Example

To return the list of experiments:

from decision_optimization_client import Client

client = Client()
# get list of available experiments
containers = client.get_experiments()
__init__(api_url=None, authorization=None, refresh_token=None, project_id=None, max_retries=3, proxies=None, cognitive_url=None, pc=None, apikey=None, verify=None)

Creates a new Decision Optimization scenario client.

Parameters
  • authorization (str, optional) – The authorization key (to set the value of the bearer token (that you get from your api key when using iam).

  • max_retries (int, optional) – maximum number of retries. Default is 3.

  • proxies (dict, optional) – Optional dictionary mapping protocol to the URL of the proxy. (more info: https://docs.python-requests.org/en/master/user/advanced/#proxies)

  • pc (object, mandatory only in Cloud Pak for Data as a Service) – Project context

  • apikey (str, optional) – IAM api key

  • verify (boolean, optional) – override http’s verify property

create_experiment(experiment=None, **kwargs)

Creates a decision experiment.

If this method is given an experiment argument, that experiment is used to initialize the values for the new experiment. Otherwise, the **kwargs are used to initialize a Experiment.

Example

Creates a Experiment using the Experiment name passed as kwargs:

experiment = client.create_experiment(name='test experiment')

Creates a Experiment using the experiment passed as a Experiment:

meta = Experiment(name=’test experiment’) experiment = client.create_experiment(experiment=meta)

Parameters
  • experiment (Experiment) – The Experiment metadata used as initial data.

  • **kwargs – kwargs used to initialize the Experiment

Returns

The decision Experiment as a Experiment

get_experiment(name=None, id=None)

Returns the decision Experiment metadata.

Parameters

name – The name of the Experiment to look for

Returns

an Experiment If the decision doesn’t exist, you’ll get an error telling you so.

get_experiments(name=None)

Returns the list of decision Experiments.

Parameters

name – An optional parameter. If given, only the Experiments for which names match name are returned.

Returns

a list of Experiment

stop_solve(container)

Stops the solve for a scenario.

update_experiment(experiment, new_data=None)

Updates decision model metadata.

Examples

Updates a Experiment with new data using name:

>>> new = Experiment()
>>> new.description = "new description"
>>> client.update_experiment(decision_model_name, new)

Gets a Experiment, then replaces description:

>>> experiment = client.get_experiment(id=guid)
>>> experiment.description = "new description"
>>> client.update_experiment(experiment)

Gets a Experiment by name, then replaces description:

>>> experiment = client.get_experiment(name='decision model name')
>>> experiment.description = "new description"
>>> client.update_experiment(experiment)
Parameters
  • experiment – A Experiment or a name as string. This experiment is used to indicate which Experiment is to be updated. If new_data is None, the Experiment is updated with the data from this experiment.

  • new_data (Experiment, optional) – A Experiment containing metadata to update.