pm4py.objects.petri package

Submodules

pm4py.objects.petri.align_utils module

class pm4py.objects.petri.align_utils.DijkstraSearchTuple(g, m, p, t, l)[source]

Bases: object

class pm4py.objects.petri.align_utils.SearchTuple(f, g, h, m, p, t, x, trust)[source]

Bases: object

class pm4py.objects.petri.align_utils.TweakedSearchTuple(f, g, h, m, p, t, x, trust, virgin)[source]

Bases: object

pm4py.objects.petri.align_utils.add_markings(curr, add)[source]
pm4py.objects.petri.align_utils.construct_standard_cost_function(synchronous_product_net, skip)[source]

Returns the standard cost function, which is: * event moves: cost 1000 * model moves: cost 1000 * tau moves: cost 1 * sync moves: cost 0 :param synchronous_product_net: :param skip: :return:

pm4py.objects.petri.align_utils.get_visible_transitions_eventually_enabled_by_marking(net, marking)[source]

Get visible transitions eventually enabled by marking (passing possibly through hidden transitions) :Parameters: * net – Petri net

  • marking – Current marking

pm4py.objects.petri.align_utils.pretty_print_alignments(alignments)[source]
Takes an alignment and prints it to the console, e.g.:

A | B | C | D |

A | B | C | >> |

Parameters

alignment – <class ‘list’>

Returns

Nothing

pm4py.objects.petri.align_utils.search_path_among_sol(sync_net: pm4py.objects.petri_net.obj.PetriNet, ini: pm4py.objects.petri_net.obj.Marking, fin: pm4py.objects.petri_net.obj.Marking, activated_transitions: List[pm4py.objects.petri_net.obj.PetriNet.Transition], skip='>>') → Tuple[List[pm4py.objects.petri_net.obj.PetriNet.Transition], bool, int][source]

(Efficient method) Searches a firing sequence among the X vector that is the solution of the (extended) marking equation

Parameters
  • sync_net – Synchronous product net

  • ini – Initial marking of the net

  • fin – Final marking of the net

  • activated_transitions – Transitions that have non-zero occurrences in the X vector

  • skip – Skip transition

Returns

  • firing_sequence – Firing sequence

  • reach_fm – Boolean value that tells if the final marking is reached by the firing sequence

  • explained_events – Number of explained events

pm4py.objects.petri.check_soundness module

pm4py.objects.petri.check_soundness.check_easy_soundness_net_in_fin_marking(net, ini, fin)[source]

Checks the easy soundness of a Petri net having the initial and the final marking

Parameters
  • net – Petri net

  • ini – Initial marking

  • fin – Final marking

Returns

Boolean value

Return type

boolean

pm4py.objects.petri.check_soundness.check_easy_soundness_of_wfnet(net)[source]

Checks the easy soundness of a workflow net

Parameters

net – Petri net

Returns

Boolean value

Return type

boolean

pm4py.objects.petri.check_soundness.check_sink_place_presence(net)[source]

Check if there is a unique sink place with empty connections

Parameters

net – Petri net

Returns

Unique source place (or None otherwise)

Return type

place

pm4py.objects.petri.check_soundness.check_source_and_sink_reachability(net, unique_source, unique_sink)[source]

Checks reachability of the source and the sink place from all simulation nodes (places/transitions) of the Petri net

Parameters
  • net – Petri net

  • unique_source – Unique source place of the Petri net

  • unique_sink – Unique sink place of the Petri net

Returns

Boolean value that is true if each node is in a path from the source place to the sink place

Return type

boolean

pm4py.objects.petri.check_soundness.check_source_place_presence(net)[source]

Check if there is a unique source place with empty connections

Parameters

net – Petri net

Returns

Unique source place (or None otherwise)

Return type

place

pm4py.objects.petri.check_soundness.check_source_sink_place_conditions(net)[source]

Check some conditions on the source/sink place important for a sound workflow net

Parameters

net – Petri net

Returns

Boolean value (True is good)

Return type

boolean

pm4py.objects.petri.check_soundness.check_wfnet(net)[source]

