-
Notifications
You must be signed in to change notification settings - Fork 308
/
isCompatible.m
248 lines (217 loc) · 8.71 KB
/
isCompatible.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
function compatibleStatus = isCompatible(solverName, printLevel, specificSolverVersion)
% determine the compatibility status of a solver based on the file compatMatrix.rst
%
% USAGE:
% compatibleStatus = isCompatible(solverName, printLevel, specificSolverVersion)
%
% INPUT:
% solverName: Name of the solver
% printLevel: verbose level (default: 0)
% specificSolverVersion: string with specific solver version (example: '12.7.1' or '6.5.1')
%
% OUTPUT:
% compatibleStatus: compatibility status
%
% * 0: not compatible with the COBRA Toolbox (tested)
% * 1: compatible with the COBRA Toolbox (tested)
% * 2: unverified compatibility with the COBRA Toolbox (not tested)
%
% .. Author: - Laurent Heirendt, August 2017
%
global CBTDIR
% define a default printLevel
if nargin < 2
printLevel = 1;
end
% determine specific version
if nargin < 3
specificSolverVersion = '';
end
% define the same interface for tomlab and quadMinos
if strcmp(solverName, 'tomlab_snopt')
solverName = 'tomlab_cplex';
end
if strcmp(solverName, 'quadMinos')
solverName = 'dqqMinos';
end
if strcmp(solverName, 'lindo_old')
solverName = 'lindo_legacy';
end
% default compatibility status (untested)
compatibleStatus = 2;
% check if the solver and the matlab version are compatible
compatMatrixFile = [CBTDIR filesep 'docs' filesep 'source' filesep 'installation' filesep 'compatMatrix.rst'];
% read in the file with the compatibility matrix
persistent C;
persistent compatMatrix;
persistent testedOS;
untestedFlag = false;
if isempty(compatMatrix)
C = {};
compatMatrix = {};
testedOS = {};
fid = fopen(compatMatrixFile);
lineCount = 0;
while 1
% save the previous line
if lineCount > 0
tline_prev = tline;
end
% read in a new line
tline = fgetl(fid);
if ~ischar(tline), break; end
% skip a table line
if ~isempty(strfind(tline, '+-------------------+')) || ~isempty(strfind(tline, '+====================+'))
tline = '';
end
% if the line is not empty, read it in
if length(tline) > 1
if printLevel > 1
disp(tline);
end
% replace the markers
tline = strrep(tline, '|x|', ':x:');
tline = strrep(tline, '|white_check_mark|', ':white_check_mark:');
tline = strrep(tline, '|warning|', ':warning:');
if strcmp(tline(1), '|')
% split the line at the vertical bar
Cpart = strsplit(tline, '|');
Cpart = Cpart(2:end-1);
% convert incompatible flag
Cpart = strrep(Cpart, ':x:', '0');
% convert compatible flag
Cpart = strrep(Cpart, ':white_check_mark:', '1');
% convert untested flag
Cpart = strrep(Cpart, ':warning:', '2');
C{end+1} = strtrim(Cpart);
else
if ~isempty(C)
compatMatrix{end+1} = C;
C = {};
end
if strcmp(tline(1:2), '~~')
testedOS{end+1} = strtrim(tline_prev);
end
end
end
lineCount = lineCount + 1;
end
compatMatrix{end+1} = C;
end
% select the compatibility matrix based on the OS
if isunix && ~ismac % linux
tableNb = 1;
resultVERS = system_dependent('getos');
tmp = strsplit(testedOS{tableNb});
if ~isempty(strfind(lower(resultVERS), lower(tmp{2})))
cMatrix = compatMatrix{tableNb};
else
untestedFlag = true;
if printLevel > 0
fprintf([' > The compatibility can only be evaluated on Linux ', tmp{2}, '.\n']);
end
end
elseif ismac % macOS
macpos = find(strncmp(testedOS,'macOS',5));
macOSFound = false;
[~, resultVERS] = unix('sw_vers');
for tableNb = macpos %
tmp = strsplit(testedOS{tableNb});
if ~isempty(strfind(resultVERS, tmp{2}))
cMatrix = compatMatrix{tableNb};
macOSFound = true;
end
end
if ~macOSFound
untestedFlag = true;
if printLevel > 0
fprintf([' > The compatibility can only be evaluated on the following mac OS versions: ', strjoin(testedOS(macpos),', '), '.\n']);
end
end
else % Windows
resultVERS = system_dependent('getos');
for tableNb = length(testedOS)-1:length(testedOS) % loop through the last 2 tables
tmp = strsplit(testedOS{tableNb});
if ~isempty(strfind(resultVERS, tmp{2}))
cMatrix = compatMatrix{tableNb};
break;
else
untestedFlag = true;
if printLevel > 0 && tableNb == length(testedOS)
fprintf([' > The compatibility can only be evaluated on Windows 7 and Windows 10.\n']);
end
end
end
end
if untestedFlag
cMatrix = {};
end
% determine the version of MATLAB and the corresponding column
versionMatlab = ['R' version('-release')];
if ~isempty(cMatrix)
compatMatlabVersions = cMatrix{1}(2:end);
colIndexVersion = strmatch(versionMatlab, compatMatlabVersions);
else
colIndexVersion = [];
end
% any MATLAB version that is not explicitly supported yields a compatibility status of 2
if isempty(colIndexVersion)
compatibleStatus = 2;
if printLevel > 0
fprintf([' > The solver compatibility is not tested with MATLAB ', versionMatlab, '.\n']);
end
else
% replace any underscores in the solvername
solverNameAlias = strrep(upper(solverName), '_', '');
% set the solver version to be checked
if exist('specificSolverVersion', 'var') && ~isempty(specificSolverVersion)
solverVersion = strrep(specificSolverVersion, '.', '');
else
solverVersion = getCobraSolverVersion(solverName, 0);
end
% check compatibility of solver
for i = 1:length(cMatrix)
% save the row of the compatibilitx matrix
row = cMatrix{i};
% determine the name of the solver
solverNameRow = row{1};
solverNameRow = upper(solverNameRow);
solverNameRow = regexprep(solverNameRow, {'\ ', '\.'}, '');
% find the correct row
if strcmpi([solverNameAlias, solverVersion], solverNameRow)
% retrieve the compatibility status from the table
compatibilityBoolean = row{colIndexVersion + 1};
% define output of solverVersion
if ~isempty(solverVersion),
txtSolverVersion = [' (version ', solverVersion, ')'];
else
txtSolverVersion = '';
end
% determine the compatibility status
if strcmpi(compatibilityBoolean, '1')
compatibleStatus = 1;
if printLevel > 0
fprintf([' > ', lower(solverName), txtSolverVersion, ' is compatible and fully tested with MATLAB ', versionMatlab, ' on your operating system.\n']);
end
elseif strcmpi(compatibilityBoolean, '0')
compatibleStatus = 0;
if printLevel > 0
fprintf([' > ', lower(solverName), txtSolverVersion, ' is NOT compatible with MATLAB ', versionMatlab, ' on your operating system.\n']);
end
else
compatibleStatus = 2;
if printLevel > 0
fprintf([' > The compatibility of ', upper(solverName), txtSolverVersion, ' is not fully tested and might not be compatible with MATLAB ', versionMatlab, ' on your operating system.\n']);
end
end
end
end
end
% special case: cplex_direct
if strcmp(solverName, 'cplex_direct') && ~verLessThan('matlab', '8.4')
compatibleStatus = 0;
if printLevel > 0
fprintf([' > ', 'cplex_direct is NOT compatible with MATLAB ', versionMatlab, ' on your operating system. Try using the tomlab_cplex interface.\n']);
end
end
end