25
25
26
26
27
27
def _sklearn_to_dict (model ):
28
+ # As of Viya 3.4 model registration fails if character fields are longer
29
+ # than 1024 characters
30
+ DESC_MAXLEN = 1024
31
+
32
+ # As of Viya 3.4 model registration fails if user-defined properties are
33
+ # longer than 512 characters.
34
+ PROP_MAXLEN = 512
35
+
28
36
# Convert Scikit-learn values to built-in Model Manager values
29
37
mappings = {'LogisticRegression' : 'Logistic regression' ,
30
38
'LinearRegression' : 'Linear regression' ,
31
39
'SVC' : 'Support vector machine' ,
32
40
'GradientBoostingClassifier' : 'Gradient boosting' ,
41
+ 'XGBClassifier' : 'Gradient boosting' ,
42
+ 'XGBRegressor' : 'Gradient boosting' ,
33
43
'RandomForestClassifier' : 'Forest' ,
34
44
'DecisionTreeClassifier' : 'Decision tree' ,
35
45
'DecisionTreeRegressor' : 'Decision tree' ,
36
46
'classifier' : 'Classification' ,
37
47
'regressor' : 'Prediction' }
38
48
49
+ if hasattr (model , '_final_estimator' ):
50
+ estimator = type (model ._final_estimator )
51
+ else :
52
+ estimator = type (model )
53
+
39
54
# Can tell if multi-class .multi_class
40
55
result = dict (
41
- description = str (model ),
42
- algorithm = mappings .get (type ( model ) .__name__ , type ( model ) .__name__ ),
56
+ description = str (model )[: DESC_MAXLEN ] ,
57
+ algorithm = mappings .get (estimator .__name__ , estimator .__name__ ),
43
58
scoreCodeType = 'ds2MultiType' ,
44
59
trainCodeType = 'Python' ,
45
60
function = mappings .get (model ._estimator_type , model ._estimator_type ),
46
61
tool = 'Python %s.%s'
47
62
% (sys .version_info .major , sys .version_info .minor ),
48
- properties = [{'name' : k , 'value' : v }
63
+ properties = [{'name' : str (k )[:PROP_MAXLEN ],
64
+ 'value' : str (v )[:PROP_MAXLEN ]}
49
65
for k , v in model .get_params ().items ()]
50
66
)
51
67
@@ -156,9 +172,9 @@ def register_model(model, name, project, repository=None, input=None,
156
172
files .append ({'name' : 'dmcas_packagescorecode.sas' ,
157
173
'file' : mas_module .score_code (),
158
174
'role' : 'Score Code' })
159
- files .append ({'name' : 'dmcas_espscorecode .sas' ,
160
- 'file' : mas_module .score_code (dest = 'ESP ' ),
161
- 'role' : 'Score Code ' })
175
+ files .append ({'name' : 'dmcas_epscorecode .sas' ,
176
+ 'file' : mas_module .score_code (dest = 'CAS ' ),
177
+ 'role' : 'score ' })
162
178
163
179
model ['inputVariables' ] = [var .as_model_metadata ()
164
180
for var in mas_module .variables
@@ -203,7 +219,10 @@ def register_model(model, name, project, repository=None, input=None,
203
219
return model
204
220
205
221
206
- def publish_model (model , destination , code = None , max_retries = 60 ,
222
+ def publish_model (model ,
223
+ destination ,
224
+ code = None ,
225
+ max_retries = 60 ,
207
226
replace = False , ** kwargs ):
208
227
"""Publish a model to a configured publishing destination.
209
228
@@ -248,7 +267,15 @@ def publish_model(model, destination, code=None, max_retries=60,
248
267
def submit_request ():
249
268
# Submit a publishing request
250
269
if code is None :
251
- publish_req = mm .publish_model (model , destination , ** kwargs )
270
+ dest_obj = mp .get_destination (destination )
271
+
272
+ if dest_obj and dest_obj .destinationType == "cas" :
273
+ publish_req = mm .publish_model (model , destination ,
274
+ force = replace ,
275
+ reload_model_table = True )
276
+ else :
277
+ publish_req = mm .publish_model (model , destination ,
278
+ force = replace )
252
279
else :
253
280
publish_req = mp .publish_model (model , destination ,
254
281
code = code , ** kwargs )
@@ -262,6 +289,11 @@ def submit_request():
262
289
# Submit and wait for status
263
290
job = submit_request ()
264
291
292
+ # If model was successfully published and it isn't a MAS module, we're done
293
+ if job .state .lower () == 'completed' \
294
+ and job .destination .destinationType != 'microAnalyticService' :
295
+ return request_link (job ,'self' )
296
+
265
297
# If MAS publish failed and replace=True, attempt to delete the module
266
298
# and republish
267
299
if job .state .lower () == 'failed' and replace and \
0 commit comments