@@ -1063,6 +1063,7 @@ def to_equality_constraint(
1063
1063
res_dict = dict ()
1064
1064
registered_params = list ()
1065
1065
registered_restrictions = list ()
1066
+ parsed_restrictions_pyatf = list ()
1066
1067
for param in tune_params .keys ():
1067
1068
registered_params .append (param )
1068
1069
for index , (res , params ) in enumerate (parsed_restrictions ):
@@ -1075,12 +1076,11 @@ def to_equality_constraint(
1075
1076
res_dict [param ][1 ].extend (params )
1076
1077
registered_restrictions .append (index )
1077
1078
# combine multiple restrictions into one
1078
- parsed_restrictions_pyatf = list ()
1079
1079
for res_tuple in res_dict .values ():
1080
1080
res , params_used = res_tuple
1081
1081
params_used = list (dict .fromkeys (params_used )) # param_used should only contain unique, dict preserves order
1082
- parsed_restrictions_pyatf .append ((f"def r({ ', ' .join (params_used )} ): return { ' and ' .join (res )} \n " , params_used ))
1083
- return parsed_restrictions_pyatf
1082
+ parsed_restrictions_pyatf .append ((f"def r({ ', ' .join (params_used )} ): return ( { ') and ( ' .join (res )} ) \n " , params_used ))
1083
+ parsed_restrictions = parsed_restrictions_pyatf
1084
1084
else :
1085
1085
# create one monolithic function
1086
1086
parsed_restrictions = ") and (" .join (
@@ -1114,8 +1114,8 @@ def to_equality_constraint(
1114
1114
1115
1115
def compile_restrictions (
1116
1116
restrictions : list , tune_params : dict , monolithic = False , format = None , try_to_constraint = True
1117
- ) -> list [tuple [Union [str , Constraint , FunctionType ], list [str ]]]:
1118
- """Parses restrictions from a list of strings into a list of strings, Functions, or Constraints (if `try_to_constraint`) and parameters used, or a single Function if monolithic is true."""
1117
+ ) -> list [tuple [Union [str , Constraint , FunctionType ], list [str ], Union [ str , None ] ]]:
1118
+ """Parses restrictions from a list of strings into a list of strings, Functions, or Constraints (if `try_to_constraint`) and parameters used and source , or a single Function if monolithic is true."""
1119
1119
# filter the restrictions to get only the strings
1120
1120
restrictions_str , restrictions_ignore = [], []
1121
1121
for r in restrictions :
@@ -1135,10 +1135,10 @@ def compile_restrictions(
1135
1135
# if it's a string, parse it to a function
1136
1136
code_object = compile (restriction , "<string>" , "exec" )
1137
1137
func = FunctionType (code_object .co_consts [0 ], globals ())
1138
- compiled_restrictions .append ((func , params_used ))
1138
+ compiled_restrictions .append ((func , params_used , restriction ))
1139
1139
elif isinstance (restriction , Constraint ):
1140
1140
# otherwise it already is a Constraint, pass it directly
1141
- compiled_restrictions .append ((restriction , params_used ))
1141
+ compiled_restrictions .append ((restriction , params_used , None ))
1142
1142
else :
1143
1143
raise ValueError (f"Restriction { restriction } is neither a string or Constraint { type (restriction )} " )
1144
1144
@@ -1150,9 +1150,10 @@ def compile_restrictions(
1150
1150
noncompiled_restrictions = []
1151
1151
for r in restrictions_ignore :
1152
1152
if isinstance (r , tuple ) and len (r ) == 2 and isinstance (r [1 ], (list , tuple )):
1153
- noncompiled_restrictions .append (r )
1153
+ restriction , params_used = r
1154
+ noncompiled_restrictions .append ((restriction , params_used , restriction ))
1154
1155
else :
1155
- noncompiled_restrictions .append ((r , () ))
1156
+ noncompiled_restrictions .append ((r , [], r ))
1156
1157
return noncompiled_restrictions + compiled_restrictions
1157
1158
1158
1159
0 commit comments