Skip to content

Commit

Permalink
added notebook for the simulator
Browse files Browse the repository at this point in the history
  • Loading branch information
PimLeerkes committed Oct 26, 2024
1 parent 257bb30 commit 62f4d42
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 10 deletions.
2 changes: 1 addition & 1 deletion docs/getting_started/die.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.2"
"version": "3.12.7"
}
},
"nbformat": 4,
Expand Down
10 changes: 5 additions & 5 deletions docs/getting_started/mdp.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count": 14,
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -12,16 +12,16 @@
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<stormpy.storage.storage.PrismProgram at 0x7fe02abc5670>"
"<stormpy.storage.storage.PrismProgram at 0x7f6d6ab2c2f0>"
]
},
"execution_count": 15,
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
Expand Down Expand Up @@ -364,7 +364,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.4"
"version": "3.12.7"
}
},
"nbformat": 4,
Expand Down
99 changes: 99 additions & 0 deletions docs/getting_started/simulator.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "a8ddc37c-66d2-43e4-8162-6be19a1d70a1",
"metadata": {},
"outputs": [],
"source": [
"import stormvogel.simulator\n",
"import stormvogel.model\n",
"import examples.monty_hall"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "eb0fadc0-7bb6-4c1d-ae3e-9e16527726ab",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"ModelType.MDP with name None\n",
"\n",
"States:\n",
"State 0 with labels ['init'] and features {}\n",
"State 1 with labels ['carchosen'] and features {}\n",
"State 2 with labels ['open'] and features {}\n",
"State 3 with labels ['goatrevealed'] and features {}\n",
"State 4 with labels ['done'] and features {}\n",
"\n",
"Transitions:\n"
]
}
],
"source": [
"#we take for example the monty hall mdp model:\n",
"mdp = examples.monty_hall.create_monty_hall_mdp()\n",
"\n",
"#we cam then simulate the model with the simulator to create a partial model:\n",
"partial_model = stormvogel.simulator.simulate(mdp, runs=1, steps=4, seed=123456)\n",
"\n",
"print(partial_model)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "34d0c293-d090-4e3d-9e80-4351f5fcba62",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"initial state --(action: empty)--> state: 2 --(action: open2)--> state: 9 --(action: empty)--> state: 20 --(action: stay)--> state: 39\n"
]
}
],
"source": [
"#we can also simulate a path:\n",
"path = stormvogel.simulator.simulate_path(mdp, steps=4, seed=123456)\n",
"\n",
"print(path)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "6b03bb18-4c65-4544-9f2b-fd58682a829d",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python (stormvogel)",
"language": "python",
"name": "stormvogel-env"
},
"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.7"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
2 changes: 1 addition & 1 deletion docs/getting_started/study.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.2"
"version": "3.12.7"
}
},
"nbformat": 4,
Expand Down
5 changes: 5 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ authors = ["The stormvogel team"]
license = "GPLv3"
readme = "README.md"

packages = [
{ include = "stormvogel" },
{ include = "examples" }
]

[tool.poetry.dependencies]
python = "^3.11"
ipywidgets = "^8.1.3"
Expand Down
20 changes: 17 additions & 3 deletions stormvogel/simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,14 @@ def simulate_path(
seed: int | None = None,
) -> Path:
"""
Simulates the model a given number of steps and returns the path created by the process.
Simulates the model and returns the path created by the process.
Args:
model: The stormvogel model that the simulator should run on.
steps: The number of steps the simulator walks through the model.
scheduler: A stormvogel scheduler to determine what actions should be taken. Random if not provided.
seed: The seed for the function that determines for each state what the next state will be. Random seed if not provided.
Returns a path object.
"""

def get_range_index(stateid: int):
Expand Down Expand Up @@ -172,8 +179,15 @@ def simulate(
seed: int | None = None,
) -> stormvogel.model.Model | None:
"""
Simulates the model a given number of steps for a given number of runs.
Returns the partial model discovered by the simulator
Simulates the model.
Args:
model: The stormvogel model that the simulator should run on
steps: The number of steps the simulator walks through the model
runs: The number of times the model gets simulated.
scheduler: A stormvogel scheduler to determine what actions should be taken. Random if not provided.
seed: The seed for the function that determines for each state what the next state will be. Random seed if not provided.
Returns the partial model discovered by all the runs of the simulator together
"""

def get_range_index(stateid: int):
Expand Down

0 comments on commit 62f4d42

Please sign in to comment.