{ "cells": [ { "cell_type": "markdown", "id": "69319b5b", "metadata": {}, "source": [ "# Simulator\n", "If we have a transition system, it might be nice to run a simulation. In this case, we have an MDP that models a hungry lion. Depending on the state it is in, it needs to decide whether it wants to 'rawr' or 'hunt' in order to prevent reaching the state 'dead'." ] }, { "cell_type": "code", "execution_count": 1, "id": "220fc914", "metadata": { "execution": { "iopub.execute_input": "2026-03-26T10:41:35.930996Z", "iopub.status.busy": "2026-03-26T10:41:35.930820Z", "iopub.status.idle": "2026-03-26T10:41:36.372108Z", "shell.execute_reply": "2026-03-26T10:41:36.371561Z" } }, "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" }, { "data": { "text/plain": [ "" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from stormvogel import *\n", "\n", "lion = examples.create_lion_mdp()\n", "show(lion)" ] }, { "cell_type": "markdown", "id": "d599e867", "metadata": {}, "source": [ "Now, let's run a simulation of the lion! If we do not provide a scheduling function, then the simulator just does a random walk, taking a random choice each time." ] }, { "cell_type": "code", "execution_count": 2, "id": "3d4b7189", "metadata": { "execution": { "iopub.execute_input": "2026-03-26T10:41:36.379418Z", "iopub.status.busy": "2026-03-26T10:41:36.379045Z", "iopub.status.idle": "2026-03-26T10:41:36.382215Z", "shell.execute_reply": "2026-03-26T10:41:36.381738Z" }, "lines_to_next_cell": 2 }, "outputs": [], "source": [ "path = simulate_path(lion, steps=5, seed=1234)" ] }, { "cell_type": "markdown", "id": "e68eaa95", "metadata": { "lines_to_next_cell": 2 }, "source": [ "We could also provide a scheduling function to choose the actions ourselves. This is somewhat similar to the `bird` API." ] }, { "cell_type": "code", "execution_count": 3, "id": "cbe03391", "metadata": { "execution": { "iopub.execute_input": "2026-03-26T10:41:36.383843Z", "iopub.status.busy": "2026-03-26T10:41:36.383676Z", "iopub.status.idle": "2026-03-26T10:41:36.386503Z", "shell.execute_reply": "2026-03-26T10:41:36.386035Z" }, "lines_to_next_cell": 0 }, "outputs": [], "source": [ "def scheduler(s: State) -> Action:\n", " return Action(\"rawr\")\n", "\n", "\n", "path2 = stormvogel.simulator.simulate_path(\n", " lion, steps=5, seed=1234, scheduler=scheduler\n", ")" ] }, { "cell_type": "markdown", "id": "0aee7440", "metadata": {}, "source": [ "We can also use the scheduler to create a partial model. This model contains all the states that have been discovered by the the simulation." ] }, { "cell_type": "code", "execution_count": 4, "id": "5a9e04ab", "metadata": { "execution": { "iopub.execute_input": "2026-03-26T10:41:36.388115Z", "iopub.status.busy": "2026-03-26T10:41:36.387950Z", "iopub.status.idle": "2026-03-26T10:41:36.419662Z", "shell.execute_reply": "2026-03-26T10:41:36.419082Z" } }, "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" }, { "data": { "text/plain": [ "" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "partial_model = stormvogel.simulator.simulate(\n", " lion, steps=5, scheduler=scheduler, seed=1234\n", ")\n", "show(partial_model)" ] } ], "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": { "1b1989d851dc4b95bef2ef1204ed3e94": { "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 } }, "25bc95325c654540abe531ea5beff1bb": { "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 } }, "578a1e3b5fdf4482b85d1b1b3885cbef": { "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_25bc95325c654540abe531ea5beff1bb", "msg_id": "", "outputs": [], "tabbable": null, "tooltip": null } }, "5c21310d0c8b48bc9fe3e344fef2ea5e": { "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_fe77cc8776b3468ea7480ea597be7ea1", "msg_id": "", "outputs": [], "tabbable": null, "tooltip": null } }, "5c37281f26d343eb9820b6ee9dc79b08": { "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 } }, "797423506866429eb48683fcd3432c27": { "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_1b1989d851dc4b95bef2ef1204ed3e94", "msg_id": "", "outputs": [], "tabbable": null, "tooltip": null } }, "9fd17190b701431fbc88e550190a374f": { "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_5c37281f26d343eb9820b6ee9dc79b08", "msg_id": "", "outputs": [], "tabbable": null, "tooltip": null } }, "fe77cc8776b3468ea7480ea597be7ea1": { "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 }