PM4Py offers support for process trees, including visualization, conversion to Petri nets, log generation, importing/exporting, and tree generation functionality. This section outlines these features.
PM4Py supports importing and exporting process trees in the PTML format. Use the following code to import a process tree from a PTML file:
Use the following code to export a process tree to a PTML file:
The 'PTAndLogGenerator' approach, described in the paper 'PTAndLogGenerator: A Generator for Artificial Event Data', has been implemented in the PM4Py library. The following code snippet can be used to generate a process tree. Review the parameters below:
Below is a table explaining the parameters used in the process tree generation:
Parameter | Meaning |
---|---|
MODE | Most frequent number of visible activities (default 20) |
MIN | Minimum number of visible activities (default 10) |
MAX | Maximum number of visible activities (default 30) |
SEQUENCE | Probability of adding a sequence operator to the tree (default 0.25) |
CHOICE | Probability of adding a choice operator to the tree (default 0.25) |
PARALLEL | Probability of adding a parallel operator to the tree (default 0.25) |
LOOP | Probability of adding a loop operator to the tree (default 0.25) |
OR | Probability of adding an OR operator to the tree (default 0) |
SILENT | Probability of adding silent activities to choice or loop operators (default 0.25) |
DUPLICATE | Probability of duplicating an activity label (default 0) |
LT_DEPENDENCY | Probability of adding random dependencies to the tree (default 0) |
INFREQUENT | Probability of making a choice have infrequent paths (default 0.25) |
NO_MODELS | Number of trees to generate from the model population (default 10) |
UNFOLD | Whether to unfold loops to include choices in dependencies (0 = False, 1 = True). If LT_DEPENDENCY ≤ 0, this should always be 0 (False). If LT_DEPENDENCY > 0, this can be either 0 or 1 (True or False). (default 10) |
MAX_REPEAT | Maximum number of loop repetitions (used only when unfolding is True) (default 10) |
Use the following code snippet to generate a log with 100 cases from a process tree:
Use the following code to convert a process tree into a Petri net:
A process tree can be printed as shown below:
A process tree can also be visualized as follows:
We present an approach to convert a block-structured accepting Petri net into a process tree. The method is based on the work by van Zelst, Sebastiaan J., "Translating Workflow Nets to Process Trees: An Algorithmic Approach" (arXiv preprint arXiv:2004.08213, 2020).
The approach returns a process tree for block-structured Petri nets and raises an exception if the Petri net is not block-structured. Below is an example of this approach:
First, we load an XES log and discover an accepting Petri net using the Alpha Miner algorithm:
Next, we convert this Petri net into a process tree:
The method succeeds since the accepting Petri net is block-structured and generates a process tree (which, in this case, coincidentally matches the process tree discovered by the inductive miner).
By default, a process tree does not include frequency or performance annotations. To optimally match a log against a process tree, you can use the alignments algorithm. The results of this algorithm provide a list of visited leaves/operators during replay, which can then be used to infer the frequency of each node at the case/event level in the process tree.
The following code can be used to add frequency annotations to the nodes of a process tree:
A frequency-based visualization of the process tree is also available: