Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/hotfixes' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
fit-alessandro-berti committed Apr 12, 2024
2 parents 104d2db + 6687770 commit 0213b90
Show file tree
Hide file tree
Showing 69 changed files with 915 additions and 616 deletions.
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ RUN apt-get -y install g++ libboost-all-dev libncurses5-dev wget
RUN apt-get -y install libtool flex bison pkg-config g++ libssl-dev automake
RUN apt-get -y install libjemalloc-dev libboost-dev libboost-filesystem-dev libboost-system-dev libboost-regex-dev python3-dev autoconf flex bison cmake
RUN apt-get -y install libxml2-dev libxslt-dev libfreetype6-dev libsuitesparse-dev
RUN apt-get -y install libclang-16-dev llvm-16-dev
RUN pip install -U wheel six pytest
RUN pip install -U meson-python>=0.13.1 Cython>=3.0.6 ninja spin==0.8 build
RUN pip install deprecation==2.1.0 graphviz==0.20.3 intervaltree==3.1.0 networkx==3.3 packaging==24.0 python-dateutil==2.9.0.post0 pytz==2024.1 six==1.16.0 sortedcontainers==2.4.0 tzdata==2024.1
Expand All @@ -24,6 +25,7 @@ RUN pip install contourpy==1.2.1 fonttools==4.51.0 kiwisolver==1.4.5 matplotlib=
#RUN cd / && git clone https://github.com/scipy/scipy.git && cd /scipy && git submodule update --init && pip3 install .
#RUN cd / && git clone https://github.com/lxml/lxml.git && cd /lxml && pip3 install .
#RUN pip3 install matplotlib
#RUN cd / && git clone https://github.com/duckdb/duckdb.git && cd /duckdb && make && cd /duckdb/tools/pythonpkg && python3 setup.py install

COPY . /app
RUN cd /app && python setup.py install
9 changes: 6 additions & 3 deletions examples/align_approx_pt.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
import importlib.util
from pm4py.algo.discovery.inductive import algorithm as inductive
from pm4py.objects.log.importer.xes import importer as xes_importer
from pm4py.visualization.process_tree import visualizer as pt_vis
from pm4py.algo.conformance.alignments.process_tree import algorithm as align_approx
from pm4py.objects.petri_net.utils.align_utils import pretty_print_alignments
from examples import examples_conf
Expand All @@ -12,8 +12,11 @@ def execute_script():

log = xes_importer.apply(log_path)
tree = inductive.apply(log)
gviz = pt_vis.apply(tree, parameters={pt_vis.Variants.WO_DECORATION.value.Parameters.FORMAT: examples_conf.TARGET_IMG_FORMAT})
pt_vis.view(gviz)

if importlib.util.find_spec("graphviz"):
from pm4py.visualization.process_tree import visualizer as pt_vis
gviz = pt_vis.apply(tree, parameters={pt_vis.Variants.WO_DECORATION.value.Parameters.FORMAT: examples_conf.TARGET_IMG_FORMAT})
pt_vis.view(gviz)

print("start calculate approximated alignments")
approx_alignments = align_approx.apply(log, tree)
Expand Down
16 changes: 10 additions & 6 deletions examples/align_decomposition_ex_paper.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from pm4py.objects.petri_net.obj import PetriNet, Marking
from pm4py.objects.petri_net.utils.petri_utils import add_arc_from_to
from pm4py.visualization.petri_net import visualizer
from pm4py.objects.petri_net.utils import decomposition
from examples import examples_conf
import importlib.util


def execute_script():
Expand Down Expand Up @@ -82,13 +82,17 @@ def execute_script():
im[start] = 1
fm = Marking()
fm[end] = 1
gvizs = []
gvizs.append(visualizer.apply(net, im, final_marking=fm, parameters={"format": examples_conf.TARGET_IMG_FORMAT}))
visualizer.view(gvizs[len(gvizs) - 1])
decomposed_net = decomposition.decompose(net, im, fm)
for snet, sim, sfm in decomposed_net:
gvizs.append(visualizer.apply(snet, sim, final_marking=sfm, parameters={"format": examples_conf.TARGET_IMG_FORMAT}))
gvizs = []

