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

pm4py.analysis.check_soundness TypeError #392

Closed simonediluna closed 1 year ago

simonediluna commented 1 year ago

The pm4py.analysis.check_soundness function raises a TypeError on a particular workflow net. I analyzed the tpn file with Woflan software and the analysis was successful. Attached you can find the txt file of the net. To be read in pm4py, it must be converted back to pnml format.

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[133], line 1
----> 1 pm.analysis.check_soundness(net, ip, fp)

File ~\anaconda3\envs\bpm_env\lib\site-packages\pm4py\analysis.py:182, in check_soundness(petri_net, initial_marking, final_marking)
    157 """
    158 Check if a given Petri net is a sound WF-net.
    159 A Petri net is a WF-net iff:
   (...)
    179     is_sound = pm4py.check_soundness(net, im, fm)
    180 """
    181 from pm4py.algo.analysis.woflan import algorithm as woflan
--> 182 return woflan.apply(petri_net, initial_marking, final_marking)

File ~\anaconda3\envs\bpm_env\lib\site-packages\pm4py\algo\analysis\woflan\algorithm.py:574, in apply(net, i_m, f_m, parameters)
    571 return_diagnostics = exec_utils.get_param_value(Parameters.RETURN_DIAGNOSTICS, parameters, False)
    573 woflan_object = woflan(net, i_m, f_m, print_diagnostics=print_diagnostics)
--> 574 step_1_res = step_1(woflan_object, return_asap_when_unsound=return_asap_when_unsound)
    576 if return_diagnostics:
    577     return step_1_res, woflan_object.get_output()

File ~\anaconda3\envs\bpm_env\lib\site-packages\pm4py\algo\analysis\woflan\algorithm.py:330, in step_1(woflan_object, return_asap_when_unsound)
    328             if woflan_object.print_diagnostics:
    329                 print('Input is ok.')
--> 330             return step_2(woflan_object, return_asap_when_unsound=return_asap_when_unsound)
    331 woflan_object.diagnostic_messages.append('The Petri Net is not PM4Py Petri Net represenatation.')
    332 if woflan_object.print_diagnostics:

File ~\anaconda3\envs\bpm_env\lib\site-packages\pm4py\algo\analysis\woflan\algorithm.py:381, in step_2(woflan_object, return_asap_when_unsound)
    379 if woflan_object.print_diagnostics:
    380     print('Petri Net is a workflow net.')
--> 381 return step_3(woflan_object, return_asap_when_unsound=return_asap_when_unsound)

File ~\anaconda3\envs\bpm_env\lib\site-packages\pm4py\algo\analysis\woflan\algorithm.py:386, in step_3(woflan_object, return_asap_when_unsound)
    384 def step_3(woflan_object, return_asap_when_unsound=False):
    385     woflan_object.set_place_invariants(compute_place_invariants(woflan_object.get_s_c_net()))
--> 386     woflan_object.set_uniform_place_invariants(transform_basis(woflan_object.get_place_invariants(), style='uniform'))
    387     woflan_object.set_s_components(
    388         compute_s_components(woflan_object.get_s_c_net(), woflan_object.get_uniform_place_invariants()))
    389     woflan_object.set_uncovered_places_s_component(
    390         compute_uncovered_places_in_component(woflan_object.get_s_components(), woflan_object.get_s_c_net()))

File ~\anaconda3\envs\bpm_env\lib\site-packages\pm4py\algo\analysis\woflan\place_invariants\utility.py:158, in transform_basis(basis, style)
    156         elif style == "uniform":
    157             for i in range(len(new_vector)):
--> 158                 new_vector[i] = points[len(set_B) + 1 + i]
    159         modified_base.append(new_vector)
    161 return modified_base

TypeError: 'NoneType' object is not subscriptable

wf_system.txt

fit-alessandro-berti commented 1 year ago

Dear @simonediluna

Thanks for signaling. We will investigate the problem and come back with a solution.

fit-alessandro-berti commented 1 year ago

Dear @simonediluna

Sorry for the long time in working this issue. The issue is resolved in pm4py 2.7.2 We found several problems that deserved our attention:

1) The (I)LP solution provided by our default Scipy solver is not always correct. We suggest to install pulp (pip install pulp) which for the given class of LP is more stable. Then pulp would be used as new default. 2) There was some undeterminism in the lists of places/transitions all along the code. They were stored as sets in the Petri net but when doing list(net.places) and list(net.transitions), the places/transitions were not always returned in the same order. 3) Also, there was a problem in the LP which we fixed.

Cheers

simonediluna commented 1 year ago

Great, the check_soundness method completes the analysis successfully now. I would just like to point out that its output is no longer a boolean value, as stated in the documentation, but a tuple.

Best.