Check if the Petri net is a workflow net

Parameters

net – Petri net

Returns

Boolean value that is true when the Petri net is a workflow net

Return type

boolean

pm4py.objects.petri.consumption_matrix module

Implements the consumption matrix as explained in the following paper:

van Dongen, Boudewijn F. “Efficiently computing alignments.” International Conference on Business Process Management. Springer, Cham, 2018. https://link.springer.com/chapter/10.1007/978-3-319-98648-7_12

class pm4py.objects.petri.consumption_matrix.ConsumptionMatrix(net: pm4py.objects.petri_net.obj.PetriNet)[source]

Bases: object

property c_matrix

Gets the Numpy representation of the consumption matrix

Returns

C matrix

Return type

C

property places

Gets the places in the order in which they have been inserted in the consumption matrix

Returns

Dictionary associating to each place an incremental number

Return type

place_indices

property transitions

Gets the transitions in the order in which they have been inserted in the consumption matrix

Returns

Dictionary associating to each transition an incremental number

Return type

trans_indices

pm4py.objects.petri.consumption_matrix.construct(net: pm4py.objects.petri_net.obj.PetriNet)pm4py.objects.petri.consumption_matrix.ConsumptionMatrix[source]

Construct a consumption matrix given a Petri net

Parameters

net – Petri net

Returns

Consumption matrix object

Return type

cons_mat

pm4py.objects.petri.decomposition module

pm4py.objects.petri.decomposition.decompose(net, im, fm)[source]
pm4py.objects.petri.decomposition.get_graph_components(places, inv_trans, trans_dup_label, tmap)[source]
pm4py.objects.petri.decomposition.merge_comp(comp1, comp2)[source]
pm4py.objects.petri.decomposition.merge_sublist_nets(list_nets)[source]

pm4py.objects.petri.embed_stochastic_map module

pm4py.objects.petri.embed_stochastic_map.apply(smap, parameters=None)[source]

Embed the stochastic map into the Petri net

Parameters
  • smap – Stochastic map

  • parameters – Possible parameters of the algorithm

Returns

Return type

void

pm4py.objects.petri.embed_stochastic_map.extract(net, parameters=None)[source]

Extract the stochastic map from the Petri net

Parameters
  • net – Petri net

  • parameters – Possible parameters of the algorithm

Returns

Return type

void

pm4py.objects.petri.explore_path module

pm4py.objects.petri.incidence_matrix module

class pm4py.objects.petri.incidence_matrix.IncidenceMatrix(net)[source]

Bases: object

property a_matrix
encode_marking(marking)[source]
property places
property transitions
pm4py.objects.petri.incidence_matrix.construct(net)[source]

pm4py.objects.petri.networkx_graph module

pm4py.objects.petri.networkx_graph.create_networkx_directed_graph(net, weight=None)[source]

Create a NetworkX directed graph from a Petri net

Parameters

net – Petri net

Returns

  • graph – NetworkX digraph

  • inv_dictionary – Correspondence between NetworkX nodes and Petri net entities

pm4py.objects.petri.networkx_graph.create_networkx_undirected_graph(net, unique_source, unique_sink)[source]

Create a NetworkX undirected graph from a Petri net, returning also correspondences for the unique source and the unique sink places that were discovered

Parameters
  • net – Petri net

  • unique_source – Unique source place

  • unique_sink – Unique sink place

Returns

  • graph – NetworkX graph

  • unique_source_corr – Correspondence in the NetworkX graph of the unique source place

  • unique_sink_corr – Correspondence in the NetworkX graph of the unique sink place

  • inv_dictionary – Correspondence between NetworkX nodes and Petri net entities

pm4py.objects.petri.obj module

pm4py.objects.petri.performance_map module

pm4py.objects.petri.performance_map.aggregate_statistics(statistics, measure='frequency', aggregation_measure=None)[source]

Gets aggregated statistics

Parameters
  • statistics – Individual element statistics (including unaggregated performances)

  • measure – Desidered view on data (frequency or performance)

  • aggregation_measure – Aggregation measure (e.g. mean, min) to use