if importlib.util.find_spec("graphviz"):
from pm4py.visualization.petri_net import visualizer

gvizs.append(visualizer.apply(net, im, final_marking=fm, parameters={"format": examples_conf.TARGET_IMG_FORMAT}))
visualizer.view(gvizs[len(gvizs) - 1])
for snet, sim, sfm in decomposed_net:
gvizs.append(visualizer.apply(snet, sim, final_marking=sfm, parameters={"format": examples_conf.TARGET_IMG_FORMAT}))
visualizer.view(gvizs[len(gvizs) - 1])


if __name__ == "__main__":
Expand Down
10 changes: 6 additions & 4 deletions examples/bpmn_from_pt_conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from pm4py.objects.log.importer.xes import importer as xes_import
from pm4py.objects.bpmn.exporter import exporter as bpmn_exporter
from examples import examples_conf
import importlib.util



Expand All @@ -14,10 +15,11 @@ def execute_script():
log = xes_import.apply(log_path)
ptree = inductive_miner.apply(log)
bpmn = pt_converter.apply(ptree, variant=pt_converter.Variants.TO_BPMN)
#bpmn = bpmn_layouter.apply(bpmn)
bpmn_exporter.apply(bpmn, "stru.bpmn")
os.remove("stru.bpmn")
pm4py.view_bpmn(bpmn, format=examples_conf.TARGET_IMG_FORMAT)

if importlib.util.find_spec("graphviz"):
bpmn_exporter.apply(bpmn, "stru.bpmn")
os.remove("stru.bpmn")
pm4py.view_bpmn(bpmn, format=examples_conf.TARGET_IMG_FORMAT)


if __name__ == "__main__":
Expand Down
4 changes: 3 additions & 1 deletion examples/bpmn_js_visualization.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import pm4py
import importlib.util


def execute_script():
log = pm4py.read_xes("../tests/input_data/running-example.xes")

bpmn_model = pm4py.discover_bpmn_inductive(log)

pm4py.view_bpmn(bpmn_model, variant_str="dagrejs")
if importlib.util.find_spec("graphviz"):
pm4py.view_bpmn(bpmn_model, variant_str="dagrejs")


if __name__ == "__main__":
Expand Down
20 changes: 11 additions & 9 deletions examples/corr_mining.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
from pm4py.statistics.start_activities.pandas import get as sa_get
from pm4py.statistics.end_activities.pandas import get as ea_get
from examples import examples_conf

from pm4py.visualization.dfg import visualizer as dfg_vis
import importlib.util


def execute_script():
Expand All @@ -25,13 +24,16 @@ def execute_script():
soj_time = soj_time_get.apply(df, parameters=parameters)
dfg, performance_dfg = correlation_miner.apply(df, variant=correlation_miner.Variants.CLASSIC,
parameters=parameters)
gviz_freq = dfg_vis.apply(dfg, activities_count=act_count, serv_time=soj_time, variant=dfg_vis.Variants.FREQUENCY,
parameters=parameters)
dfg_vis.view(gviz_freq)
gviz_perf = dfg_vis.apply(performance_dfg, activities_count=act_count, serv_time=soj_time,
variant=dfg_vis.Variants.PERFORMANCE,
parameters=parameters)
dfg_vis.view(gviz_perf)

if importlib.util.find_spec("grapviz"):
from pm4py.visualization.dfg import visualizer as dfg_vis
gviz_freq = dfg_vis.apply(dfg, activities_count=act_count, serv_time=soj_time, variant=dfg_vis.Variants.FREQUENCY,
parameters=parameters)
dfg_vis.view(gviz_freq)
gviz_perf = dfg_vis.apply(performance_dfg, activities_count=act_count, serv_time=soj_time,
variant=dfg_vis.Variants.PERFORMANCE,
parameters=parameters)
dfg_vis.view(gviz_perf)


if __name__ == "__main__":
Expand Down
9 changes: 6 additions & 3 deletions examples/cost_based_dfg.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import pm4py
import os
from pm4py.algo.discovery.dfg.adapters.pandas import df_statistics
from pm4py.visualization.dfg import visualizer as dfg_visualizer
from examples import examples_conf
import importlib.util


