ibm_cplex not working

867 views
Skip to first unread message

Akhila George

unread,
May 26, 2021, 8:31:53 PM5/26/21
to COBRA Toolbox
Hi,
I installed IBM ILOG CPLEX Optimization studio 12.8 in windows 10. In MATLAB (R2020b), the path is set to cplex\matlab\x64_win64 folder. However, ibm_cplex seems to be not working while running initCobraToolbox. Please see the attached for the details.
Thanks. 
Kind regards,
Akhila

COBRAconfigReport.log

Ronan M.T. Fleming

unread,
May 27, 2021, 6:23:24 AM5/27/21
to COBRA Toolbox
Hi Akhilia,
what is the output from:

solverName = 'ibm_cplex';
solverType = 'LP';
printLevel = 2;
validationLevel = 2;
[solverOK, solverInstalled] = changeCobraSolver(solverName,
solverType, printLevel, validationLevel)

Regards,

Ronan
> --
>
> ---
> You received this message because you are subscribed to the Google Groups "COBRA Toolbox" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to cobra-toolbo...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/cobra-toolbox/75bce47e-5c98-49c6-9b36-6a73477217f1n%40googlegroups.com.



--
--
Mr. Ronan MT Fleming B.V.M.S. Dip. Math. Ph.D.
----------------------------------------------------------------------------
Assistant Professor,
Division of Systems Biomedicine and Pharmacology,
Leiden Academic Centre for Drug Research,
Faculty of Science,
Leiden University.
https://www.universiteitleiden.nl/en/staffmembers/ronan-fleming
&
H2020 Project Coordinator,
Systems Medicine of Mitochondrial Parkinson’s Disease,
http://sysmedpd.eu
&
Senior Lecturer,
School of Medicine,
National University of Ireland, Galway.
----------------------------------------------------------------------------
Peer-reviewed publications: https://goo.gl/FZPG23
Mobile: +353 852 109 806
Skype: ronan.fleming
----------------------------------------------------------------------------
(This message is confidential and may contain privileged information.
It is intended for the named recipient only. If you receive it in
error please notify me and permanently delete the original message and
any copies.)

Akhila George

unread,
May 27, 2021, 8:01:59 PM5/27/21
to cobra-...@googlegroups.com
Hi Ronan,
Please see the following output. Thanks.

solverOK =

  logical

   0
solverInstalled =

  logical

   0

Kind regards,
Akhila

You received this message because you are subscribed to a topic in the Google Groups "COBRA Toolbox" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/cobra-toolbox/3uNJxvMwzbI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to cobra-toolbo...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cobra-toolbox/CAOivGYuTDtYemDbwqYOLEObGCYrJZOKPri8EdEyGNeuzUA882Q%40mail.gmail.com.

Akhila George

unread,
Jun 7, 2021, 11:36:02 PM6/7/21
to cobra-...@googlegroups.com
Hi Ronan,
How can I fix this issue?
Thanks.

Kind regards,
Akhila

Ronan M.T. Fleming

unread,
Jun 8, 2021, 5:14:44 AM6/8/21
to COBRA Toolbox
Hi Akhila,

run

updateCobraToolbox()

then
run

solverName = 'ibm_cplex';
solverType = 'LP';
printLevel = 2;
validationLevel = 2;
[solverOK, solverInstalled] = changeCobraSolver(solverName,
solverType, printLevel, validationLevel)

My output is below:
[solverOK, solverInstalled] = changeCobraSolver(solverName,solverType,
printLevel, validationLevel)

> changeCobraSolver: IBM ILOG CPLEX interface added to MATLAB path.
> ibm_cplex (version 1210) is compatible and fully tested with MATLAB
R2021a on your operating system.
Version identifier: 12.10.0.0 | 2019-11-26 | 843d4de
CPXPARAM_Output_WriteLevel 3
CPXPARAM_Output_CloneLog -1
Found incumbent of value 0.000000 after 0.01 sec. (0.00 ticks)

Root node processing (before b&c):
Real time = 0.01 sec. (0.00 ticks)
Parallel b&c, 8 threads:
Real time = 0.00 sec. (0.00 ticks)
Sync time (average) = 0.00 sec.
Wait time (average) = 0.00 sec.
------------
Total (root+branch&cut) = 0.01 sec. (0.00 ticks)

solverOK =

logical

1


solverInstalled =

logical

1
> To view this discussion on the web visit https://groups.google.com/d/msgid/cobra-toolbox/CAKjGROH3v3_oTBGMHSz0cv%2BGF4B_eBB3KT34_%2BQ8-EVB2%3D%2BSbw%40mail.gmail.com.

Akhila George

unread,
Jun 8, 2021, 11:10:19 PM6/8/21
to cobra-...@googlegroups.com
Hi Ronan,
I came across the following error while running updateCobraToolbox()

Error using cd
Cannot CD to C:\Program Files\MATLAB\R2020b\toolbox\cobratoolbox\.tmp (Name is
nonexistent or not a directory).

Error in portableGitSetup (line 43)
        cd([CBTDIR filesep tmpFolder]);

