Support to BPMN 2.0
In PM4Py, we offer support for importing/exporting/layouting BPMN diagrams. The support is limited to the following BPMN elements:
- Events (start / end events)
- Gateways (exclusive, parallel, inclusive)
Moreover, we offer support to conversion from/to some process models implemented in PM4Py (such as Petri nets and BPMN diagrams).
BPMN 2.0 – Importing
The BPMN 2.0 XML files can be imported using the following instructions:
import pm4py import os bpmn_graph = pm4py.read_bpmn(os.path.join("tests", "input_data", "running-example.bpmn"))
BPMN 2.0 – Exporting
The BPMN models can be exported using the following instructions (here, bpmn_graph is the Python object hosting the model).
import pm4py import os pm4py.write_bpmn(bpmn_graph, "ru.bpmn", enable_layout=True)
The enable_layout, set to True, enables the automatic layouting of the BPMN model before the export.
BPMN 2.0 – Layouting
A layouting operation tries to give a good position to the nodes and the edges of the BPMN diagram. For our purposes, we chose an octilinear edges layout.
The following commands perform the layouting:
from pm4py.objects.bpmn.layout import layouter bpmn_graph = layouter.apply(bpmn_graph)
BPMN 2.0 – Conversion to Petri net
A conversion of a BPMN model into a Petri net model enables different PM4Py algorithms (such as conformance checking and simulation algorithms), hence is a particularly important operation.
To convert a BPMN model into an (accepting) Petri net, the following code can be used:
from pm4py.objects.conversion.bpmn import converter as bpmn_converter net, im, fm = bpmn_converter.apply(bpmn_graph)
BPMN 2.0 – Conversion from a process tree
Process trees are important classes of block-structured processes (and the output of the inductive miner algorithm). These models can be easily converted to BPMN models.
Let’s see an example. First, we import a XES event log, and we discover a model using the inductive miner:
import pm4py import os log = pm4py.read_xes(os.path.join("tests", "input_data", "running-example.xes")) tree = pm4py.discover_tree_inductive(log)
Then, we can convert that to a BPMN graph:
from pm4py.objects.conversion.process_tree import converter bpmn_graph = converter.apply(tree, variant=converter.Variants.TO_BPMN)