BPMN 2.0 Management

BETA feature: PM4Py offers limited support to BPMN 2.0 on the ‘bpmnIntegration’ branch

BPMN 2.0 is a powerful language, with a lot of constructs, and usually is easier to understand from the business.

Importing BPMN 2.0 diagrams

The following code is useful to import BPMN diagrams

import os
from pm4py.objects.bpmn.importer import bpmn20 as bpmn_importer

bpmn_graph = bpmn_importer.import_bpmn(os.path.join("tests","input_data","running-example.bpmn"))

Exporting BPMN 2.0 diagrams

The following code is useful to export a BPMN diagram:

from pm4py.objects.bpmn.exporter import bpmn20 as bpmn_exporter

bpmn_exporter.export_bpmn(bpmn_graph, "running-example.bpmn")

While the information is present in the BPMN diagram, a layouting algorithm is not applied to the diagrams.

Converting a Petri net to a BPMN diagram

In this subsection, a way to convert a Petri net to a BPMN diagram is provided. Suppose to start with the import of an event log:

import os
from pm4py.objects.log.importer.xes import factory as xes_importer

log = xes_importer.import_log(os.path.join("tests","input_data","running-example.xes"))

And the application of a Process Discovery algorithm (for example, the Inductive Miner):

from pm4py.algo.discovery.inductive import factory as inductive_miner

net, initial_marking, final_marking = inductive_miner.apply(log)

The following code could be used to convert a Petri net into a BPMN diagram with some mapping information:

from pm4py.objects.conversion.petri_to_bpmn import factory as bpmn_converter

bpmn_graph, elements_correspondence, inv_elements_correspondence, el_corr_keys_map = bpmn_converter.apply(net, initial_marking, final_marking)

The output comprise the following elements:

  • bpmn_graph: the BPMN diagram object
  • elements_correspondence: a dictionary that stores the correspondence between some elements of the Petri net (places, transitions, arcs) and some elements of the BPMN diagram (tasks, gateways, arcs).
  • inv_elements_correspondence: the inverse of elements_correspondence, stores the correspondence between elements of the BPMN diagram and elements of the Petri net

Converting a BPMN diagram into a Petri net

In this subsection, a way to convert a BPMN diagram into a Petri net is provided. Suppose to start with the import of a BPMN diagram:

import os
from pm4py.objects.bpmn.importer import bpmn20 as bpmn_importer

bpmn_graph = bpmn_importer.import_bpmn(os.path.join("tests","input_data","running-example.bpmn"))

Then the following operation triggers the conversion from BPMN to Petri net (along with elements correspondence):

from pm4py.objects.conversion.bpmn_to_petri import factory as bpmn_to_petri

net, initial_marking, final_marking, elements_correspondence, inv_elements_correspondence, el_corr_keys_map = bpmn_to_petri.apply(bpmn_graph)

The output, aside from the Petri net, the initial and the final marking, will contain the following elements:

  • bpmn_graph: the BPMN diagram object
  • elements_correspondence: a dictionary that stores the correspondence between some elements of the Petri net (places, transitions, arcs) and some elements of the BPMN diagram (tasks, gateways, arcs).
  • inv_elements_correspondence: the inverse of elements_correspondence, stores the correspondence between elements of the BPMN diagram and elements of the Petri net

Visualizing a BPMN diagram on the screen

The following code is useful to display a BPMN diagram on the screen:

from pm4py.visualization.bpmn import factory as bpmn_vis_factory

bpmn_figure = bpmn_vis_factory.apply(bpmn_graph)
bpmn_vis_factory.view(bpmn_figure)

The default visualization format is PNG. If the format needs to be changed, then a parameters containing the format of the image could be passed as argument to the apply method:

from pm4py.visualization.bpmn import factory as bpmn_vis_factory

bpmn_figure = bpmn_vis_factory.apply(bpmn_graph, parameters={"format": "svg"})
bpmn_vis_factory.view(bpmn_figure)

The representation could then be saved on the hard drive through the following code:

bpmn_vis_factory.save(bpmn_figure, "running-example.svg")

BPMN diagram

Some options to decorate the BPMN graph with frequency/performance information have been provided, that report the results of a replay on the Petri net on the BPMN graph. For the sake of simplicity, these algorithms take in input a Petri net along with an initial and a final marking, do automatically the conversion to a BPMN diagram, apply decoration algorithms on the Petri net and report the result on the BPMN diagram.

Some examples could be provided for frequency and performance. Frequency:

from pm4py.visualization.bpmn import factory as bpmn_vis_factory

bpmn_figure = bpmn_vis_factory.apply_petri(net, initial_marking, final_marking, log=log, variant="frequency")
bpmn_vis_factory.view(bpmn_figure)

BPMN diagram with frequency

Performance:

from pm4py.visualization.bpmn import factory as bpmn_vis_factory

bpmn_figure = bpmn_vis_factory.apply_petri(net, initial_marking, final_marking, log=log, variant="performance")
bpmn_vis_factory.view(bpmn_figure)

BPMN diagram with performance

Alternatively, a visualization option is provided that automatically converts the BPMN graph into a Petri net, and discovers decorations through replay on the Petri net. For Frequency the following applies:

from pm4py.visualization.bpmn import factory as bpmn_vis_factory

bpmn_figure = bpmn_vis_factory.apply_through_conv(bpmn_graph, log=log, variant="frequency")
bpmn_vis_factory.view(bpmn_figure)

For Performance the following applies:

from pm4py.visualization.bpmn import factory as bpmn_vis_factory

bpmn_figure = bpmn_vis_factory.apply_through_conv(bpmn_graph, log=log, variant="performance")
bpmn_vis_factory.view(bpmn_figure)

Direct annotation of BPMN graphs (exportable in BPMN2.0 format)

Instead of decorating a picture of the BPMN diagram with the frequency/performance information, it is possible to write directly inside the BPMN 2.0 XML the information related to frequency/performance

For annotating the frequency, the following instructions could be used:

from pm4py.visualization.bpmn import factory as bpmn_vis_factory

bpmn_graph = bpmn_vis_factory.apply_embedding(bpmn_graph, log=log, variant="frequency")

For annotating the performance, the following instructions could be used:

from pm4py.visualization.bpmn import factory as bpmn_vis_factory

bpmn_graph = bpmn_vis_factory.apply_embedding(bpmn_graph, log=log, variant="performance")

And the BPMN 2.0 XML could be exported using the following instructions:

bpmn_diagram_exporter.export_bpmn(bpmn_graph, "bpmn_graph.bpmn")

BPMN Layouting

PM4Py offers some basic BPMN layouting that permits to render the BPMN 2.0 XML file.

To perform the layouting, the following code should be executed:

from pm4py.objects.bpmn.util import bpmn_diagram_layouter

bpmn_graph = bpmn_diagram_layouter.apply(bpmn_graph)

An example could be provided on the BPI Challenge 2017 event log:

.