How to use DOcplex in Compute Canada cluster
In this tutorial, we will learn how to use DOcplex in Compute Canada cluster. For this, we need to install the IBM ILOG CPLEX Optimization Studio 20.1.0. The version may vary. Here, I am using the 20.1.0 version.
Step 1: Log in to Compute Canada cluster
We can use ssh to connect to the Compute Canada cluster. We can use the following command:
Here, ‘username’ is your user name for the Compute Canada cluster.
Step 2: Download CPLEX
Next, we need to download CPLEX from the IBM website. Depending on the version you downloaded, the file name could be like this: ILOG_COS_20.10_LINUX_X86_64.bin
Step 3: Upload the CPLEX file to the cluster
We can upload the downloaded CPLEX binary file to the cluster using the following command:
scp ILOG_COS_20.10_LINUX_X86_64.bin email@example.com:/home/username/projects/def-mainuser/username
The above command is executed from a terminal where the binary file is located. You may also change the cluster path depending on your need.
Step 4: Make the binary file executable
Now, we have the binary file of CPLEX in the cluster. We need to make the binary file executable. We can do this as follows:
chmod +x ILOG_COS_20.10_LINUX_X86_64.bin
Step 5: Execute the binary file to install CPLEX
Next, we need to execute the binary file to install CPLEX on the cluster as follows:
Now, we just need to follow the instructions as shown in the installation terminal window.
Make sure to provide the installation directory as follows:
This will install CPLEX.
Step 6: Install DOcplex
We want to use the Python API of CPLEX such as DOcplex. For this, we need to load the Python module first. Then we use the virtual environment and activate it to execute the setup python file. The commands are shown below:
module load python
virtualenv — no-download ENV
python /home/username/projects/def-mainuser/satta/opt/ibm/ILOG/CPLEX_Studio201/python/setup.py install
This will also create a new directory “ENV” in the current directory. Finally, we execute the following command to install DOcplex, as follows:
pip install docplex
To exit from the virtual environment, we can use the following command:
Step 7: Final configuration
To access CPLEX, we need to create a personal module. In order to find our installed CPLEX modules, we need to modify the configuration file $HOME/.bashrc so that it points to the root of this hierarchy, by adding the following line:
Now, we need to create a directory structure in which we put the new CPLEX module, as follows:
mkdir -p $HOME/modulefiles/mycplex
We can use cd $HOME and ls commands to see that this directory structure has been created already.
Then, we need to go to the “mycplex” directory as follows:
Now, we create a directory in the current directory as follows:
The name of this directory is the same as the CPLEX version that we have just installed.
In this directory “20.1.0”, we need to upload a file. The file name is “cplex_module.sh”.
Note that depending on the CPLEX version that we have installed we need to change the lines corresponding to the variables “cplexversion” and “studio_root”. Download this file and open a terminal and use the following command to upload this downloaded file to the cluster:
scp cplex_module.sh firstname.lastname@example.org:/home/username/modulefiles/mycplex/20.1.0
Now, we are ready to use DOcplex on Compute Canada cluster.
Interested readers can read the following story to learn how to use DOcplex for solving a linear programming problem (LPP):