Shortcut#

The shortcuts are used to modify the Experiment/Model object directly. The mrfmsim package provides the following shortcuts:

  • loop_shortcut: loop over a parameter during the experiment execution. The shortcut finds the optimal location in the graph to create the subgraph and create the loop.

  • print_shortcut: automatically apply print_inputs and print_output shortcuts to individual nodes that print out intermediate variable values during node execution.

Loop Shortcut#

The loop shortcut works by locating the first dependency of the parameter in the graph. It then creates a subgraph that contains all the nodes that depend on the parameter. A new experiment is created with the subgraph as a single node, and the node function is an experiment model. When multiple parameters need to be looped, the user needs to inspect the order of the parameter appearance in the graph to achieve an optimal result.

For example, a graph of \(G=\{V=\{A, B, C\}, E=\{(A, B), (B, C)\}\}\):

A -> B -> C

A(a, b)
B(c, d)
C(e, f)

The optimal way to loop c and e is to define the loop of parameter e in node C first and then define the loop of parameter c in node B second. If the order given is reversed, both parameters c and e are looped at node B level. The reason for the behavior is that when loop c is created, the graph:

A -> BC

A(a, b)
BC(c, d, e, f)

As a result, the subsequent loop definition only recognizes the subgraph node BC and loop the node instead.

Note

For a two-loop system, the optimal order can always be resolved. However, looping more than three parameters, the optimal order may not be resolved. Therefore, the design decision is made for the user to define the loop order.

shortcut module#

Shortcuts

The shortcut should work for both the Model and the Experiment classes.

mrfmsim.shortcut.loop_shortcut(model, parameter: str, name=None)[source]#

Shortcut to add a loop to a subgraph.

The parameter needs to be in the graph signature. Otherwise, an exception is raised. For parameters that are not from the graph (generated by modifiers), use regular loops or change modifiers.

Parameters:
  • model – executable model

  • parameter (str) – loop parameter

  • name (str) – name of the new model, defaults to old model name.

Returns:

a new model with looped parameter

mrfmsim.shortcut.print_shortcut(model, stdout_format_list, **pargs)[source]#

Shortcut to add print modifiers to nodes.

Parameters:
  • model – mrfmsim experiment

  • stdout_format_list (list) – list of format strings each format string should only contain one variable.

If the variable is not in the inputs or outputs of the nodes, the variable is ignored. The printout prioritizes inputs in a node. If a parameter is a node input and output, the first occurrence is used (when it is the output of the node). The decision to make all output the same setting (pargs for print()) is to simplify the implementation. If the user wants to have customized printout behavior, use the regular modifier for each node.