Rust4PM draws its process models as SVG images. The layout is computed in Rust with graphlay and needs no Graphviz installation.
import r4pm
log = r4pm.import_item("EventLog", "data/road-traffic-fines.xes.gz")
net = r4pm.bindings.discover_inductive_net(log)
# An Svg is a str holding the SVG markup. Notebooks display it as an image.
svg = r4pm.bindings.petri_net_svg(net)
svg.save("model.svg")
# Options steer the layout, the style sets colors and sizes. Fields left out keep their default.
vertical = r4pm.bindings.petri_net_svg(
net, {"direction": "topbottom"}, {"base": {"background": "#f5f5f4"}}
)
vertical.save("model-vertical.svg")
dfg = r4pm.bindings.discover_dfg(log)
r4pm.bindings.dfg_svg(dfg).save("dfg.svg")The snippet writes three files: the Petri net that IMf discovers for Road Traffic Fines (model.svg), the same net from top to bottom on a gray background (model-vertical.svg), and the DFG of the log (dfg.svg).
The Svg class
In Python, every *_svg binding returns an Svg, a str subclass that holds the SVG markup. .save(path) writes it to a file. Jupyter and VS Code notebooks display an Svg as an image when it is the value of a cell, e.g., a cell that ends with r4pm.bindings.petri_net_svg(net). As a string, it can also be written into an HTML page.
Models
| Model | Python | Rust |
|---|---|---|
| Petri net | petri_net_svg(net) | net.export_svg(path) |
| Process tree | process_tree_svg(tree) | tree.export_svg(path) |
| Directly-follows graph | dfg_svg(dfg) | dfg.export_svg(path) |
| Partial order trace | partial_order_svg(trace) | trace.export_svg(classifier, path) |
| Object-centric DFG | ocdfg_svg(ocdfg) | svg(&ocdfg, ..) |
| Object-centric Petri net | ocpn_svg(ocpn) | svg(&ocpn.to_json_form(), ..) |
| OC-DECLARE constraints | oc_declare_svg(arcs) | svg(arcs.as_slice(), ..) |
| Object and event types of an OCEL | oc_type_graph_svg(oc_type_graph_from_ocel(ocel)) | svg(&OcTypeGraph::from_linked_ocel(&ocel), ..) |
| Object-centric Petri net annotated by Reflow | reflow_annotated_ocpn_svg(model) | model.svg(&style, None) |
In Rust, process_mining::visualization::svg(&model, &options, &style) returns the SVG as a String for every model, and export_svg writes it with the default options and style. For example, the object-centric models of the Order Management log:
ocel = r4pm.import_item("SlimLinkedOCEL", "data/order-management.xml.gz")
r4pm.bindings.ocdfg_svg(r4pm.bindings.discover_ocdfg(ocel)).save("ocdfg.svg")
r4pm.bindings.ocpn_svg(r4pm.bindings.discover_ocpn(ocel)).save("ocpn.svg")
r4pm.bindings.oc_type_graph_svg(r4pm.bindings.oc_type_graph_from_ocel(ocel)).save("types.svg")Analyze object-centric data discovers these models.
Options, style and palette
The *_svg bindings of the models in the table take three optional arguments, except reflow_annotated_ocpn_svg, which takes only style and palette. In the dicts for options and style, fields left out keep their default.
optionschange what is drawn and how it is laid out.directionis"leftright"(the default for Petri nets) or"topbottom"(the default for DFGs).layout_patchchanges fields of the layout engine's settings, e.g.,{"routing": {"style": "diagonal"}}. For DFGs, OC-DFGs, Petri nets and object-centric Petri nets,annotationsreplace the labels, layout weights and line widths of nodes and edges, e.g., to show durations instead of counts. For DFGs, OC-DFGs and object-centric Petri nets,badgesshow object types as small discs in the node of an activity. A DFG also takesterminals, which draws the start and end nodes (on by default).stylesets colors, line widths, font sizes and padding. Every style has the shared fields underbase(underpetri.basefor object-centric Petri nets), e.g.,{"base": {"background": "#f5f5f4"}}, and most have more fields, e.g., the color of silent transitions in a Petri net.palettegives six fallback colors (node_bg,node_border,node_text,arc_color,arc_label_bgandexport_bg) for elements whose style names no color. A palette needs all six. The default styles name every color, and a palette does not change the default drawing of any model in the table. It applies to scenes with elements that name no color, e.g., a scene that you edited yourself.
Custom layouts
Besides *_svg, every model has four more bindings for interactive editors:
*_layoutreturns the positions of nodes and the routes of edges.*_svg_from_layoutdraws the model over a given layout, e.g., one with moved nodes, with optionaloverridesof the style of single nodes and edges.*_scene_from_layoutreturns the drawing as a scene of shapes, texts and lines, whichrender_scene_svg(scene, palette)turns into an SVG.*_layout_requestreturns the input of the layout engine.layout_graphlays it out (layout_treefor process trees), andreroute_graphroutes the edges again after nodes were moved.
layout = r4pm.bindings.petri_net_layout(net)
layout["nodes"][0]["center"]["y"] += 100
r4pm.bindings.petri_net_svg_from_layout(net, layout).save("moved.svg")In Rust, layout, layout_request, scene_from_layout and svg in process_mining::visualization take any model, and visualization::engine has layout_graph, layout_tree, reroute_graph and render_scene_svg. Reference: visualization bindings.