def execute_script():
log = pm4py.read_xes(os.path.join("..", "tests", "input_data", "roadtraffic100traces.xes"), return_legacy_log_object=False)
cost_based_dfg = df_statistics.get_dfg_graph(log, measure="cost", cost_attribute="amount")
gviz = dfg_visualizer.apply(cost_based_dfg, variant=dfg_visualizer.Variants.COST, parameters={"format": examples_conf.TARGET_IMG_FORMAT})
dfg_visualizer.view(gviz)

if importlib.util.find_spec("grapviz"):
from pm4py.visualization.dfg import visualizer as dfg_visualizer
gviz = dfg_visualizer.apply(cost_based_dfg, variant=dfg_visualizer.Variants.COST, parameters={"format": examples_conf.TARGET_IMG_FORMAT})
dfg_visualizer.view(gviz)


if __name__ == "__main__":
Expand Down
6 changes: 5 additions & 1 deletion examples/data_petri_nets.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from pm4py.objects.petri_net.data_petri_nets.data_marking import DataMarking
from pm4py.objects.log.importer.xes import importer as xes_importer
from examples import examples_conf
import importlib.util


def get_trans_by_name(net, name):
Expand All @@ -18,7 +19,10 @@ def get_trans_by_name(net, name):
def execute_script():
log = xes_importer.apply(os.path.join("..", "tests", "input_data", "roadtraffic100traces.xes"))
net, im, fm = pm4py.read_pnml(os.path.join("..", "tests", "input_data", "data_petri_net.pnml"), auto_guess_final_marking=True)
pm4py.view_petri_net(net, im, fm, format=examples_conf.TARGET_IMG_FORMAT)

if importlib.util.find_spec("graphviz"):
pm4py.view_petri_net(net, im, fm, format=examples_conf.TARGET_IMG_FORMAT)

aligned_traces = alignments.apply(log, net, im, fm, variant=alignments.Variants.VERSION_DIJKSTRA_LESS_MEMORY, parameters={"ret_tuple_as_trans_desc": True})
for index, trace in enumerate(log):
aligned_trace = aligned_traces[index]
Expand Down
29 changes: 16 additions & 13 deletions examples/dec_treplay_imdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

from pm4py.algo.discovery.inductive import algorithm as inductive_miner
from pm4py.objects.log.importer.xes import importer as xes_importer
from pm4py.visualization.petri_net import visualizer as pn_vis
from pm4py.objects.conversion.process_tree import converter as process_tree_converter
from examples import examples_conf
import importlib.util


def execute_script():
Expand All @@ -14,18 +14,21 @@ def execute_script():
# apply Inductive Miner
process_tree = inductive_miner.apply(log)
net, initial_marking, final_marking = process_tree_converter.apply(process_tree)
# get visualization
variant = pn_vis.Variants.PERFORMANCE
parameters_viz = {pn_vis.Variants.PERFORMANCE.value.Parameters.AGGREGATION_MEASURE: "mean", pn_vis.Variants.PERFORMANCE.value.Parameters.FORMAT: examples_conf.TARGET_IMG_FORMAT}
gviz = pn_vis.apply(net, initial_marking, final_marking, log=log, variant=variant,
parameters=parameters_viz)
pn_vis.view(gviz)
# do another visualization with frequency
variant = pn_vis.Variants.FREQUENCY
parameters_viz = {pn_vis.Variants.FREQUENCY.value.Parameters.FORMAT: examples_conf.TARGET_IMG_FORMAT}
gviz = pn_vis.apply(net, initial_marking, final_marking, log=log, variant=variant,
parameters=parameters_viz)
pn_vis.view(gviz)

if importlib.util.find_spec("graphviz"):
from pm4py.visualization.petri_net import visualizer as pn_vis
# get visualization
variant = pn_vis.Variants.PERFORMANCE
parameters_viz = {pn_vis.Variants.PERFORMANCE.value.Parameters.AGGREGATION_MEASURE: "mean", pn_vis.Variants.PERFORMANCE.value.Parameters.FORMAT: examples_conf.TARGET_IMG_FORMAT}
gviz = pn_vis.apply(net, initial_marking, final_marking, log=log, variant=variant,
parameters=parameters_viz)
pn_vis.view(gviz)
# do another visualization with frequency
variant = pn_vis.Variants.FREQUENCY
parameters_viz = {pn_vis.Variants.FREQUENCY.value.Parameters.FORMAT: examples_conf.TARGET_IMG_FORMAT}
gviz = pn_vis.apply(net, initial_marking, final_marking, log=log, variant=variant,
parameters=parameters_viz)
pn_vis.view(gviz)


