@@ -102,9 +102,6 @@ class StopCriterionReached(Exception):
102
102
"block_size_x" ,
103
103
"block_size_y" ,
104
104
"block_size_z" ,
105
- "ngangs" ,
106
- "nworkers" ,
107
- "vlength" ,
108
105
]
109
106
110
107
@@ -248,9 +245,37 @@ def check_block_size_params_names_list(block_size_names, tune_params):
248
245
UserWarning ,
249
246
)
250
247
248
+ def check_restriction (restrict , params : dict ) -> bool :
249
+ """Check whether a configuration meets a search space restriction."""
250
+ # if it's a python-constraint, convert to function and execute
251
+ if isinstance (restrict , Constraint ):
252
+ restrict = convert_constraint_restriction (restrict )
253
+ return restrict (list (params .values ()))
254
+ # if it's a string, fill in the parameters and evaluate
255
+ elif isinstance (restrict , str ):
256
+ return eval (replace_param_occurrences (restrict , params ))
257
+ # if it's a function, call it
258
+ elif callable (restrict ):
259
+ return restrict (** params )
260
+ # if it's a tuple, use only the parameters in the second argument to call the restriction
261
+ elif (isinstance (restrict , tuple ) and len (restrict ) == 2
262
+ and callable (restrict [0 ]) and isinstance (restrict [1 ], (list , tuple ))):
263
+ # unpack the tuple
264
+ restrict , selected_params = restrict
265
+ # look up the selected parameters and their value
266
+ selected_params = dict ((key , params [key ]) for key in selected_params )
267
+ # call the restriction
268
+ if isinstance (restrict , Constraint ):
269
+ restrict = convert_constraint_restriction (restrict )
270
+ return restrict (list (selected_params .values ()))
271
+ else :
272
+ return restrict (** selected_params )
273
+ # otherwise, raise an error
274
+ else :
275
+ raise ValueError (f"Unkown restriction type { type (restrict )} ({ restrict } )" )
251
276
252
277
def check_restrictions (restrictions , params : dict , verbose : bool ) -> bool :
253
- """Check whether a specific configuration meets the search space restrictions."""
278
+ """Check whether a configuration meets the search space restrictions."""
254
279
if callable (restrictions ):
255
280
valid = restrictions (params )
256
281
if not valid and verbose is True :
@@ -260,40 +285,13 @@ def check_restrictions(restrictions, params: dict, verbose: bool) -> bool:
260
285
for restrict in restrictions :
261
286
# Check the type of each restriction and validate accordingly. Re-implement as a switch when Python >= 3.10.
262
287
try :
263
- # if it's a python-constraint, convert to function and execute
264
- if isinstance (restrict , Constraint ):
265
- restrict = convert_constraint_restriction (restrict )
266
- if not restrict (params .values ()):
267
- valid = False
268
- break
269
- # if it's a string, fill in the parameters and evaluate
270
- elif isinstance (restrict , str ):
271
- if not eval (replace_param_occurrences (restrict , params )):
272
- valid = False
273
- break
274
- # if it's a function, call it
275
- elif callable (restrict ):
276
- if not restrict (** params ):
277
- valid = False
278
- break
279
- # if it's a tuple, use only the parameters in the second argument to call the restriction
280
- elif (isinstance (restrict , tuple ) and len (restrict ) == 2
281
- and callable (restrict [0 ]) and isinstance (restrict [1 ], (list , tuple ))):
282
- # unpack the tuple
283
- restrict , selected_params = restrict
284
- # look up the selected parameters and their value
285
- selected_params = dict ((key , params [key ]) for key in selected_params )
286
- # call the restriction
287
- if not restrict (** selected_params ):
288
- valid = False
289
- break
290
- # otherwise, raise an error
291
- else :
292
- raise ValueError (f"Unkown restriction type { type (restrict )} ({ restrict } )" )
288
+ valid = check_restriction (restrict , params )
289
+ if not valid :
290
+ break
293
291
except ZeroDivisionError :
294
292
logging .debug (f"Restriction { restrict } with configuration { get_instance_string (params )} divides by zero." )
295
293
if not valid and verbose is True :
296
- print (f"skipping config { get_instance_string (params )} , reason: config fails restriction" )
294
+ print (f"skipping config { get_instance_string (params )} , reason: config fails restriction { restrict } " )
297
295
return valid
298
296
299
297
@@ -311,6 +309,9 @@ def f_restrict(p):
311
309
elif isinstance (restrict , MaxProdConstraint ):
312
310
def f_restrict (p ):
313
311
return np .prod (p ) <= restrict ._maxprod
312
+ elif isinstance (restrict , MinProdConstraint ):
313
+ def f_restrict (p ):
314
+ return np .prod (p ) >= restrict ._minprod
314
315
elif isinstance (restrict , MaxSumConstraint ):
315
316
def f_restrict (p ):
316
317
return sum (p ) <= restrict ._maxsum
@@ -1005,6 +1006,9 @@ def to_equality_constraint(restriction: str, params: list[str]) -> Optional[Unio
1005
1006
params_used = list (params_used )
1006
1007
finalized_constraint = None
1007
1008
if try_to_constraint and " or " not in res and " and " not in res :
1009
+ # if applicable, strip the outermost round brackets
1010
+ while parsed_restriction [0 ] == '(' and parsed_restriction [- 1 ] == ')' and '(' not in parsed_restriction [1 :] and ')' not in parsed_restriction [:1 ]:
1011
+ parsed_restriction = parsed_restriction [1 :- 1 ]
1008
1012
# check if we can turn this into the built-in numeric comparison constraint
1009
1013
finalized_constraint = to_numeric_constraint (parsed_restriction , params_used )
1010
1014
if finalized_constraint is None :
@@ -1059,8 +1063,15 @@ def compile_restrictions(restrictions: list, tune_params: dict, monolithic = Fal
1059
1063
# return the restrictions and used parameters
1060
1064
if len (restrictions_ignore ) == 0 :
1061
1065
return compiled_restrictions
1062
- restrictions_ignore = list (zip (restrictions_ignore , (() for _ in restrictions_ignore )))
1063
- return restrictions_ignore + compiled_restrictions
1066
+
1067
+ # use the required parameters or add an empty tuple for unknown parameters of ignored restrictions
1068
+ noncompiled_restrictions = []
1069
+ for r in restrictions_ignore :
1070
+ if isinstance (r , tuple ) and len (r ) == 2 and isinstance (r [1 ], (list , tuple )):
1071
+ noncompiled_restrictions .append (r )
1072
+ else :
1073
+ noncompiled_restrictions .append ((r , ()))
1074
+ return noncompiled_restrictions + compiled_restrictions
1064
1075
1065
1076
1066
1077
def process_cache (cache , kernel_options , tuning_options , runner ):
@@ -1181,7 +1192,7 @@ def correct_open_cache(cache, open_cache=True):
1181
1192
filestr = cachefile .read ().strip ()
1182
1193
1183
1194
# if file was not properly closed, pretend it was properly closed
1184
- if len (filestr ) > 0 and not filestr [- 3 :] == "}\n }" :
1195
+ if len (filestr ) > 0 and not filestr [- 3 :] in [ "}\n }" , "}}}" ] :
1185
1196
# remove the trailing comma if any, and append closing brackets
1186
1197
if filestr [- 1 ] == "," :
1187
1198
filestr = filestr [:- 1 ]
0 commit comments