{ "cells": [ { "cell_type": "markdown", "id": "4fa0c0e3", "metadata": {}, "source": [ "# Stormpy Conversion\n", "Models can be converted back and forth between stormvogel and stormpy with ease using the `mapping` module.
\n", "This is useful, because this allows you to combine both APIs. For example, you could create a model in stormvogel becuase it has an easy API, do some model checking in stormpy, and then convert it back to display the results. (Note that there is also a direct model checking function available that uses stormpy behind the scenes.)" ] }, { "cell_type": "code", "execution_count": 1, "id": "068e24ad", "metadata": { "execution": { "iopub.execute_input": "2026-03-26T10:47:21.721822Z", "iopub.status.busy": "2026-03-26T10:47:21.721593Z", "iopub.status.idle": "2026-03-26T10:47:22.114345Z", "shell.execute_reply": "2026-03-26T10:47:22.113769Z" } }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", " \n", " Network\n", " \n", " \n", " \n", " \n", " \n", "
\n", " \n", " \n", " \n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "from stormvogel import *\n", "\n", "stormvogel_model = examples.create_car_mdp()\n", "vis = show(stormvogel_model, layout=stormvogel.layout.Layout(\"layouts/car.json\"))" ] }, { "cell_type": "markdown", "id": "7dbdd35f", "metadata": {}, "source": [ "First, let's convert the stormvogel model to the same model in stormpy." ] }, { "cell_type": "code", "execution_count": 2, "id": "42933703", "metadata": { "execution": { "iopub.execute_input": "2026-03-26T10:47:22.121426Z", "iopub.status.busy": "2026-03-26T10:47:22.121110Z", "iopub.status.idle": "2026-03-26T10:47:22.124663Z", "shell.execute_reply": "2026-03-26T10:47:22.124165Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "-------------------------------------------------------------- \n", "Model type: \tMDP (sparse)\n", "States: \t5\n", "Transitions: \t9\n", "Choices: \t9\n", "Reward Models: none\n", "State Labels: \t6 labels\n", " * red light -> 2 item(s)\n", " * init -> 1 item(s)\n", " * accident -> 1 item(s)\n", " * still -> 2 item(s)\n", " * moving -> 2 item(s)\n", " * green light -> 2 item(s)\n", "Choice Labels: \t3 labels\n", " * wait -> 4 item(s)\n", " * accelerate -> 2 item(s)\n", " * brake -> 2 item(s)\n", "-------------------------------------------------------------- \n", "\n" ] } ], "source": [ "import stormvogel.stormpy_utils.mapping as mapping\n", "\n", "stormpy_model = mapping.stormvogel_to_stormpy(stormvogel_model)\n", "print(stormpy_model)" ] }, { "cell_type": "markdown", "id": "5d27a12b", "metadata": {}, "source": [ "And now we convert it back." ] }, { "cell_type": "code", "execution_count": 3, "id": "ecc70aed", "metadata": { "execution": { "iopub.execute_input": "2026-03-26T10:47:22.126265Z", "iopub.status.busy": "2026-03-26T10:47:22.126099Z", "iopub.status.idle": "2026-03-26T10:47:22.155382Z", "shell.execute_reply": "2026-03-26T10:47:22.154831Z" } }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", " \n", " Network\n", " \n", " \n", " \n", " \n", " \n", "
\n", " \n", " \n", " \n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "stormvogel_model2 = mapping.stormpy_to_stormvogel(stormpy_model)\n", "vis = show(stormvogel_model2, layout=Layout(\"layouts/car.json\"))" ] }, { "cell_type": "markdown", "id": "99f6d70a", "metadata": {}, "source": [ "The result of the double conversion is equal to the original model." ] }, { "cell_type": "code", "execution_count": 4, "id": "7e0a543a", "metadata": { "execution": { "iopub.execute_input": "2026-03-26T10:47:22.162186Z", "iopub.status.busy": "2026-03-26T10:47:22.162021Z", "iopub.status.idle": "2026-03-26T10:47:22.165706Z", "shell.execute_reply": "2026-03-26T10:47:22.165228Z" } }, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "stormvogel_model == stormvogel_model2" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.12.13" }, "widgets": { "application/vnd.jupyter.widget-state+json": { "state": { "2412f02db6064ed5b69f3bc754171855": { "model_module": "@jupyter-widgets/base", "model_module_version": "2.0.0", "model_name": "LayoutModel", "state": { "_model_module": "@jupyter-widgets/base", "_model_module_version": "2.0.0", "_model_name": "LayoutModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "2.0.0", "_view_name": "LayoutView", "align_content": null, "align_items": null, "align_self": null, "border_bottom": null, "border_left": null, "border_right": null, "border_top": null, "bottom": null, "display": null, "flex": null, "flex_flow": null, "grid_area": null, "grid_auto_columns": null, "grid_auto_flow": null, "grid_auto_rows": null, "grid_column": null, "grid_gap": null, "grid_row": null, "grid_template_areas": null, "grid_template_columns": null, "grid_template_rows": null, "height": null, "justify_content": null, "justify_items": null, "left": null, "margin": null, "max_height": null, "max_width": null, "min_height": null, "min_width": null, "object_fit": null, "object_position": null, "order": null, "overflow": null, "padding": null, "right": null, "top": null, "visibility": null, "width": null } }, "31f27ddce5bc4b0180e08fb79df4642c": { "model_module": "@jupyter-widgets/base", "model_module_version": "2.0.0", "model_name": "LayoutModel", "state": { "_model_module": "@jupyter-widgets/base", "_model_module_version": "2.0.0", "_model_name": "LayoutModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "2.0.0", "_view_name": "LayoutView", "align_content": null, "align_items": null, "align_self": null, "border_bottom": null, "border_left": null, "border_right": null, "border_top": null, "bottom": null, "display": null, "flex": null, "flex_flow": null, "grid_area": null, "grid_auto_columns": null, "grid_auto_flow": null, "grid_auto_rows": null, "grid_column": null, "grid_gap": null, "grid_row": null, "grid_template_areas": null, "grid_template_columns": null, "grid_template_rows": null, "height": null, "justify_content": null, "justify_items": null, "left": null, "margin": null, "max_height": null, "max_width": null, "min_height": null, "min_width": null, "object_fit": null, "object_position": null, "order": null, "overflow": null, "padding": null, "right": null, "top": null, "visibility": null, "width": null } }, "499996e8e3ad4c2a8923575785ed1bc9": { "model_module": "@jupyter-widgets/base", "model_module_version": "2.0.0", "model_name": "LayoutModel", "state": { "_model_module": "@jupyter-widgets/base", "_model_module_version": "2.0.0", "_model_name": "LayoutModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "2.0.0", "_view_name": "LayoutView", "align_content": null, "align_items": null, "align_self": null, "border_bottom": null, "border_left": null, "border_right": null, "border_top": null, "bottom": null, "display": null, "flex": null, "flex_flow": null, "grid_area": null, "grid_auto_columns": null, "grid_auto_flow": null, "grid_auto_rows": null, "grid_column": null, "grid_gap": null, "grid_row": null, "grid_template_areas": null, "grid_template_columns": null, "grid_template_rows": null, "height": null, "justify_content": null, "justify_items": null, "left": null, "margin": null, "max_height": null, "max_width": null, "min_height": null, "min_width": null, "object_fit": null, "object_position": null, "order": null, "overflow": null, "padding": null, "right": null, "top": null, "visibility": null, "width": null } }, "59012d1345e64e8f88485c215c393d38": { "model_module": "@jupyter-widgets/output", "model_module_version": "1.0.0", "model_name": "OutputModel", "state": { "_dom_classes": [], "_model_module": "@jupyter-widgets/output", "_model_module_version": "1.0.0", "_model_name": "OutputModel", "_view_count": null, "_view_module": "@jupyter-widgets/output", "_view_module_version": "1.0.0", "_view_name": "OutputView", "layout": "IPY_MODEL_2412f02db6064ed5b69f3bc754171855", "msg_id": "", "outputs": [], "tabbable": null, "tooltip": null } }, "75e3cb66f912427295aa2e2117e8623a": { "model_module": "@jupyter-widgets/output", "model_module_version": "1.0.0", "model_name": "OutputModel", "state": { "_dom_classes": [], "_model_module": "@jupyter-widgets/output", "_model_module_version": "1.0.0", "_model_name": "OutputModel", "_view_count": null, "_view_module": "@jupyter-widgets/output", "_view_module_version": "1.0.0", "_view_name": "OutputView", "layout": "IPY_MODEL_499996e8e3ad4c2a8923575785ed1bc9", "msg_id": "", "outputs": [], "tabbable": null, "tooltip": null } }, "9998a330e33844eb9e846b251c3599b1": { "model_module": "@jupyter-widgets/output", "model_module_version": "1.0.0", "model_name": "OutputModel", "state": { "_dom_classes": [], "_model_module": "@jupyter-widgets/output", "_model_module_version": "1.0.0", "_model_name": "OutputModel", "_view_count": null, "_view_module": "@jupyter-widgets/output", "_view_module_version": "1.0.0", "_view_name": "OutputView", "layout": "IPY_MODEL_a95d419e218240e8984c97bb595bcd01", "msg_id": "", "outputs": [], "tabbable": null, "tooltip": null } }, "a4da0cea0ccd4d6da9192e3747570569": { "model_module": "@jupyter-widgets/output", "model_module_version": "1.0.0", "model_name": "OutputModel", "state": { "_dom_classes": [], "_model_module": "@jupyter-widgets/output", "_model_module_version": "1.0.0", "_model_name": "OutputModel", "_view_count": null, "_view_module": "@jupyter-widgets/output", "_view_module_version": "1.0.0", "_view_name": "OutputView", "layout": "IPY_MODEL_31f27ddce5bc4b0180e08fb79df4642c", "msg_id": "", "outputs": [], "tabbable": null, "tooltip": null } }, "a95d419e218240e8984c97bb595bcd01": { "model_module": "@jupyter-widgets/base", "model_module_version": "2.0.0", "model_name": "LayoutModel", "state": { "_model_module": "@jupyter-widgets/base", "_model_module_version": "2.0.0", "_model_name": "LayoutModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "2.0.0", "_view_name": "LayoutView", "align_content": null, "align_items": null, "align_self": null, "border_bottom": null, "border_left": null, "border_right": null, "border_top": null, "bottom": null, "display": null, "flex": null, "flex_flow": null, "grid_area": null, "grid_auto_columns": null, "grid_auto_flow": null, "grid_auto_rows": null, "grid_column": null, "grid_gap": null, "grid_row": null, "grid_template_areas": null, "grid_template_columns": null, "grid_template_rows": null, "height": null, "justify_content": null, "justify_items": null, "left": null, "margin": null, "max_height": null, "max_width": null, "min_height": null, "min_width": null, "object_fit": null, "object_position": null, "order": null, "overflow": null, "padding": null, "right": null, "top": null, "visibility": null, "width": null } } }, "version_major": 2, "version_minor": 0 } } }, "nbformat": 4, "nbformat_minor": 5 }