if __name__ == "__main__":
Expand Down
18 changes: 11 additions & 7 deletions examples/decisiontree_align_example.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
from pm4py.objects.log.importer.xes import importer as xes_importer
from pm4py.algo.discovery.inductive import algorithm as inductive_miner
from pm4py.algo.decision_mining import algorithm
from pm4py.visualization.decisiontree import visualizer as visualizer
from pm4py.objects.conversion.process_tree import converter as process_tree_converter
from examples import examples_conf
import os
import importlib.util


def execute_script():
# in this case, we obtain a decision tree by alignments on a specific decision point
log = xes_importer.apply(os.path.join("..", "tests", "input_data", "running-example.xes"))
process_tree = inductive_miner.apply(log)
net, im, fm = process_tree_converter.apply(process_tree)
# we need to specify a decision point. In this case, the place p_10 is a suitable decision point
clf, feature_names, classes = algorithm.get_decision_tree(log, net, im, fm, decision_point="p_10")
# we can visualize the decision tree
gviz = visualizer.apply(clf, feature_names, classes,
parameters={visualizer.Variants.CLASSIC.value.Parameters.FORMAT: examples_conf.TARGET_IMG_FORMAT})
visualizer.view(gviz)

if importlib.util.find_spec("sklearn") and importlib.util.find_spec("graphviz"):
# we need to specify a decision point. In this case, the place p_10 is a suitable decision point
clf, feature_names, classes = algorithm.get_decision_tree(log, net, im, fm, decision_point="p_10")

# we can visualize the decision tree
from pm4py.visualization.decisiontree import visualizer as visualizer
gviz = visualizer.apply(clf, feature_names, classes,
parameters={visualizer.Variants.CLASSIC.value.Parameters.FORMAT: examples_conf.TARGET_IMG_FORMAT})
visualizer.view(gviz)


if __name__ == "__main__":
Expand Down
34 changes: 21 additions & 13 deletions examples/decisiontree_trivial_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
from pm4py.objects.log.importer.xes import importer as xes_importer
from pm4py.objects.log.util import get_class_representation
from pm4py.algo.transformation.log_to_features import algorithm as log_to_features
from pm4py.visualization.decisiontree import visualizer as dt_vis
from examples import examples_conf
import importlib.util


def execute_script():
Expand All @@ -16,21 +16,29 @@ def execute_script():
data, feature_names = log_to_features.apply(log, variant=log_to_features.Variants.TRACE_BASED)
# gets classes representation by final concept:name value (end activity)
target, classes = get_class_representation.get_class_representation_by_str_ev_attr_value_value(log, "concept:name")
# mine the decision tree given 'data' and 'target'
clf = ml_utils.DecisionTreeClassifier(max_depth=7)
clf.fit(data, target)
# visualize the decision tree
gviz = dt_vis.apply(clf, feature_names, classes, parameters={dt_vis.Variants.CLASSIC.value.Parameters.FORMAT: examples_conf.TARGET_IMG_FORMAT})
dt_vis.view(gviz)

if importlib.util.find_spec("sklearn") and importlib.util.find_spec("graphviz"):
# mine the decision tree given 'data' and 'target'
clf = ml_utils.DecisionTreeClassifier(max_depth=7)
clf.fit(data, target)

# visualize the decision tree
from pm4py.visualization.decisiontree import visualizer as dt_vis
gviz = dt_vis.apply(clf, feature_names, classes, parameters={dt_vis.Variants.CLASSIC.value.Parameters.FORMAT: examples_conf.TARGET_IMG_FORMAT})
dt_vis.view(gviz)

# gets classes representation by trace duration (threshold between the two classes = 200D)
target, classes = get_class_representation.get_class_representation_by_trace_duration(log, 2 * 8640000)
# mine the decision tree given 'data' and 'target'
clf = ml_utils.DecisionTreeClassifier(max_depth=7)
clf.fit(data, target)
# visualize the decision tree
gviz = dt_vis.apply(clf, feature_names, classes, parameters={dt_vis.Variants.CLASSIC.value.Parameters.FORMAT: examples_conf.TARGET_IMG_FORMAT})
dt_vis.view(gviz)

