pm4py / pm4py-core

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

Creating initial marking for alignments KeyError: 1d7d1b3f-ec36-410f-a0e8-65c7f905cd80 #149

Closed gertjanssenswillen closed 4 years ago

gertjanssenswillen commented 4 years ago

I'm trying to compute alignments for a petri net, and a log. The difficulty is that the both are imported, the net is not discovered from the log with pm4py Additional difficulty, when the net is imported, the initial marking is empty. So I tried to create one myself.


from pm4py.objects.log.importer.xes import factory as xes_importer
from pm4py.objects.petri.importer import pnml as pnml_importer
from pm4py.objects.petri.petrinet import PetriNet, Marking

log = xes_importer.import_log("merged_log_1.xes")

net, initial_marking, final_marking = pnml_importer.import_net("Petrinets/0_0_filtered_log_1.pnml")

print(net)
print(initial_marking)
print(final_marking)

inital_marking = Marking()

initial_marking[PetriNet.Place("1d7d1b3f-ec36-410f-a0e8-65c7f905cd80")] = 1

from pm4py.algo.conformance.alignments import factory as align_factory
alignments = align_factory.apply_log(log, net, initial_marking, final_marking)

print(alignments)

The error is the following:

`Traceback (most recent call last):

File "", line 1, in runfile('C:/Users/lucp8407/Documents/UH - Local/Python workspace/pm4py/ccc.py', wdir='C:/Users/lucp8407/Documents/UH - Local/Python workspace/pm4py')

File "C:\Users\lucp8407\AppData\Local\Continuum\anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 786, in runfile execfile(filename, namespace)

File "C:\Users\lucp8407\AppData\Local\Continuum\anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 110, in execfile exec(compile(f.read(), filename, 'exec'), namespace)

File "C:/Users/lucp8407/Documents/UH - Local/Python workspace/pm4py/ccc.py", line 26, in alignments = align_factory.apply_log(log, net, initial_marking, final_marking)

File "C:\Users\lucp8407\AppData\Local\Continuum\anaconda3\lib\site-packages\pm4py\algo\conformance\alignments\factory.py", line 139, in apply_log best_worst_cost = VERSIONS_COST[version](petri_net, initial_marking, final_marking, parameters=parameters)

File "C:\Users\lucp8407\AppData\Local\Continuum\anaconda3\lib\site-packages\pm4py\algo\conformance\alignments\versions\state_equation_a_star.py", line 72, in get_best_worst_cost parameters=new_parameters)

File "C:\Users\lucp8407\AppData\Local\Continuum\anaconda3\lib\site-packages\pm4py\algo\conformance\alignments\versions\state_equation_a_star.py", line 159, in apply trace_net_costs, parameters[PARAM_MODEL_COST_FUNCTION], revised_sync)

File "C:\Users\lucp8407\AppData\Local\Continuum\anaconda3\lib\site-packages\pm4py\objects\petri\synchronous_product.py", line 104, in construct_cost_aware sync_im[p2_map[p]] = im2[p]

KeyError: 1d7d1b3f-ec36-410f-a0e8-65c7f905cd80`

Any idea's what the cause might be, what I am doing wrong?

There's also a warning related to import_net being deprecated. What is the correct function, I based myself upon the documentation on the website?

fit-alessandro-berti commented 4 years ago

Dear Gert,

With the command, you are not picking the place from the existing Petri net, but instead creating a completely new place that is not contained in the Petri net

Hence the error!

To pick an existing place, a way is list comprehension, like:

my_place = [p for p in net.places if p.name = "1d7d1b3f-ec36-410f-a0e8-65c7f905cd80"][0] initial_marking = {my_place: 1}