@@ -224,31 +224,27 @@ def set_queue_adapter(
224
224
225
225
def powerup_by_kwargs (
226
226
original_wf : Workflow ,
227
- add_powerup_module : List [str ] = None ,
228
- ** powerup_kwargs ,
227
+ powerup_dicts : List [dict ],
229
228
):
230
229
"""
231
- apply powerups in the form using a kwargs dictionary of the form:
232
- {
233
- powerup_function_name1 : {parameter1 : value1, parameter2: value2},
234
- powerup_function_name2 : {parameter1 : value1, parameter2: value2},
235
- }
230
+ apply powerups in the form using a list of dictionaries
231
+ [
232
+ {"powerup_name" : powerup_function1, "kwargs": {parameter1 : value1, parameter2: value2} },
233
+ {"powerup_name" : powerup_function2, "kwargs": {parameter1 : value1, parameter2: value2} },
234
+ ]
236
235
237
236
As an example:
238
- power_up_by_kwargs( "add_additional_fields_to_taskdocs" : {
239
- "update_dict" : {"foo" : "bar"}
240
- }
237
+ power_up_by_kwargs([
238
+ {"powerup_name" : "add_additional_fields_to_taskdocs",
239
+ "kwargs: {"update_dict" : {"foo" : "bar"}}}
240
+ ]
241
241
)
242
242
243
243
Args:
244
244
original_wf: workflow that will be changed
245
- add_powerup_module: user_made modules that contain powerups
246
- powerup_kwargs: KWARGS used to apply any power, EXAMPLE:
247
- {"add_modify_incar": {
248
- "modify_incar_params": {
249
- "incar_update": {"KPAR": 8}}
250
- }
251
- }
245
+ powerup_dicts: dictionary containing the powerup_name and kwarg.
246
+ if "." is present in the name it will be imported as a full path
247
+ if not we will use standard atomate modules where the powerups are kept
252
248
253
249
"""
254
250
# a list of possible powerups in atomate (most specific first)
@@ -257,17 +253,27 @@ def powerup_by_kwargs(
257
253
"atomate.qchem.powerups" ,
258
254
"atomate.common.powerups" ,
259
255
]
260
- # user can add new modules containing custom powerups
261
- if add_powerup_module is not None :
262
- powerup_modules = add_powerup_module + powerup_modules
263
-
264
- for k , v in powerup_kwargs .items ():
265
- for module_name in powerup_modules :
266
- try :
267
- module = import_module (module_name )
268
- powerup = getattr (module , k )
269
- original_wf = powerup (original_wf , ** v )
270
- break
271
- except Exception :
272
- pass
256
+
257
+ for pd in powerup_dicts :
258
+ name = pd ["powerup_name" ]
259
+ kwargs = pd ["kwargs" ]
260
+ found = False
261
+ if "." in name :
262
+ module_name , method_name = name .rsplit ("." , 1 )
263
+ module = import_module (module_name )
264
+ powerup = getattr (module , method_name )
265
+ original_wf = powerup (original_wf , ** kwargs )
266
+ found = True
267
+ else :
268
+ for module_name in powerup_modules :
269
+ try :
270
+ module = import_module (module_name )
271
+ powerup = getattr (module , name )
272
+ original_wf = powerup (original_wf , ** kwargs )
273
+ found = True
274
+ break
275
+ except Exception :
276
+ pass
277
+ if not found :
278
+ raise RuntimeError ("Could not find powerup {}." .format (name ))
273
279
return original_wf
0 commit comments