Error in installGitBash (line 32)
            portableGitSetup(gitBashVersion, 0);

Error in updateGitBash (line 81)
                installGitBash();

Error in updateCobraToolbox (line 20)
        updateGitBash(fetchAndCheckOnly);

How can I fix this?
Kind regards,
Akhila

Ronan M.T. Fleming

unread,
Jun 9, 2021, 5:06:13 AM6/9/21
to COBRA Toolbox
Hi Akhila,
reading the code and debugging it. e.g. I see the lines:

% define the name of the temporary folder
tmpFolder = '.tmp';

% create .tmp if not already present
if ~exist(tmpFolder, 'dir')
mkdir(tmpFolder);
end

% determine architecture
archstr = computer('arch');
archBit = archstr(end-1:end);

% save the current directory
currentDir = pwd;

% change to temporary directory
cd([CBTDIR filesep tmpFolder]);

Does the folder exist, are the permissions there to make the folder?
This is an open source project with 250k lines. Try to debug it
yourself and if you find a solution, post it here, or better yet make
the contribution so that it will also be fixed by others. If you are
still stuck, then ask again.
Regards,
Ronan
> To view this discussion on the web visit https://groups.google.com/d/msgid/cobra-toolbox/CAKjGROFbuZiGjGRgHw_Oc69Viu5TiowcUfUOZw6au-5xguUVUw%40mail.gmail.com.

Akhila George

unread,
Jun 9, 2021, 10:13:35 PM6/9/21
to cobra-...@googlegroups.com
Hi Ronan,
The updateCobraToolbox() didn't update the CobraToolbox due to unstaged files, it seems. Then I happened to remove the installation for reinstalling CobraToolbox by following the instructions given for removing legacy installation. But now in gitBash, it says the following:
$ git clone --depth=1 https://github.com/opencobra/cobratoolbox.git cobratoolbox
fatal: destination path 'cobratoolbox' already exists and is not an empty directory.

How can I fix this?  How can I reinstall CobraToolbox.
Thanks for your help.

Kind regards,
Akhila



Ronan M.T. Fleming

unread,
Jun 10, 2021, 6:40:09 AM6/10/21
to COBRA Toolbox
Hi Akhila,
if you have unstaged files it may mean that you have edited some of
the cobra toolbox or put some files in that folder. In that case
updateCobraToolbox() will not overwrite your local changes. It is only
designed to update if one does not have local changes. You have two
options:
1) if you want to just use the cobra toolbox but not make changes to
it, and discard your existing changes, then delete the existing cobra
toolbox folder and install a new version.
2) if you want use and change files in the cobra toolbox (for sharing
with the community later) you need to go this route:
https://opencobra.github.io/cobratoolbox/latest/contributing.html
After you have a fork-cobratoolbox installation then go into the old
cobratoolbox folder and from the command line use:
git status
That will show you the files you changed that you may wish to move
over into the fork-cobratoolbox version.
Regards,
Ronan
> To view this discussion on the web visit https://groups.google.com/d/msgid/cobra-toolbox/CAKjGROHWu8-oA0d6jY5ixsZRq-CaQPgwRwPmL%2BX6rC9GwKkxAA%40mail.gmail.com.

Akhila George

unread,
Jun 10, 2021, 11:37:34 PM6/10/21
to cobra-...@googlegroups.com
Hi Ronan,
I chose the first option in your mail. Deleted CobraToolbox folder from MATLAB and then cloned the repository again using GitBash. It shows the following error while the current folder is cobratoolbox..
>> initCobraToolbox
Unrecognized function or variable 'initCobraToolbox'.

How shall I fix this? Thanks.
Kind regards,
Akhila


Ronan M.T. Fleming

unread,
Jun 11, 2021, 3:39:21 AM6/11/21
to COBRA Toolbox

Akhila George

unread,
Jun 13, 2021, 8:24:53 PM6/13/21
to cobra-...@googlegroups.com
Thanks, Ronan. I'm able to initialize cobraToolbox by removing custom paths in Matlab. 

Kind regards,
Akhila

Akhila George

unread,
Jun 13, 2021, 8:29:41 PM6/13/21
to cobra-...@googlegroups.com
Hi Ronan,
I got the following output.
>> updateCobraToolbox()
 > Checking for available updates ...
 > Extracting the gitBash archive (this may take a while) ... Done.
 > gitBash folder (C:\Program Files\MATLAB\R2020b\toolbox\cobratoolbox\.tmp\PortableGit-2.13.3) could not be renamed.
 > gitBash successfully installed.
.
 > currentBranch = master.
 > The COBRA Toolbox is up-to-date.
>> solverName = 'ibm_cplex';
>> solverType = 'LP';
>> printLevel = 2;
>> validationLevel = 2;
>> [solverOK, solverInstalled] = changeCobraSolver(solverName,solverType, printLevel, validationLevel)

 > changeCobraSolver: IBM ILOG CPLEX interface added to MATLAB path.
 > The solver compatibility is not tested with MATLAB R2020b.

solverOK =

  logical

   0


solverInstalled =

  logical

   0

Kind regards,
Akhila



Ronan M.T. Fleming

