pm4py / pm4py-core

Public repository for the PM4Py (Process Mining for Python) project.
https://pm4py.fit.fraunhofer.de
GNU General Public License v3.0
722 stars 286 forks source link

Apply-functions of Algorithms change log-objects #89

Closed japeberg closed 5 years ago

japeberg commented 5 years ago

Operating System: Ubuntu 18.04.2 LTS PM4PY-Version: 1.1.18

While trying to work with different discovery algorithms I stumbled upon this problem. Giving the log-object as a parameter to the apply-function of an discovery algorithm changes the log-object so that it is not usable anymore for other usage in the package (for example another discovery algorithm).

Minimal Example

from pm4py.objects.log.importer.csv import factory as csv_importer
from pm4py.algo.discovery.alpha import factory as alpha_miner
from pm4py.algo.discovery.inductive import factory as inductive_miner

log = csv_importer.import_event_log("running-example.csv")

alpha_petri, alpha_initial_marking, alpha_final_marking = alpha_miner.apply(log)
inductive_petri, inductive_initial_marking, inductive_final_marking = inductive_miner.apply(log)

Output

Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "/home/xxx/.local/share/JetBrains/Toolbox/apps/PyCharm-P/ch-0/191.7479.30/helpers/pydev/_pydev_bundle/pydev_umd.py", line 197, in runfile
    pydev_imports.execfile(filename, global_vars, local_vars)  # execute the script
  File "/home/xxx/.local/share/JetBrains/Toolbox/apps/PyCharm-P/ch-0/191.7479.30/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "/home/xxx/projects/yyyy/error_check_pm4py.py", line 11, in <module>
    inductive_petri, inductive_initial_marking, inductive_final_marking = inductive_miner.apply(log)
  File "/home/xxxx/projects/yyyy/venv/lib/python3.6/site-packages/pm4py/algo/discovery/inductive/factory.py", line 35, in apply
    return VERSIONS[variant](log_conversion.apply(log, parameters, log_conversion.TO_EVENT_LOG), parameters)
  File "/home/xxxx/projects/yyyy/venv/lib/python3.6/site-packages/pm4py/objects/conversion/log/factory.py", line 20, in apply
    return VERSIONS[variant](log, parameters=parameters)
  File "/home/xxxx/projects/yyyy/venv/lib/python3.6/site-packages/pm4py/objects/conversion/log/versions/to_event_log.py", line 32, in apply
    case_attribute_prefix=case_pref, enable_deepcopy=enable_deepcopy)
  File "/home/xxxx/projects/yyyy/venv/lib/python3.6/site-packages/pm4py/objects/conversion/log/versions/to_event_log.py", line 64, in transform_event_stream_to_event_log
    glue = event[case_glue]
KeyError: 'case:concept:name'

Expected Outcome would be a non-failure of inductive_miner.apply(log)

japeberg commented 5 years ago

Found my error. I was not aware that log = conversion_factory.apply(log) was necessary to perform.