Returns

Aggregated statistics for arcs, transitions, places

Return type

aggregated_statistics

pm4py.objects.petri.performance_map.aggregate_stats(statistics, elem, aggregation_measure)[source]

Aggregate the statistics

Parameters
  • statistics – Element statistics

  • elem – Current element

  • aggregation_measure – Aggregation measure (e.g. mean, min) to use

Returns

Aggregated statistics

Return type

aggr_stat

pm4py.objects.petri.performance_map.calculate_annotation_for_trace(trace, net, initial_marking, act_trans, activity_key, ht_perf_method='last')[source]

Calculate annotation for a trace in the variant, in order to retrieve information useful for calculate frequency/performance for all the traces belonging to the variant

Parameters
  • trace – Trace

  • net – Petri net

  • initial_marking – Initial marking

  • act_trans – Activated transitions during token replay of the given trace

  • activity_key – Attribute that identifies the activity (must be specified if different from concept:name)

  • ht_perf_method – Method to use in order to annotate hidden transitions (performance value could be put on the last possible point (last) or in the first possible point (first)

Returns

Statistics annotation for the given trace

Return type

annotation

pm4py.objects.petri.performance_map.filter_cases_exceeding_specified_acti_performance(log, transition_performance, activity, lower_bound)[source]

Filter cases exceeding the specified activity performance threshold

Parameters
  • log – Event log

  • transition_performance – Dictionary where each transition label is associated to performance measures

  • activity – Target activity (of the filter)

  • lower_bound – Lower bound (filter cases which have a duration of the activity exceeding)

Returns

Filtered log

Return type

filtered_log

pm4py.objects.petri.performance_map.find_min_max_arc_frequency(statistics)[source]

Find minimum and maximum arc frequency

Parameters

statistics – Element statistics

Returns

  • min_frequency – Minimum arc frequency

  • max_frequency – Maximum arc frequency

pm4py.objects.petri.performance_map.find_min_max_arc_performance(statistics, aggregation_measure)[source]

Find minimum and maximum arc performance

Parameters
  • statistics – Element statistics

  • aggregation_measure – Aggregation measure (e.g. mean, min) to use

Returns

  • min_performance – Minimum performance

  • max_performance – Maximum performance

pm4py.objects.petri.performance_map.find_min_max_trans_frequency(statistics)[source]

Find minimum and maximum transition frequency

Parameters

statistics – Element statistics

Returns

  • min_frequency – Minimum transition frequency (in the replay)

  • max_frequency – Maximum transition frequency (in the replay)

pm4py.objects.petri.performance_map.get_idx_exceeding_specified_acti_performance(log, transition_performance, activity, lower_bound)[source]

Get indexes of the cases exceeding the specified activity performance threshold

Parameters
  • log – Event log

  • transition_performance – Dictionary where each transition label is associated to performance measures

  • activity – Target activity (of the filter)

  • lower_bound – Lower bound (filter cases which have a duration of the activity exceeding)

Returns

A list of indexes in the log

Return type

idx

pm4py.objects.petri.performance_map.get_transition_performance_with_token_replay(log, net, im, fm)[source]

Gets the transition performance through the usage of token-based replay

Parameters
  • log – Event log

  • net – Petri net

  • im – Initial marking

  • fm – Final marking

Returns

Dictionary where each transition label is associated to performance measures

Return type

transition_performance

pm4py.objects.petri.performance_map.single_element_statistics(log, net, initial_marking, aligned_traces, variants_idx, activity_key='concept:name', timestamp_key='time:timestamp', ht_perf_method='last', parameters=None)[source]

Get single Petrinet element statistics

Parameters
  • log – Log

  • net – Petri net

  • initial_marking – Initial marking

  • aligned_traces – Result of the token-based replay

  • variants_idx – Variants along with indexes of belonging traces

  • activity_key – Activity key (must be specified if different from concept:name)

  • timestamp_key – Timestamp key (must be specified if different from time:timestamp)

  • ht_perf_method – Method to use in order to annotate hidden transitions (performance value could be put on the last possible point (last) or in the first possible point (first)

  • parameters – Possible parameters of the algorithm

Returns

Petri net element statistics (frequency, unaggregated performance)

Return type

statistics

pm4py.objects.petri.petrinet module

pm4py.objects.petri.projection module

pm4py.objects.petri.projection.project_net_on_matrix(net, activities, parameters=None)[source]

Project a Petri net with: - only visible transitions - where each place preset/postset is disjoint - with unique visible transitions on a numeric matrix

Parameters
  • net – Petri net

  • activities – List of activities

  • parameters – Possible parameters of the algorithm

pm4py.objects.petri.projection.project_net_on_place(place)[source]

Project a Petri net on a place

Parameters

place – Place

Returns

  • net – (Place) net

  • im – Empty initial marking

  • fm – Empty final marking

pm4py.objects.petri.properties module

pm4py.objects.petri.reachability_graph module

class pm4py.objects.petri.reachability_graph.Parameters(value)[source]

Bases: enum.Enum

An enumeration.

MAX_ELAB_TIME = 'max_elab_time'
pm4py.objects.petri.reachability_graph.construct_reachability_graph(net, initial_marking, use_trans_name=False, parameters=None)[source]

Creates a reachability graph of a certain Petri net. DO NOT ATTEMPT WITH AN UNBOUNDED PETRI NET, EVER.

Parameters
  • net (Petri net)

  • initial_marking (initial marking of the Petri net.)

Returns

re_gr

Return type

Transition system that represents the reachability graph of the input Petri net.

pm4py.objects.petri.reachability_graph.construct_reachability_graph_from_flow(incoming_transitions, outgoing_transitions, use_trans_name=False, parameters=None)[source]

Construct the reachability graph from the marking flow

Parameters
  • incoming_transitions – Incoming transitions

  • outgoing_transitions – Outgoing transitions

  • use_trans_name – Use the transition name

Returns

Transition system that represents the reachability graph of the input Petri net.

Return type

re_gr

pm4py.objects.petri.reachability_graph.marking_flow_petri(net, im, return_eventually_enabled=False, parameters=None)[source]

Construct the marking flow of a Petri net

Parameters
  • net – Petri net

  • im – Initial marking

  • return_eventually_enabled – Return the eventually enabled (visible) transitions

pm4py.objects.petri.reachability_graph.staterep(name)[source]

Creates a string representation for a state of a transition system. Necessary because graphviz does not support symbols simulation than alphanimerics and ‘_’. TODO: find a better representation.

Parameters

name (the name of a state)

Returns

Return type

Version of the name filtered of non-alphanumerical characters (except ‘_’)

pm4py.objects.petri.reduction module

pm4py.objects.petri.reduction.apply_simple_reduction(net)[source]

Apply a simple reduction to the Petri net

Parameters

net – Petri net

pm4py.objects.petri.reduction.reduce_single_entry_transitions(net)[source]

Reduces the number of the single entry transitions in the Petri net

Parameters

net – Petri net

pm4py.objects.petri.reduction.reduce_single_exit_transitions(net)[source]

Reduces the number of the single exit transitions in the Petri net

Parameters

net – Petri net

pm4py.objects.petri.semantics module

pm4py.objects.petri.semantics.enabled_transitions(pn, m)[source]

Returns a set of enabled transitions in a Petri net and given marking

Parameters
  • param pn: Petri net

  • param m: marking of the pn

Returns

Return type

return: set of enabled transitions

pm4py.objects.petri.semantics.execute(t, pn, m)[source]

Executes a given transition in a given Petri net and Marking

Parameters
  • param t: transition to execute

  • param pn: Petri net

  • param m: marking to use

Returns

Return type

return: newly reached marking if :param t: is enabled, None otherwise

pm4py.objects.petri.semantics.is_enabled(t, pn, m)[source]

Verifies whether a given transition is enabled in a given Petri net and marking

Parameters
  • param t: transition to check

  • param pn: Petri net

  • param m: marking to check

Returns

Return type

return: true if enabled, false otherwise

pm4py.objects.petri.semantics.try_to_execute(t, pn, m)[source]
pm4py.objects.petri.semantics.weak_execute(t, m)[source]

Execute a transition even if it is not fully enabled

Parameters
  • param t: transition to execute

  • param m: marking to use

Returns

Return type

return: newly reached marking if :param t: is enabled, None otherwise

pm4py.objects.petri.synchronous_product module

pm4py.objects.petri.synchronous_product.construct(pn1, im1, fm1, pn2, im2, fm2, skip)[source]

Constructs the synchronous product net of two given Petri nets.

Parameters
  • pn1 – Petri net 1

  • im1 – Initial marking of Petri net 1

  • fm1 – Final marking of Petri net 1

  • pn2 – Petri net 2

  • im2 – Initial marking of Petri net 2

  • fm2 – Final marking of Petri net 2

  • skip – Symbol to be used as skip

Returns

Return type

return: Synchronous product net and associated marking labels are of the form (a,>>)

pm4py.objects.petri.synchronous_product.construct_cost_aware(pn1, im1, fm1, pn2, im2, fm2, skip, pn1_costs, pn2_costs, sync_costs)[source]

Constructs the synchronous product net of two given Petri nets.

Parameters
  • pn1 – Petri net 1

  • im1 – Initial marking of Petri net 1

  • fm1 – Final marking of Petri net 1

  • pn2 – Petri net 2

  • im2 – Initial marking of Petri net 2

  • fm2 – Final marking of Petri net 2

  • skip – Symbol to be used as skip

  • pn1_costs – dictionary mapping transitions of pn1 to corresponding costs

  • pn2_costs – dictionary mapping transitions of pn2 to corresponding costs

  • pn1_costs – dictionary mapping pairs of transitions in pn1 and pn2 to costs

  • sync_costs – Costs of sync moves

Returns

Return type

return: Synchronous product net and associated marking labels are of the form (a,>>)

pm4py.objects.petri.utils module

pm4py.objects.petri.utils.acyclic_net_variants(net, initial_marking, final_marking, activity_key='concept:name')[source]

Given an acyclic accepting Petri net, initial and final marking extracts a set of variants (in form of traces) replayable on the net. Warning: this function is based on a marking exploration. If the accepting Petri net contains loops, the method will not work properly as it stops the search if a specific marking has already been encountered.

Parameters
  • param net: An acyclic workflow net

  • param initial_marking: The initial marking of the net.

  • param final_marking: The final marking of the net.

  • param activity_key: activity key to use

Returns

Return type

return: variants: list Set of variants - in the form of Trace objects - obtainable executing the net

pm4py.objects.petri.utils.add_arc_from_to(fr, to, net, weight=1)[source]

Adds an arc from a specific element to another element in some net. Assumes from and to are in the net!

Parameters
  • fr (transition/place from)

  • to (transition/place to)

  • net (net to use)

  • weight (weight associated to the arc)

Returns

Return type

None

pm4py.objects.petri.utils.add_place(net, name=None)[source]
pm4py.objects.petri.utils.add_transition(net, name=None, label=None)[source]
pm4py.objects.petri.utils.construct_trace_net(trace, trace_name_key='concept:name', activity_key='concept:name')[source]

Creates a trace net, i.e. a trace in Petri net form.

Parameters
  • trace (list input trace, assumed to be a list of events)

  • trace_name_key (str key of the attribute that defines the name of the trace)

  • activity_key (str key of the attribute of the events that defines the activity name)

Returns

tuple

Return type

tuple of the net, initial marking and the final marking

pm4py.objects.petri.utils.construct_trace_net_cost_aware(trace, costs, trace_name_key='concept:name', activity_key='concept:name')[source]

Creates a trace net, i.e. a trace in Petri net form mapping specific costs to transitions.

Parameters
  • trace (list input trace, assumed to be a list of events)

  • costs (list list of costs, length should be equal to the length of the input trace)

  • trace_name_key (str key of the attribute that defines the name of the trace)

  • activity_key (str key of the attribute of the events that defines the activity name)

Returns

tuple

Return type

tuple of the net, initial marking, final marking and map of costs

pm4py.objects.petri.utils.decorate_places_preset_trans(net)[source]

Decorate places with information useful for the replay

Parameters

net – Petri net

pm4py.objects.petri.utils.decorate_transitions_prepostset(net)[source]

Decorate transitions with sub and addition markings

Parameters

net – Petri net

pm4py.objects.petri.utils.get_cycles_petri_net_places(net)[source]

Get the cycles of a Petri net (returning only list of places belonging to the cycle)

Parameters

net – Petri net

Returns

Cycles (places) of the Petri net

Return type

cycles

pm4py.objects.petri.utils.get_cycles_petri_net_transitions(net)[source]

Get the cycles of a Petri net (returning only list of transitions belonging to the cycle)

Parameters

net – Petri net

Returns

Cycles (transitions) of the Petri net

Return type

cycles

pm4py.objects.petri.utils.get_places_shortest_path(net, place_to_populate, current_place, places_shortest_path, actual_list, rec_depth, max_rec_depth)[source]

Get shortest path between places lead by hidden transitions

Parameters
  • net – Petri net

  • place_to_populate – Place that we are populating the shortest map of

  • current_place – Current visited place (must explore its transitions)

  • places_shortest_path – Current dictionary

  • actual_list – Actual list of transitions to enable

  • rec_depth – Recursion depth

  • max_rec_depth – Maximum recursion depth

pm4py.objects.petri.utils.get_places_shortest_path_by_hidden(net, max_rec_depth)[source]

Get shortest path between places lead by hidden transitions

Parameters
  • net – Petri net

  • max_rec_depth – Maximum recursion depth

pm4py.objects.petri.utils.get_s_components_from_petri(net, im, fm, rec_depth=0, curr_s_comp=None, visited_places=None, list_s_components=None, max_rec_depth=6)[source]

Gets the S-components from a Petri net

Parameters
  • net – Petri net

  • im – Initial marking

  • fm – Final marking

  • curr_s_comp – Current S component

  • visited_places – Visited places

  • list_s_components – List of S-components

  • max_rec_depth – Maximum recursion depth

Returns

List of S-components

Return type

s_components

pm4py.objects.petri.utils.get_strongly_connected_subnets(net)[source]

Get the strongly connected components subnets in the Petri net

Parameters

net – Petri net

Returns

List of strongly connected transitions of the Petri net

Return type

strongly_connected_transitions

pm4py.objects.petri.utils.get_transition_by_name(net, transition_name)[source]

Get a transition by its name

Parameters
  • net – Petri net

  • transition_name – Transition name

Returns

Transition object

Return type

transition

pm4py.objects.petri.utils.invert_spaths_dictionary(spaths)[source]

Invert the shortest paths (between places) dictionary, from target-source to source-target

Parameters

spaths – Shortest paths dictionary

Returns

Inverted shortest paths dictionary

Return type

inv_spaths

pm4py.objects.petri.utils.is_sub_marking(sub_marking, marking)[source]
pm4py.objects.petri.utils.merge(trgt=None, nets=None)[source]
pm4py.objects.petri.utils.place_set_as_marking(places)[source]
pm4py.objects.petri.utils.post_set(elem)[source]
pm4py.objects.petri.utils.pre_set(elem)[source]
pm4py.objects.petri.utils.remove_arc(net, arc)[source]

Removes an arc from a Petri net

Parameters
  • net – Petri net

  • arc – Arc of the Petri net

Returns

Petri net

Return type

net

pm4py.objects.petri.utils.remove_place(net, place)[source]

Remove a place from a Petri net

Parameters
  • net – Petri net

  • place – Place to remove

Returns

Petri net

Return type

net

pm4py.objects.petri.utils.remove_transition(net, trans)[source]

Remove a transition from a Petri net

Parameters
  • net – Petri net

  • trans – Transition to remove

Returns

Petri net

Return type

net

pm4py.objects.petri.utils.remove_unconnected_components(net)[source]

Remove unconnected components from a Petri net

Parameters

net – Petri net

Returns

Cleaned Petri net

Return type

net

Module contents