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

Trouble using function solve_marking_equation #415

Closed chlauer99 closed 1 year ago

chlauer99 commented 1 year ago

Hello, I wanted to use the result the solution of the marking equation as heuristic in my code. Luckily I found a fitting function in pm4py, which solves such equations, namely solve_marking_equation. But during testing it appeared that the function does not work properly in my implementation. After researching and trying out a few things, I still don't what the root cause for this error is.

The following error appears for every setting I tried:

Error Traceback (most recent call last): File "/Users/chlau/anaconda3/lib/python3.9/site-packages/cvxopt/coneprog.py", line 680, in conelp try: f = kktsolver(W) File "/Users/chlau/anaconda3/lib/python3.9/site-packages/cvxopt/coneprog.py", line 585, in kktsolver return factor(W) File "/Users/chlau/anaconda3/lib/python3.9/site-packages/cvxopt/misc.py", line 1472, in factor lapack.potrf(F['K']) ArithmeticError: 9

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/Users/chlau/Library/CloudStorage/OneDrive-Persönlich/Dokumente/UNI/DFKI/geclont/rmm4py-ml/tests/prediction_models/discovery_prediction/test_petri_net_estimator.py", line 214, in test_compute_probability_distribution check_distribution(prefix_probability_1, self.prob_net) File "/Users/chlau/Library/CloudStorage/OneDrive-Persönlich/Dokumente/UNI/DFKI/geclont/rmm4py-ml/tests/prediction_models/discovery_prediction/test_petri_net_estimator.py", line 181, in check_distribution prob_dist_computed = model.compute_probability_distribution_from_prefix(prefix=list(prefix.split(" "))) File "/Users/chlau/Library/CloudStorage/OneDrive-Persönlich/Dokumente/UNI/DFKI/geclont/rmm4py-ml/src/rmm4pyml/prediction_models/discovery_prediction/petri_net_estimator.py", line 431, in compute_probability_distribution_from_prefix replay_result = self.align_and_replay(prefix) File "/Users/chlau/Library/CloudStorage/OneDrive-Persönlich/Dokumente/UNI/DFKI/geclont/rmm4py-ml/src/rmm4pyml/prediction_models/discovery_prediction/petri_net_estimator.py", line 417, in align_and_replay aligned_prefix = align_prefix_to_model(prefix=prefix, petri_net_esti=self) File "/Users/chlau/Library/CloudStorage/OneDrive-Persönlich/Dokumente/UNI/DFKI/geclont/rmm4py-ml/src/rmm4pyml/prediction_models/discovery_prediction/prefix_alignment.py", line 80, in align_prefix_to_model alignment = compute_prefix_alignment(prefix=prefix, start_state=start_state, petri_net_esti=petri_net_esti) File "/Users/chlau/Library/CloudStorage/OneDrive-Persönlich/Dokumente/UNI/DFKI/geclont/rmm4py-ml/src/rmm4pyml/prediction_models/discovery_prediction/prefix_alignment.py", line 134, in compute_prefix_alignment next_activities, states, goal_t = shortest_path(states=states, start=last_t, File "/Users/chlau/Library/CloudStorage/OneDrive-Persönlich/Dokumente/UNI/DFKI/geclont/rmm4py-ml/src/rmm4pyml/prediction_models/discovery_prediction/prefix_alignment.py", line 209, in shortest_path costs = g_new + compute_heuristic(net=petri_net_esti.petri_net, i_m=petri_net_esti.initial_marking, File "/Users/chlau/Library/CloudStorage/OneDrive-Persönlich/Dokumente/UNI/DFKI/geclont/rmm4py-ml/src/rmm4pyml/prediction_models/discovery_prediction/prefix_alignment.py", line 322, in compute_heuristic heuristic = solve_marking_equation(petri_net=net, initial_marking=i_m, final_marking=f_m) File "/Users/chlau/anaconda3/lib/python3.9/site-packages/pm4py/analysis.py", line 118, in solve_marking_equation return marking_equation.get_h_value(me) File "/Users/chlau/anaconda3/lib/python3.9/site-packages/pm4py/algo/analysis/marking_equation/algorithm.py", line 71, in get_h_value return exec_utils.get_variant(variant).get_h_value(solver, parameters=parameters) File "/Users/chlau/anaconda3/lib/python3.9/site-packages/pm4py/algo/analysis/marking_equation/variants/classic.py", line 325, in get_h_value return solver.solve()[0] File "/Users/chlau/anaconda3/lib/python3.9/site-packages/pm4py/algo/analysis/marking_equation/variants/classic.py", line 219, in solve return self.solve_given_components(c, Aub, bub, Aeq, beq) File "/Users/chlau/anaconda3/lib/python3.9/site-packages/pm4py/algo/analysis/marking_equation/variants/classic.py", line 252, in solve_given_components sol = solver.apply(c, Aub, bub, Aeq, beq, variant=solver.DEFAULT_LP_SOLVER_VARIANT) File "/Users/chlau/anaconda3/lib/python3.9/site-packages/pm4py/util/lp/solver.py", line 115, in apply return VERSIONS_APPLY[variant](c, Aub, bub, Aeq, beq, parameters=parameters) File "/Users/chlau/anaconda3/lib/python3.9/site-packages/pm4py/util/lp/variants/cvxopt_solver.py", line 71, in apply sol = solvers.lp(c, Aub, bub, A=Aeq, b=beq) File "/Users/chlau/anaconda3/lib/python3.9/site-packages/cvxopt/coneprog.py", line 3009, in lp return conelp(c, G, h, {'l': m, 'q': [], 's': []}, A, b, primalstart, File "/Users/chlau/anaconda3/lib/python3.9/site-packages/cvxopt/coneprog.py", line 682, in conelp raise ValueError("Rank(A) < p or Rank([G; A]) < n") ValueError: Rank(A) < p or Rank([G; A]) < n

I used the function as advised in the Documentation: from pm4py.read import read_pnml from pm4py.analysis import solve_marking_equation net, im, fm = read_pnml('model.pnml') save_vis_petri_net(petri_net=net, initial_marking=im, final_marking=fm, file_path="model_vis.jpg") heuristic = solve_marking_equation(net, im, fm)

Here is also a list of the versions of packages and python I'm currently using:

Could you please help me to fix this problem?

fit-alessandro-berti commented 1 year ago

First thing, try to uninstall the package "cvxopt"

pip uninstall cvxopt

Let us know if with Scipy as solver it works or it is still broken

chlauer99 commented 1 year ago

Thank you, that did work!