Modifier#
The available modifiers:
|
Modify function to iterate over one given parameter. |
|
Modify function to iterate over the parameters pairwise. |
|
Profile the execution time of a function. |
|
Print the node input to the console. |
|
Print the node output to the console. |
modifier module#
- mmodel.modifier.add_modifier_metadata(name, *args, **kwargs)[source]#
Decorator to add metadata to a function.
- mmodel.modifier.format_time(dt, precision)[source]#
Format time in seconds to a human-readable string.
- mmodel.modifier.loop_input(parameter: str)[source]#
Modify function to iterate over one given parameter.
- Parameters:
parameter (str) – target parameter to loop The target parameter name is changed to f”{param}_loop”
- mmodel.modifier.parse_fields(format_str)[source]#
Parse the field from the format string.
- Parameters:
format_str (str) – format string
- Returns:
list of fields
The function parses out the field names in the format string. Some field names have slicers or attribute access, such as B0.value, B0[0], B0[0:2]. The function only returns B0 for all these fields. Since there can be duplicated fields after the name split, the function returns unique elements.
- mmodel.modifier.print_inputs(format_str: str, **pargs)[source]#
Print the node input to the console.
- Parameters:
format_str (str) – format string for input and output. The format should be keyword-only.
pargs – keyword arguments for the print function
The names of the parameters are parsed from the format string.
- mmodel.modifier.print_output(format_str: str, **pargs)[source]#
Print the node output to the console.
- Parameters:
format_str (str) – format string for input and output. The format should be keyword-only. The behavior is for keeping consistency with other print modifiers.
pargs – keyword arguments for the print function
The names of the parameters are parsed from the format string. The use of the format_str is different from the input method, as the modifiers do not know the return name of the node. Only one output field is allowed, and the field name is used as the return name.
- mmodel.modifier.profile_time(number=1, repeat=1, verbose=False, precision=2)[source]#
Profile the execution time of a function.
The modifier behaves similarly to the timeit module. However, the modifier does not suppress garbage collection during function execution; therefore, the result might be slightly different.