docplex.mp.context module

class docplex.mp.context.Context(**kwargs)[source]

Bases: docplex.mp.context.BaseContext

The context used to control the behavior of solve engine.

cplex_parameters

A docplex.mp.params.parameters.RootParameterGroup to store CPLEX parameters.

solver.auto_publish

If True, a model being solved will automatically publish all publishable items (solve_details, json_solution).

solver.auto_publish.solve_details

If True, solve details are automatically published when docplex.mp.model.Model.solve() is called. The default value is True.

solver.auto_publish.json_solution

If True, the solution is automatically published when docplex.mp.model.Model.solve() is called. The solution is saved as an output attachment whose name is solution.json. The default value is False, unless the Python script is run on the DOcplexcloud service.

solver.log_output

This attribute can have the following values:

  • True: When True, logs are printed to sys.out.
  • False: When False, logs are not printed.
  • A file-type object: Logs are printed to that file-type object.
solver.docloud

The parent node for attributes controlling the solve on Decision Optimization on Cloud.

solver.docloud.url

The DOcplexcloud service URL.

solver.docloud.key

The DOcplexcloud service API key.

solver.docloud.ignored_keys

A collection or a string that is a comma-separated list of values to ignore. If any key passed has a value in this list, the key is ignored.

solver.docloud.ignored_urls

A collection or a string that is a comma-separated list of values to ignore. If any url passed has a value in this list, the url is ignored.

solver.docloud.run_deterministic

Specific engine parameters are uploaded to keep the run deterministic.

solver.docloud.verbose

Makes the connector verbose.

solver.docloud.timeout

The timeout for requests.

solver.docloud.waittime

The wait time to wait for jobs to finish.

solver.docloud.verify

If True, verifies SSL certificates.

solver.docloud.log_requests

If True, the REST requests are logged.

solver.docloud.log_poll_interval

The interval for log polling.

solver.docloud.progress_poll_interval

The interval for progress polling.

solver.docloud.exchange_format

The exchange format to use. When setting the format, you can use the following strings: “lp”. When getting the format, the property type is docplex.mp.format.ExchangeFormat.

static make_default_context(file_list=None, logger=None, **kwargs)[source]

Creates a default context.

If file_list is a string, then it is considered to be the name of a config file to be read.

If file_list is a list, it is considered to be a list of names of a config files to be read.

if file_list is None or not specified, the following files are read if they exist:

  • the PYTHONPATH is searched for the following files:

    • cplex_config.py
    • cplex_config_<hostname>.py
    • docloud_config.py

Python files are evaluated with a context object in the current scope, and you set values from this context:

context.solver.docloud.url = 'http://testing.blabla.ibm.com'
context.solver.docloud.key = 'This is an api_key'
context.cplex_parameters.emphasis.memory = 1
context.cplex_parameters.emphasis.mip = 2
Parameters:
read_settings(file_list=None, logger=None)[source]

Reads settings for a list of files.

If file_list is a string, then it is considered to be the name of a config file to be read.

If file_list is a list, it is considered to be a list of names of config files to be read.

if file_list is None or not specified, the following files are read if they exist:

  • the PYTHONPATH is searched for the following files:

    • cplex_config.py
    • cplex_config_<hostname>.py
    • docloud_config.py

Python files are evaluated with a context object in the current scope, and you set values from this context:

context.solver.docloud.url = 'http://testing.blabla.ibm.com'
context.solver.docloud.key = 'This is an api_key'
context.cplex_parameters.emphasis.memory = 1
context.cplex_parameters.emphasis.mip = 2
Parameters:file_list – The list of config files to read.
update(kwargs, create_missing_nodes=False)[source]

Updates this context from child parameters specified in kwargs.

The following keys are recognized:

  • cplex_parameters: A set of CPLEX parameters to use instead of the parameters defined as context.cplex_parameters.
  • agent: Changes the context.solver.agent parameter.
    Supported agents include:
    • docloud: forces the solve operation to use DOcplexcloud
    • local: forces the solve operation to use native CPLEX
  • url: Overwrites the URL of the DOcplexcloud service defined by context.solver.docloud.url.
  • key: Overwrites the authentication key of the DOcplexcloud service defined by context.solver.docloud.key.
  • log_output: if True, solver logs are output to stdout.
    If this is a stream, solver logs are output to that stream object. Overwrites the context.solver.log_output parameter.
Parameters:
  • kwargs – A dict containing keyword args to use to update this context.
  • create_missing_nodes – When a keyword arg specify a parameter that is not already member of this context, creates the parameter if create_missing_nodes is True.