pm4py.conformance.conformance_diagnostics_token_based_replay#
- pm4py.conformance.conformance_diagnostics_token_based_replay(log: EventLog | DataFrame, petri_net: PetriNet, initial_marking: Marking, final_marking: Marking, activity_key: str = 'concept:name', timestamp_key: str = 'time:timestamp', case_id_key: str = 'case:concept:name', return_diagnostics_dataframe: bool = False, opt_parameters: Dict[Any, Any] | None = None) List[Dict[str, Any]] [source]#
Apply token-based replay for conformance checking analysis. This method returns the full token-based replay diagnostics.
Token-based replay matches a trace against a Petri net model, starting from the initial marking, to discover which transitions are executed and in which places there are remaining or missing tokens for the given process instance. Token-based replay is useful for conformance checking: a trace fits the model if, during its execution, all transitions can be fired without the need to insert any missing tokens. If reaching the final marking is imposed, a trace fits if it reaches the final marking without any missing or remaining tokens.
In PM4Py, the token replayer implementation can handle hidden transitions by calculating the shortest paths between places. It can be used with any Petri net model that has unique visible transitions and hidden transitions. When a visible transition needs to be fired and not all places in its preset have the correct number of tokens, the current marking is checked to see if any hidden transitions can be fired to enable the visible transition. The hidden transitions are then fired, reaching a marking that permits the firing of the visible transition.
The approach is described in: Berti, Alessandro, and Wil MP van der Aalst. “Reviving Token-based Replay: Increasing Speed While Improving Diagnostics.” ATAED@ Petri Nets/ACSD. 2019.
The output of the token-based replay, stored in the variable replayed_traces, contains for each trace in the log:
trace_is_fit: Boolean value indicating whether the trace conforms to the model.
activated_transitions: List of transitions activated in the model by the token-based replay.
reached_marking: Marking reached at the end of the replay.
missing_tokens: Number of missing tokens.
consumed_tokens: Number of consumed tokens.
remaining_tokens: Number of remaining tokens.
produced_tokens: Number of produced tokens.
- Parameters:
log – Event log.
petri_net (
PetriNet
) – Petri net.initial_marking (
Marking
) – Initial marking.final_marking (
Marking
) – Final marking.activity_key (
str
) – Attribute to be used for the activity (default is “concept:name”).timestamp_key (
str
) – Attribute to be used for the timestamp (default is “time:timestamp”).case_id_key (
str
) – Attribute to be used as the case identifier (default is “case:concept:name”).return_diagnostics_dataframe (
bool
) – If possible, returns a dataframe with the diagnostics instead of the usual output (default is constants.DEFAULT_RETURN_DIAGNOSTICS_DATAFRAME).opt_parameters – Optional parameters for the token-based replay, including: * reach_mark_through_hidden: Boolean to decide if the final marking should be reached through hidden transitions. * stop_immediately_unfit: Boolean to decide if the replay should stop immediately when non-conformance is detected. * walk_through_hidden_trans: Boolean to decide if the replay should walk through hidden transitions to enable visible transitions. * places_shortest_path_by_hidden: Shortest paths between places using hidden transitions. * is_reduction: Indicates if the token-based replay is called in a reduction attempt. * thread_maximum_ex_time: Maximum allowed execution time for alignment threads. * cleaning_token_flood: Decides if token flood cleaning should be performed. * disable_variants: Disable variants grouping. * return_object_names: Decide whether to return names instead of object pointers.
- Returns:
A list of dictionaries containing diagnostics for each trace.
- Return type:
List[Dict[str, Any]]
- Example:
-
- net, im, fm = pm4py.discover_petri_net_inductive(
dataframe, activity_key=’concept:name’, case_id_key=’case:concept:name’, timestamp_key=’time:timestamp’
) tbr_diagnostics = pm4py.conformance_diagnostics_token_based_replay(
dataframe, net, im, fm, activity_key=’concept:name’, case_id_key=’case:concept:name’, timestamp_key=’time:timestamp’