unread,
Jun 13, 2021, 8:33:10 PM6/13/21
to COBRA Toolbox
Hi Akhila,

I don't know. I don't use windows. Try a different solver. Gurobi?

Could some other windows user help Akhila?

Regards,

Ronan
> To view this discussion on the web visit https://groups.google.com/d/msgid/cobra-toolbox/CAKjGROHZ087JTVwT2%3DG2r5VjBGDdUcUW%2Bg8On_YTefZgYOAPPg%40mail.gmail.com.

Ronan M.T. Fleming

unread,
Jun 13, 2021, 8:35:15 PM6/13/21
to COBRA Toolbox
put a breakpoint on this line
https://github.com/opencobra/cobratoolbox/blob/531bc415edab4d1b7c0cd9fd78ac867a706cd6ac/src/base/solvers/getSetSolver/changeCobraSolver.m#L514
then debug it

On Mon, 14 Jun 2021 at 01:32, Ronan M.T. Fleming

Akhila George

unread,
Jun 13, 2021, 10:24:57 PM6/13/21
to cobra-...@googlegroups.com
Thanks. Gurobi is working.

Kind regards,
Akhila

Johannes van Beek

unread,
Jul 14, 2021, 5:07:44 AM7/14/21
to COBRA Toolbox
I encountered the same problem (one difference: Matlab veriosn 2020a) as Akhila running initCobraToolbox and also running other code which calls changeCobraSolver.m. I noticed the following when trying to find the cause:

when reaching
changeCobraSolver.m line 445 and following :
case {'ibm_cplex','cplexlp'}
            try
                ILOGcplex = Cplex('fba');  % Initialize the CPLEX object
                solverOK = true;
            catch ME
                solverOK = false;
            end
            matver=split(version,'.');
            matver=str2double(strcat(char(matver(1)),'.',char(matver(2))));
            if matver < 8.6
                warning('off', 'MATLAB:lang:badlyScopedReturnValue');  % take out warning message
            end

this generates an exception, which is not reported, but  the  exception is caught and solverOK is set to 'false'. If the call to Cplex is commented out at first glance the installation seems to be OK, but problems arise on further calls to Cplex().

The exception is something like:
K>> ILOGcplex = Cplex('fba')
Error using Cplex
Error:File: Cplex.p Line: 942 Column: 0
Identifier 'changedParam' is not a function or a shared variable. To
share 'changedParam' with nested function, initialize it in the current
scope. For more information, see Sharing Variables Between Parent and
Nested Functions. 

at another occasion:
ME = 
  MException with properties:

    identifier: 'MATLAB:lang:IdentifierNotSharedVariableWithNestedScope'
       message: 'Error:File: Cplex.p Line: 942 Column: 0↵Identifier 'changedParam' is not a function or a shared variable. To share 'changedParam' with nested function, initialize it in the current scope. For more information, see Sharing Variables Between Parent and Nested Functions.'
         cause: {}
         stack: [4×1 struct]
    Correction: []

Cplex.p is a content-obscured, executable file and I do not know how to search further.

The problem arises each time Cplex() is called via initCobraToolbox or during other calls to changeCobraSolver.

At one occasion there was also mention of Cplex not being installed or the IBM license server not being reached.

However,  other calls of Cplex functions in matlab code which does not use the cobratoolbox still work well.


Kind Regards,

Hans van Beek

Op maandag 14 juni 2021 om 04:24:57 UTC+2 schreef akhila...@gmail.com:

Ronan M.T. Fleming

unread,
Jul 14, 2021, 7:50:28 AM7/14/21
to COBRA Toolbox
Hi Hans,
here is the same error from something unconnected to cplex:
https://www.programmersought.com/article/27296334458/
They have different cplex interfaces, maybe its just the object
oriented one that is problematic?
Regards,
Ronan
> To view this discussion on the web visit https://groups.google.com/d/msgid/cobra-toolbox/6087f237-7b90-41f0-9767-f809787c32den%40googlegroups.com.



--
--
Mr. Ronan MT Fleming B.V.M.S. Dip. Math. Ph.D.
----------------------------------------------------------------------------
Associate Professor,
School of Medicine,
National University of Ireland, Galway.
&
Assistant Professor,
Division of Systems Biomedicine and Pharmacology,
Leiden Academic Centre for Drug Research,
Faculty of Science,
Leiden University.
https://www.universiteitleiden.nl/en/staffmembers/ronan-fleming
&
H2020 Project Coordinator,
Systems Medicine of Mitochondrial Parkinson’s Disease,
http://sysmedpd.eu

Ronan M.T. Fleming

unread,
Nov 4, 2021, 5:27:12 AM11/4/21
to COBRA Toolbox
Hi Hans,
did you ever find a solution to that issue "Identifier 'changedParam' is not a function or a shared variable."
It has occurred again:
Regards,
Ronan

Ronan M.T. Fleming

unread,
Nov 18, 2021, 3:32:31 PM11/18/21
to COBRA Toolbox
Thanks to Tim Hensen @trjhensen for getting to the bottom of this cplex issue. See here:
Reply all
Reply to author
Forward
0 new messages