0 / 0
Configuring environments and adding Python extensions
Last updated: Nov 29, 2023
Decision Optimization experiment Python and CPLEX runtime versions and Python extensions

You can change your default environment for Python and CPLEX in the experiment Overview.

Before you begin

Required permissions
To view environments, you can have any role in a deployment space. To edit or create environments, you must have the Editor or Admin role in the space. For more information, see Deployment space collaborator roles and permissions.

About this task

This video provides a visual method to learn the concepts and tasks in this documentation.

After you load the example in your Decision Optimization experiment, you can follow the video.

Video disclaimer: Some minor steps and graphical steps in this video might differ from your platform. The user interface is also frequently improved.

When you use the experiment UI, the necessary environments are created for you automatically. However, you can, configure the environment to be used for your solve, by changing the default environment. This environment will then be applied to all scenarios in your experiment. The environment will depend on your model type: Python, OPL, CPLEX, CPO, or Modeling Assistant.

Python is used to run Decision Optimization models formulated in DOcplex in Decision Optimization experiments. Modeling Assistant models also use Python because DOcplex code is generated when models are run or deployed. Models formulated in OPL or in specific file formats for CPLEX or CP Optimizer, such as LP or CPO formats, do not use Python environments.

The Decision Optimization environment currently supports Python 3.10. The default version is Python 3.10.

The following procedure shows you how to change the default environment for DOcplex and Modeling Assistant models. This can be useful for checking if your model works with the latest version of CPLEX, or for testing your model with larger data sets that require more hardware. Or perhaps you need to update the Python version or want to include some particular Python libraries using Python extensions.

To select a different run environment for a particular scenario, see Selecting a different run environment for a particular scenario.

Procedure

To change the default environment for DOcplex and Modeling Assistant models:

  1. Open the Overview, click information icon to open the Information pane, and select the Environments tab.

    Environment tab of information pane

  2. Expand the environment section according to your model type. For Python and Modeling Assistant models, expand Python environment. You can see the default Python environment (if one exists). To change the default environment for OPL, CPLEX, or CPO models, expand the appropriate environment section according to your model type and follow this same procedure.
  3. Expand the name of your environment, and select a different Python environment.
  4. Optional: To create a new environment:
    1. Select New environment for Python.
      A new window opens for you to define your new environment. New environment window showing empty fields
    2. Enter a name, and select a CPLEX version, hardware specification, copies (number of nodes), Python version and (optionally) you can set Associate a Python extension to On to include any Python libraries that you want to add.
    3. Click New Python extension.
    4. Enter a name for your extension in the new Create a Python extension window that opens, and click Create.
    5. In the new Configure Python extension window that opens, you can set YAML code to On and enter or edit the provided YAML code.
      For example, use the provided template to add the custom libraries:
      # Modify the following content to add a software customization to an environment.
      # To remove an existing customization, delete the entire content and click Apply.
      
      # Add conda channels on a new line after defaults, indented by two spaces and a hyphen.
      channels:
        - defaults
      
      # To add packages through conda or pip, remove the comment on the following line.
      # dependencies:
      
      # Add conda packages here, indented by two spaces and a hyphen.
      # Remove the comment on the following line and replace sample package name with your package name:
      #  - a_conda_package=1.0
      
      # Add pip packages here, indented by four spaces and a hyphen.
      # Remove the comments on the following lines  and replace sample package name with your package name.
      #  - pip:
      #    - a_pip_package==1.0

      You can also click Browse to add any Python libraries.

      For example, this image shows a dynamic programming Python library that is imported and YAML code set to On.Configure Python extension window showing YAML code and a Dynamic Programming library included

      Click Done.

    6. Click Create in the New environment window.
    Your chosen (or newly created) environment appears as ticked in the Python environments drop-down list in the Environments tab. The tick indicates that this is the default Python environment for all scenarios in your experiment.
  5. Select Manage experiment environments to see a detailed list of all existing environments for your experiment in the Environments tab.
    Manage experiment environment with two environments and drop-down menu.

    You can use the options provided by clicking the three vertical dots next to an environment to Edit, Set as default, Update in a deployment space or Delete the environment. You can also create a New environment from the Manage experiment environments window, but creating a new environment from this window does not make it the default unless you explicitly set is as the default.

    Updating your environment for Python or CPLEX versions: Python versions are regularly updated. If however you have explicitly specified an older Python version in your model, you must update this version specification or your models will not work. You can either create a new Python environment, as described earlier, or edit one from Manage experiment environments. This is also useful if you want to select a different version of CPLEX for your default environment.
  6. Click the Python extensions tab.

    Python extensions tab showing created extension

    Here you can view your Python extensions and see which environment it is used in. You can also create a New Python extension or use the options to Edit, Download, and Delete existing ones. If you edit a Python extension that is used by an experiment environment, the environment will be re-created.

    You can also view your Python environments in your deployment space assets and any Python extensions you have added will appear in the software specification.

Selecting a different run environment for a particular scenario

You can choose different environments for individual scenarios on the Environment tab of the Run configuration pane.

About this task

This task is useful if you don't want certain scenarios to use the default environment (this is when more than one Python version is supported, currently Python 3.10 is available). See Run environment tab for more details.

To select a different run environment for a particular scenario, without changing the default for all the other scenarios:

Procedure

  1. Open the Scenario pane and select your scenario in the Build model view.
  2. Click the Configure run icon next to the Run button to open the Run configuration pane and select the Environment tab.
  3. Choose Select run environment for this scenario, choose an environment from the drop-down menu, and click Run.
  4. Open the Overview information pane. You can now see that your scenario has your chosen environment, while other scenarios are not affected by this modification.
Generative AI search and answer
These answers are generated by a large language model in watsonx.ai based on content from the product documentation. Learn more