Modifiers and shortcuts#
mrfmsim adds additional modifiers and shortcuts specific to the experimental simulation to the mmodel modifiers. See modifier and shortcut tutorial for details. The shortcuts are used to modify the Experiment/Model object directly, which consists of applying modifiers to individual nodes or the model/experiment.
List of modifiers and shortcuts for the mrfmsim and mmodel package.
Modifiers/Shorcuts |
Module |
Description |
---|---|---|
loop_input |
mmodel.modifier |
Modify function to iterate one given parameter. |
zip_loop_inputs |
mmodel.modifier |
Modify function to iterate the parameters pairwise. |
profile_time |
mmodel.modifier |
Profile the execution time of a function. |
print_inputs |
mmodel.modifier |
Print the inputs of the function with units. |
print_output |
mmodel.modifier |
Print the outputs of the function with units. |
Replace the component in the model. |
||
Modify a node using numba jit. |
||
loop_shortcut |
mmodel.shortcut |
Loop over a parameter during the experiment execution. |
print_shortcut |
mmodel.shortcut |
Apply |
modifier
module#
- mrfmsim.modifier.numba_jit(**kwargs)[source]#
Numba jit modifier with keyword arguments.
Add metadata to numba.jit. The numba decorator outputs all the parameters make it hard to read. Use the decorator the same way as numba.jit().
- mrfmsim.modifier.replace_component(replacement: dict, allow_duplicate=False)[source]#
Modify the signature with components.
The modifier modifies the internal model function. The wrapper function is keyword-only. The function by default does not allow duplicated signature. If we want to replace several attributes with a component, the component name cannot exist in the original signature. For example, if we have a function
- def func(a, b, obj):
return a + b, obj
and we want to replace a and b with a component, we cannot name the component “obj”.
In rares that we do want to replace a, b with a component,
- def func(obj):
return obj.a + obj.b, obj
func(obj=obj)
we would have to use “obj_obj” as the component name. The result function is equivalent to
- def func(obj_obj, obj):
return obj_obj.a + obj_obj.b + obj
func(obj_obj=obj, obj=obj)
The behavior is very confusing to users. The solution is to replace the components, but leave the original “obj” signature as it is. In the final signature, the duplicated signatures are combined into one. The solution here is to add a boolean flag allow_duplicate. If the flag is set to True, the function allows duplicated signatures.
The solution, however, leaves another ambiguity. If we indeed want to replace the component with the same name, but use the original name with an attribute:
- def func(obj):
return obj.a + obj.b, obj.obj
func(obj=obj)
We have decided that this behavior is not allowed regardless the flag. Because in this case, in an inspection attempt, it is confusing to understand if the obj is the original obj or an attribute to the new obj. In this case, a new object name should be used.
- Parameters:
replacement (dict[str]) – in the format of {component_object: [replacement_attribute1, replacement_attribute2, …]}