if importlib.util.find_spec("sklearn") and importlib.util.find_spec("graphviz"):
# mine the decision tree given 'data' and 'target'
clf = ml_utils.DecisionTreeClassifier(max_depth=7)
clf.fit(data, target)

# visualize the decision tree
from pm4py.visualization.decisiontree import visualizer as dt_vis
gviz = dt_vis.apply(clf, feature_names, classes, parameters={dt_vis.Variants.CLASSIC.value.Parameters.FORMAT: examples_conf.TARGET_IMG_FORMAT})
dt_vis.view(gviz)


if __name__ == "__main__":
Expand Down
12 changes: 8 additions & 4 deletions examples/dfg_align_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
from pm4py.algo.filtering.dfg import dfg_filtering
from pm4py.algo.conformance.alignments.dfg import algorithm as dfg_alignment
from pm4py.statistics.attributes.log import get
from pm4py.visualization.dfg import visualizer
from pm4py.objects.petri_net.utils import align_utils
from examples import examples_conf
import importlib.util


def execute_script():
Expand All @@ -32,9 +32,13 @@ def execute_script():
print(bb - aa)
print(sum(x["visited_states"] for x in aligned_traces))
print(sum(x["cost"] // align_utils.STD_MODEL_LOG_MOVE_COST for x in aligned_traces))
gviz = visualizer.apply(dfg, activities_count=ac, parameters={"start_activities": sa, "end_activities": ea,
"format": examples_conf.TARGET_IMG_FORMAT})
visualizer.view(gviz)

if importlib.util.find_spec("graphviz"):
from pm4py.visualization.dfg import visualizer
gviz = visualizer.apply(dfg, activities_count=ac, parameters={"start_activities": sa, "end_activities": ea,
"format": examples_conf.TARGET_IMG_FORMAT})
visualizer.view(gviz)

cc = time.time()
aligned_traces2 = petri_alignments.apply(log, net, im, fm,
variant=petri_alignments.Variants.VERSION_DIJKSTRA_LESS_MEMORY)
Expand Down
15 changes: 9 additions & 6 deletions examples/dfg_filt_act_paths_perc.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pm4py
from pm4py.visualization.dfg import visualizer as dfg_visualizer
from pm4py.algo.filtering.dfg import dfg_filtering
from examples import examples_conf
import importlib.util


def execute_script():
Expand All @@ -12,11 +12,14 @@ def execute_script():
dfg, sa, ea, act_count = dfg_filtering.filter_dfg_on_activities_percentage(dfg, sa, ea, act_count, 0.3)
# keep the specified amount of paths
dfg, sa, ea, act_count = dfg_filtering.filter_dfg_on_paths_percentage(dfg, sa, ea, act_count, 0.3)
# view the DFG
gviz = dfg_visualizer.apply(dfg, activities_count=act_count, parameters={dfg_visualizer.Variants.FREQUENCY.value.Parameters.START_ACTIVITIES: sa,
dfg_visualizer.Variants.FREQUENCY.value.Parameters.END_ACTIVITIES: ea,
dfg_visualizer.Variants.FREQUENCY.value.Parameters.FORMAT: examples_conf.TARGET_IMG_FORMAT})
dfg_visualizer.view(gviz)

if importlib.util.find_spec("graphviz"):
# view the DFG
from pm4py.visualization.dfg import visualizer as dfg_visualizer
gviz = dfg_visualizer.apply(dfg, activities_count=act_count, parameters={dfg_visualizer.Variants.FREQUENCY.value.Parameters.START_ACTIVITIES: sa,
dfg_visualizer.Variants.FREQUENCY.value.Parameters.END_ACTIVITIES: ea,
dfg_visualizer.Variants.FREQUENCY.value.Parameters.FORMAT: examples_conf.TARGET_IMG_FORMAT})
dfg_visualizer.view(gviz)


if __name__ == "__main__":
Expand Down
Loading

0 comments on commit 0213b90

Please sign in to comment.