decision_optimization_client.Client
- class decision_optimization_client.Client
Bases:
objectThe 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(wslib=wslib) # with wslib being the ibm-watson-studio-lib 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, wslib=None, apikey=None, verify=None, iam_url=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)wslib (
object, mandatory in Cloud Pak for Data notebooks) – ibm-watson-studio-lib contextapikey (
str, optional) – IAM api keyverify (
boolean, optional) – override http’s verify property
- create_experiment(experiment=None, folder_id=None, **kwargs)
Creates a decision experiment.
If this method is given an
experimentargument, that experiment is used to initialize the values for the new experiment. Otherwise, the**kwargsare used to initialize aExperiment.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, folder_id=None)
Returns the decision Experiment metadata.
- Parameters:
name – The name of the Experiment to look for
- Returns:
an
ExperimentIf the decision doesn’t exist, you’ll get an error telling you so.
- get_experiments(name=None, folder_id=None, folder_path=None)
Returns the list of decision Experiments.
- Parameters:
name – An optional parameter. If given, only the Experiments for which names match
nameare returned.- Returns:
a list of
Experiment
- stop_solve(container)
Stops the solve for a scenario.
- update_experiment(experiment, new_data=None, folder_id=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
Experimentor a name as string. Thisexperimentis used to indicate which Experiment is to be updated. Ifnew_datais None, the Experiment is updated with the data from thisexperiment.new_data (
Experiment, optional) – AExperimentcontaining metadata to update.