{ "cells": [ { "metadata": { "ExecuteTime": { "end_time": "2026-05-29T14:06:21.624671300Z", "start_time": "2026-05-29T14:06:21.609661100Z" } }, "cell_type": "code", "source": [ "import warnings\n", "warnings.filterwarnings(\"ignore\", category=UserWarning)" ], "id": "940545f4d82e065d", "outputs": [], "execution_count": 1 }, { "cell_type": "markdown", "id": "5279e90c", "metadata": {}, "source": [ "# Conformance Checking with a DECLARE model\n", "\n", "This tutorial explains how to perform the conformance checking of a DECLARE model and how to browse the results. We start by importing the classes for managing with DECLARE models: `DeclareModel` and `DeclareModelTemplate`:" ] }, { "cell_type": "code", "id": "deea27bb", "metadata": { "ExecuteTime": { "end_time": "2026-05-29T14:06:23.305029200Z", "start_time": "2026-05-29T14:06:21.630954800Z" } }, "source": [ "import os\n", "\n", "from Declare4Py.ProcessModels.DeclareModel import DeclareModel" ], "outputs": [], "execution_count": 2 }, { "cell_type": "markdown", "id": "6f2f5b6f", "metadata": {}, "source": [ "The next step is the parsing of the log and of the DECLARE model." ] }, { "cell_type": "code", "id": "cefcfbac", "metadata": { "ExecuteTime": { "end_time": "2026-05-29T14:06:24.523911100Z", "start_time": "2026-05-29T14:06:23.335319300Z" } }, "source": [ "from Declare4Py.D4PyEventLog import D4PyEventLog\n", "\n", "log_path = os.path.join(\"../../../\", \"tests\", \"test_logs\",\"Sepsis Cases.xes.gz\")\n", "event_log = D4PyEventLog(case_name=\"case:concept:name\")\n", "event_log.parse_xes_log(log_path)\n", "\n", "model_path = os.path.join(\"../../../\", \"tests\", \"test_models\",\"data_model.decl\")\n", "declare_model = DeclareModel().parse_from_file(model_path)" ], "outputs": [ { "data": { "text/plain": [ "parsing log, completed traces :: 0%| | 0/1050 [00:00, ?it/s]" ], "application/vnd.jupyter.widget-view+json": { "version_major": 2, "version_minor": 0, "model_id": "dba49fbc972f43fe93e64c4aa6239fc1" } }, "metadata": {}, "output_type": "display_data" } ], "execution_count": 3 }, { "cell_type": "markdown", "id": "32fea405", "metadata": {}, "source": [ "We retrieve the constraints of the model." ] }, { "cell_type": "code", "id": "ea33c883", "metadata": { "ExecuteTime": { "end_time": "2026-05-29T14:06:24.555797700Z", "start_time": "2026-05-29T14:06:24.539906900Z" } }, "source": [ "model_constraints = declare_model.get_decl_model_constraints()\n", "\n", "print(\"Model constraints:\")\n", "print(\"-----------------\")\n", "for idx, constr in enumerate(model_constraints):\n", " print(idx, constr)" ], "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Model constraints:\n", "-----------------\n", "0 Existence2[Admission NC] | |\n", "1 Chain Response[Admission NC, Release B] |A.org:group is K |T.org:group is E |\n", "2 Chain Response[Admission NC, Release A] |A.org:group is I |T.org:group is E |133020,957701,s\n", "3 Chain Precedence[IV Liquid, Admission NC] |A.org:group is I |T.org:group is A |92,14473,s\n", "4 Chain Response[ER Registration, ER Triage] |(A.DiagnosticArtAstrup is false) AND (A.SIRSCritHeartRate is true) AND (A.org:group is A) AND (A.DiagnosticBlood is true) AND (A.DisfuncOrg is false) AND (A.DiagnosticECG is true) AND (A.Age >= 45) AND (A.InfectionSuspected is true) AND (A.DiagnosticLacticAcid is true) AND (A.DiagnosticSputum is true) AND (A.Hypoxie is false) AND (A.DiagnosticUrinaryCulture is true) AND (A.DiagnosticLiquor is false) AND (A.SIRSCritTemperature is true) AND (A.Infusion is true) AND (A.Hypotensie is false) AND (A.DiagnosticUrinarySediment is true) AND (A.Oligurie is false) AND (A.Age <= 80) AND (A.SIRSCritTachypnea is true) AND (A.DiagnosticOther is false) AND (A.SIRSCritLeucos is false) AND (A.DiagnosticIC is true) AND (A.SIRSCriteria2OrMore is true) AND (A.DiagnosticXthorax is true) |T.org:group is C |52,2154,s\n", "5 Chain Precedence[Release A, Return ER] |A.org:group is ? |T.org:group is E |1121801,1121801,s\n", "6 Chain Precedence[ER Sepsis Triage, IV Antibiotics] |A.org:group is L |T.org:group is L |15,11000,s\n", "7 Chain Response[ER Sepsis Triage, IV Antibiotics] |A.org:group is L |T.org:group is L |15,11000,s\n", "8 Chain Precedence[Admission IC, Admission NC] |A.org:group is J |T.org:group is J |\n", "9 Chain Precedence[IV Antibiotics, Admission NC] |A.org:group is F |T.org:group is A |92,14459,s\n", "10 Chain Precedence[Admission NC, Release B] |A.org:group is E |T.org:group is K |48225,48225,s\n", "11 Chain Response[Admission IC, Admission NC] |A.org:group is J |T.org:group is J |61534,61534,s\n", "12 Chain Response[LacticAcid, Leucocytes] |A.LacticAcid <= 0.8 |T.Leucocytes >= 13.8 |0,2778,m\n", "13 Chain Precedence[ER Registration, ER Triage] |A.org:group is C |(T.InfectionSuspected is true) AND (T.SIRSCritTemperature is true) AND (T.DiagnosticLacticAcid is true) AND (T.DiagnosticBlood is true) AND (T.DiagnosticIC is true) AND (T.SIRSCriteria2OrMore is true) AND (T.DiagnosticECG is true) |52,2154,s\n" ] } ], "execution_count": 4 }, { "cell_type": "markdown", "id": "e2a96f45", "metadata": {}, "source": [ "The class `MPDeclareAnalyzer` initializes the DECLARE conformance checking (Declare4Py implements the MP DECLARE analyzer algorithm). The `MPDeclareAnalyzer` constructor takes as an input the boolean parameter `consider_vacuity=true` that means that vacuously satisfied traces are considered as satisfied, violated otherwise. The constructor also needs the `event_log` and the `declare_model` objects. After this setting, the method `run` of the `MPDeclareAnalyzer` class will execute the task." ] }, { "cell_type": "code", "id": "52f2679d", "metadata": { "ExecuteTime": { "end_time": "2026-05-29T14:06:26.180113400Z", "start_time": "2026-05-29T14:06:24.555797700Z" } }, "source": [ "from Declare4Py.ProcessMiningTasks.ConformanceChecking.MPDeclareAnalyzer import MPDeclareAnalyzer\n", "from Declare4Py.ProcessMiningTasks.ConformanceChecking.MPDeclareResultsBrowser import MPDeclareResultsBrowser\n", "\n", "\n", "basic_checker = MPDeclareAnalyzer(log=event_log, declare_model=declare_model, consider_vacuity=False)\n", "conf_check_res: MPDeclareResultsBrowser = basic_checker.run()" ], "outputs": [], "execution_count": 5 }, { "cell_type": "markdown", "id": "d3592687", "metadata": {}, "source": [ "The result of the `run` method is a `ResultsBrowser` object that allows for the retrieval of the conformance checking results with the `get_metric()` method. This takes as input the `metric` parameter with values in `num_pendings`, `num_activations`, `num_fulfillments`, `num_violations` and `state`. This return a table whose rows are the results of each trace according to the DECLARE constraints in the model (as columns). For example, this execution" ] }, { "cell_type": "code", "id": "88771d4a", "metadata": { "ExecuteTime": { "end_time": "2026-05-29T14:06:26.323129100Z", "start_time": "2026-05-29T14:06:26.195609200Z" } }, "source": [ "conf_check_res.get_metric(metric=\"num_activations\")" ], "outputs": [ { "data": { "text/plain": [ " Existence2[Admission NC] | | \\\n", "0 None \n", "1 None \n", "2 None \n", "3 None \n", "4 None \n", "... ... \n", "1045 None \n", "1046 None \n", "1047 None \n", "1048 None \n", "1049 None \n", "\n", " Chain Response[Admission NC, Release B] |A.org:group is K |T.org:group is E | \\\n", "0 0 \n", "1 0 \n", "2 0 \n", "3 0 \n", "4 0 \n", "... ... \n", "1045 0 \n", "1046 0 \n", "1047 0 \n", "1048 0 \n", "1049 0 \n", "\n", " Chain Response[Admission NC, Release A] |A.org:group is I |T.org:group is E |133020,957701,s \\\n", "0 0 \n", "1 0 \n", "2 0 \n", "3 0 \n", "4 0 \n", "... ... \n", "1045 0 \n", "1046 0 \n", "1047 0 \n", "1048 0 \n", "1049 0 \n", "\n", " Chain Precedence[IV Liquid, Admission NC] |A.org:group is I |T.org:group is A |92,14473,s \\\n", "0 0 \n", "1 0 \n", "2 0 \n", "3 0 \n", "4 0 \n", "... ... \n", "1045 0 \n", "1046 0 \n", "1047 0 \n", "1048 0 \n", "1049 0 \n", "\n", " Chain Response[ER Registration, ER Triage] |(A.DiagnosticArtAstrup is false) AND (A.SIRSCritHeartRate is true) AND (A.org:group is A) AND (A.DiagnosticBlood is true) AND (A.DisfuncOrg is false) AND (A.DiagnosticECG is true) AND (A.Age >= 45) AND (A.InfectionSuspected is true) AND (A.DiagnosticLacticAcid is true) AND (A.DiagnosticSputum is true) AND (A.Hypoxie is false) AND (A.DiagnosticUrinaryCulture is true) AND (A.DiagnosticLiquor is false) AND (A.SIRSCritTemperature is true) AND (A.Infusion is true) AND (A.Hypotensie is false) AND (A.DiagnosticUrinarySediment is true) AND (A.Oligurie is false) AND (A.Age <= 80) AND (A.SIRSCritTachypnea is true) AND (A.DiagnosticOther is false) AND (A.SIRSCritLeucos is false) AND (A.DiagnosticIC is true) AND (A.SIRSCriteria2OrMore is true) AND (A.DiagnosticXthorax is true) |T.org:group is C |52,2154,s \\\n", "0 0 \n", "1 0 \n", "2 0 \n", "3 0 \n", "4 0 \n", "... ... \n", "1045 0 \n", "1046 0 \n", "1047 0 \n", "1048 0 \n", "1049 0 \n", "\n", " Chain Precedence[Release A, Return ER] |A.org:group is ? |T.org:group is E |1121801,1121801,s \\\n", "0 0 \n", "1 0 \n", "2 0 \n", "3 1 \n", "4 0 \n", "... ... \n", "1045 0 \n", "1046 0 \n", "1047 0 \n", "1048 0 \n", "1049 0 \n", "\n", " Chain Precedence[ER Sepsis Triage, IV Antibiotics] |A.org:group is L |T.org:group is L |15,11000,s \\\n", "0 0 \n", "1 0 \n", "2 0 \n", "3 0 \n", "4 0 \n", "... ... \n", "1045 0 \n", "1046 0 \n", "1047 0 \n", "1048 0 \n", "1049 0 \n", "\n", " Chain Response[ER Sepsis Triage, IV Antibiotics] |A.org:group is L |T.org:group is L |15,11000,s \\\n", "0 0 \n", "1 0 \n", "2 0 \n", "3 0 \n", "4 0 \n", "... ... \n", "1045 0 \n", "1046 0 \n", "1047 0 \n", "1048 0 \n", "1049 1 \n", "\n", " Chain Precedence[Admission IC, Admission NC] |A.org:group is J |T.org:group is J | \\\n", "0 0 \n", "1 0 \n", "2 0 \n", "3 0 \n", "4 0 \n", "... ... \n", "1045 0 \n", "1046 0 \n", "1047 0 \n", "1048 0 \n", "1049 0 \n", "\n", " Chain Precedence[IV Antibiotics, Admission NC] |A.org:group is F |T.org:group is A |92,14459,s \\\n", "0 0 \n", "1 1 \n", "2 0 \n", "3 1 \n", "4 0 \n", "... ... \n", "1045 1 \n", "1046 0 \n", "1047 0 \n", "1048 0 \n", "1049 0 \n", "\n", " Chain Precedence[Admission NC, Release B] |A.org:group is E |T.org:group is K |48225,48225,s \\\n", "0 0 \n", "1 0 \n", "2 0 \n", "3 0 \n", "4 0 \n", "... ... \n", "1045 0 \n", "1046 0 \n", "1047 0 \n", "1048 0 \n", "1049 0 \n", "\n", " Chain Response[Admission IC, Admission NC] |A.org:group is J |T.org:group is J |61534,61534,s \\\n", "0 0 \n", "1 0 \n", "2 0 \n", "3 0 \n", "4 0 \n", "... ... \n", "1045 0 \n", "1046 0 \n", "1047 0 \n", "1048 0 \n", "1049 0 \n", "\n", " Chain Response[LacticAcid, Leucocytes] |A.LacticAcid <= 0.8 |T.Leucocytes >= 13.8 |0,2778,m \\\n", "0 0 \n", "1 1 \n", "2 0 \n", "3 0 \n", "4 0 \n", "... ... \n", "1045 0 \n", "1046 0 \n", "1047 0 \n", "1048 1 \n", "1049 0 \n", "\n", " Chain Precedence[ER Registration, ER Triage] |A.org:group is C |(T.InfectionSuspected is true) AND (T.SIRSCritTemperature is true) AND (T.DiagnosticLacticAcid is true) AND (T.DiagnosticBlood is true) AND (T.DiagnosticIC is true) AND (T.SIRSCriteria2OrMore is true) AND (T.DiagnosticECG is true) |52,2154,s \n", "0 1 \n", "1 1 \n", "2 1 \n", "3 1 \n", "4 1 \n", "... ... \n", "1045 1 \n", "1046 1 \n", "1047 1 \n", "1048 1 \n", "1049 1 \n", "\n", "[1050 rows x 14 columns]" ], "text/html": [ "
| \n", " | Existence2[Admission NC] | | | \n", "Chain Response[Admission NC, Release B] |A.org:group is K |T.org:group is E | | \n", "Chain Response[Admission NC, Release A] |A.org:group is I |T.org:group is E |133020,957701,s | \n", "Chain Precedence[IV Liquid, Admission NC] |A.org:group is I |T.org:group is A |92,14473,s | \n", "Chain Response[ER Registration, ER Triage] |(A.DiagnosticArtAstrup is false) AND (A.SIRSCritHeartRate is true) AND (A.org:group is A) AND (A.DiagnosticBlood is true) AND (A.DisfuncOrg is false) AND (A.DiagnosticECG is true) AND (A.Age >= 45) AND (A.InfectionSuspected is true) AND (A.DiagnosticLacticAcid is true) AND (A.DiagnosticSputum is true) AND (A.Hypoxie is false) AND (A.DiagnosticUrinaryCulture is true) AND (A.DiagnosticLiquor is false) AND (A.SIRSCritTemperature is true) AND (A.Infusion is true) AND (A.Hypotensie is false) AND (A.DiagnosticUrinarySediment is true) AND (A.Oligurie is false) AND (A.Age <= 80) AND (A.SIRSCritTachypnea is true) AND (A.DiagnosticOther is false) AND (A.SIRSCritLeucos is false) AND (A.DiagnosticIC is true) AND (A.SIRSCriteria2OrMore is true) AND (A.DiagnosticXthorax is true) |T.org:group is C |52,2154,s | \n", "Chain Precedence[Release A, Return ER] |A.org:group is ? |T.org:group is E |1121801,1121801,s | \n", "Chain Precedence[ER Sepsis Triage, IV Antibiotics] |A.org:group is L |T.org:group is L |15,11000,s | \n", "Chain Response[ER Sepsis Triage, IV Antibiotics] |A.org:group is L |T.org:group is L |15,11000,s | \n", "Chain Precedence[Admission IC, Admission NC] |A.org:group is J |T.org:group is J | | \n", "Chain Precedence[IV Antibiotics, Admission NC] |A.org:group is F |T.org:group is A |92,14459,s | \n", "Chain Precedence[Admission NC, Release B] |A.org:group is E |T.org:group is K |48225,48225,s | \n", "Chain Response[Admission IC, Admission NC] |A.org:group is J |T.org:group is J |61534,61534,s | \n", "Chain Response[LacticAcid, Leucocytes] |A.LacticAcid <= 0.8 |T.Leucocytes >= 13.8 |0,2778,m | \n", "Chain Precedence[ER Registration, ER Triage] |A.org:group is C |(T.InfectionSuspected is true) AND (T.SIRSCritTemperature is true) AND (T.DiagnosticLacticAcid is true) AND (T.DiagnosticBlood is true) AND (T.DiagnosticIC is true) AND (T.SIRSCriteria2OrMore is true) AND (T.DiagnosticECG is true) |52,2154,s | \n", "
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | \n", "None | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "1 | \n", "
| 1 | \n", "None | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "1 | \n", "0 | \n", "0 | \n", "1 | \n", "1 | \n", "
| 2 | \n", "None | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "1 | \n", "
| 3 | \n", "None | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "1 | \n", "0 | \n", "0 | \n", "0 | \n", "1 | \n", "0 | \n", "0 | \n", "0 | \n", "1 | \n", "
| 4 | \n", "None | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "1 | \n", "
| ... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "
| 1045 | \n", "None | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "1 | \n", "0 | \n", "0 | \n", "0 | \n", "1 | \n", "
| 1046 | \n", "None | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "1 | \n", "
| 1047 | \n", "None | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "1 | \n", "
| 1048 | \n", "None | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "1 | \n", "1 | \n", "
| 1049 | \n", "None | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "1 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "1 | \n", "
1050 rows × 14 columns
\n", "