Skip to content

Commit

Permalink
fix linter?
Browse files Browse the repository at this point in the history
  • Loading branch information
YouGuessedMyName committed Jan 4, 2025
1 parent 78048e8 commit aebe127
Show file tree
Hide file tree
Showing 22 changed files with 47,440 additions and 47,456 deletions.
26,382 changes: 13,191 additions & 13,191 deletions docs/getting_started/00_die.ipynb

Large diffs are not rendered by default.

26,606 changes: 13,303 additions & 13,303 deletions docs/getting_started/01_study.ipynb

Large diffs are not rendered by default.

2,094 changes: 1,047 additions & 1,047 deletions docs/getting_started/02_naive_value_iteration.ipynb

Large diffs are not rendered by default.

28,200 changes: 14,100 additions & 14,100 deletions docs/getting_started/03_prism.ipynb

Large diffs are not rendered by default.

3,268 changes: 1,634 additions & 1,634 deletions docs/getting_started/04_mdp.ipynb

Large diffs are not rendered by default.

5,802 changes: 2,901 additions & 2,901 deletions docs/getting_started/05_simulator.ipynb

Large diffs are not rendered by default.

656 changes: 328 additions & 328 deletions docs/getting_started/07_pomdp.ipynb

Large diffs are not rendered by default.

1,746 changes: 873 additions & 873 deletions docs/getting_started/08_pomdp-maze.ipynb

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions docs/getting_started/die.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@
></script>
<style type="text/css">
#mynetwork {
width: 800px;
height: 600px;
border: 1px solid lightgray;
}
</style>
</head>
<body>
<div id="mynetwork"></div>
<script type="text/javascript">
var nodes = new vis.DataSet([{ id: 0, label: `init`, group: "states" },
{ id: 1, label: `rolled1`, group: "states" },
{ id: 2, label: `rolled2`, group: "states" },
Expand Down Expand Up @@ -207,4 +207,4 @@
"
border:none !important;
allowfullscreen webkitallowfullscreen mozallowfullscreen
></iframe>
></iframe>
2 changes: 1 addition & 1 deletion docs/getting_started/layouts/pinkgreen.json
Original file line number Diff line number Diff line change
Expand Up @@ -153,4 +153,4 @@
"resultSymbol": "\u2606",
"show_rewards": true
}
}
}
8 changes: 4 additions & 4 deletions docs/getting_started/lion.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@
&gt;&lt;/script&gt;
&lt;style type=&quot;text/css&quot;&gt;
#mynetwork {
width: 687px;
height: 519px;
border: 1px solid lightgray;
}
&lt;/style&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;div id=&quot;mynetwork&quot;&gt;&lt;/div&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
var nodes = new vis.DataSet([{ id: 0, label: `init`, group: &quot;states&quot;, x: -253, y: -205 },
{ id: 1, label: `full :D`, group: &quot;states&quot;, x: 18, y: 193 },
{ id: 2, label: `satisfied :)`, group: &quot;states&quot;, x: -27, y: -59 },
Expand Down Expand Up @@ -346,4 +346,4 @@
"
border:none !important;
allowfullscreen webkitallowfullscreen mozallowfullscreen
></iframe>
></iframe>
8 changes: 4 additions & 4 deletions docs/getting_started/model.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@
&gt;&lt;/script&gt;
&lt;style type=&quot;text/css&quot;&gt;
#mynetwork {

width: 800px;
height: 600px;
border: 1px solid lightgray;

}
&lt;/style&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;div id=&quot;mynetwork&quot;&gt;&lt;/div&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
<<<<<<< HEAD

var nodes = new vis.DataSet([{ id: 0, label: `escaped
ʘ 4`, group: &quot;states&quot;, x: -297, y: 598 },
{ id: 1, label: `t,(1,1)
Expand Down Expand Up @@ -664,4 +664,4 @@
"
border:none !important;
allowfullscreen webkitallowfullscreen mozallowfullscreen
></iframe>
></iframe>
8 changes: 4 additions & 4 deletions docs/getting_started/prism.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@
&gt;&lt;/script&gt;
&lt;style type=&quot;text/css&quot;&gt;
#mynetwork {
width: 800px;
height: 600px;
border: 1px solid lightgray;
}
&lt;/style&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;div id=&quot;mynetwork&quot;&gt;&lt;/div&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
var nodes = new vis.DataSet([{ id: 0, label: `nextnand,init
€ : 0.0
☆ 113/152`, group: &quot;states&quot; },
Expand Down Expand Up @@ -965,4 +965,4 @@
"
border:none !important;
allowfullscreen webkitallowfullscreen mozallowfullscreen
></iframe>
></iframe>
8 changes: 4 additions & 4 deletions docs/getting_started/study.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@
&gt;&lt;/script&gt;
&lt;style type=&quot;text/css&quot;&gt;
#mynetwork {
width: 800px;
height: 600px;
border: 1px solid lightgray;
}
&lt;/style&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;div id=&quot;mynetwork&quot;&gt;&lt;/div&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
var nodes = new vis.DataSet([{ id: 0, label: `init`, group: &quot;states&quot;, x: -15, y: -210 },
{ id: 1, label: `studied`, group: &quot;states&quot;, x: -83, y: -4 },
{ id: 2, label: `didn&#x27;t study`, group: &quot;states&quot;, x: 72, y: -22 },
Expand Down Expand Up @@ -244,4 +244,4 @@
"
border:none !important;
allowfullscreen webkitallowfullscreen mozallowfullscreen
></iframe>
></iframe>
42 changes: 21 additions & 21 deletions stormvogel/layout_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,36 +49,36 @@ def __warn_failed_positions_save(self):
If you cannot get the server to work, set stormvogel.communication_server.enable_server to false and re-run.
This will speed up stormvogel and ignore this message, but it means that you cannot store positions in layout files.
Please contact the stormvogel developpers if you keep running into issues.""")

def set_current_vis_node_positions_in_layout(self):
"""Try to save the positions of the nodes in the graph to the layout.
The user is informed if this fails."""
with self.debug_output:
logging.debug(f"Status of vis {self.vis}")
if self.vis is not None:
with self.output:
if stormvogel.communication_server.server is None:
with self.output:
if stormvogel.communication_server.server is None:
with self.debug_output:
logging.info(
"Node positions won't be saved because the server is disabled."
)
with self.output:
print(
"Node positions won't be saved because the server is disabled."
)
else:
try:
positions = self.vis.get_positions()
with self.debug_output:
logging.info(
"Node positions won't be saved because the server is disabled."
logging.debug(positions)
self.layout.layout["positions"] = positions
except TimeoutError:
with self.debug_output:
logging.warning(
"Failed to save node positions in layout file."
)
with self.output:
print(
"Node positions won't be saved because the server is disabled."
)
else:
try:
positions = self.vis.get_positions()
with self.debug_output:
logging.debug(positions)
self.layout.layout["positions"] = positions
except TimeoutError:
with self.debug_output:
logging.warning(
"Failed to save node positions in layout file."
)
with self.output:
self.__warn_failed_positions_save()
self.__warn_failed_positions_save()

def process_save_button(self):
if self.layout.layout["saving"]["save_button"]:
Expand Down
11 changes: 5 additions & 6 deletions stormvogel/show.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,10 @@ def show(
"""
if layout is None:
layout = stormvogel.layout.DEFAULT()
do_init_server = ( # We only need to start the server if we want to have the layout editor.
show_editor
and stormvogel.communication_server.enable_server
do_init_server = ( # We only need to start the server if we want to have the layout editor.
show_editor and stormvogel.communication_server.enable_server
)
#do_display = not show_editor
# do_display = not show_editor
vis = stormvogel.visualization.Visualization(
model=model,
name=name,
Expand All @@ -52,14 +51,14 @@ def show(
do_init_server=do_init_server,
)
vis.show()
if show_editor:
if show_editor:
e = stormvogel.layout_editor.LayoutEditor(
layout, vis, do_display=False, debug_output=debug_output
)
e.show()
box = widgets.HBox(children=[vis.output, e.output])
ipd.display(box)
else: # Unfortunately, the sphinx docs only work if we save the html as a file and embed.
else: # Unfortunately, the sphinx docs only work if we save the html as a file and embed.
iframe = vis.nt.generate_iframe()
with open(name + ".html", "w") as f:
f.write(iframe)
Expand Down
12 changes: 4 additions & 8 deletions stormvogel/visjs.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Our own Python bindings to the vis.js library in JavaScript."""

from typing import Tuple
import IPython.display as ipd
import ipywidgets as widgets
import html
Expand All @@ -12,9 +11,8 @@
import string
import logging


spam: widgets.Output = widgets.Output()
from collections import namedtuple
Node = namedtuple("Node", "id label group")


class Network(stormvogel.displayable.Displayable):
Expand All @@ -29,7 +27,7 @@ def __init__(
do_display: bool = True,
debug_output: widgets.Output = widgets.Output(),
do_init_server: bool = True,
positions: dict[str, dict[str, int]] | None = None
positions: dict[str, dict[str, int]] | None = None,
) -> None:
"""Display a visjs network using IPython. The network can display by itself or you can specify an Output widget in which it should be displayed.
Expand All @@ -55,7 +53,7 @@ def __init__(
self.server: stormvogel.communication_server.CommunicationServer = (
stormvogel.communication_server.initialize_server()
)
self.positions: dict[str, dict[str, int]]
self.positions: dict[str, dict[str, int]]
if positions is None:
self.positions = {}
else:
Expand Down Expand Up @@ -116,9 +114,7 @@ def add_node(
if group is not None:
current += f', group: "{group}"'
if self.positions is not None and str(id) in self.positions:
current += (
f', x: {self.positions[str(id)]["x"]}, y: {self.positions[str(id)]["y"]}'
)
current += f', x: {self.positions[str(id)]["x"]}, y: {self.positions[str(id)]["y"]}'
if self.new_nodes_hidden and id != self.initial_node_id:
current += ", hidden: true"
current += " },\n"
Expand Down
2 changes: 1 addition & 1 deletion stormvogel/visualization.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def __create_nt(self) -> None:
debug_output=self.debug_output,
do_display=False,
do_init_server=self.do_init_server,
positions= self.layout.layout["positions"]
positions=self.layout.layout["positions"],
)

def show(self) -> None:
Expand Down
2 changes: 1 addition & 1 deletion tests/saved_test_layout.json
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,4 @@
"init": {
"color": "TEST_COLOR"
}
}
}
3 changes: 1 addition & 2 deletions tests/test_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ def test_stormpy_to_stormvogel_and_back_mdp():

assert sparse_equal(stormpy_mdp, new_stormpy_mdp)


def test_stormvogel_to_stormpy_and_back_mdp():
# we test it for monty hall mdp
stormvogel_mdp = examples.monty_hall.create_monty_hall_mdp()
Expand Down Expand Up @@ -230,7 +231,6 @@ def test_stormpy_to_stormvogel_and_back_pomdp():
assert sparse_equal(stormpy_pomdp, new_stormpy_pomdp)



def test_stormvogel_to_stormpy_and_back_ma():
# we create a stormpy representation of an example ma
stormvogel_ma = examples.simple_ma.create_simple_ma()
Expand All @@ -254,4 +254,3 @@ def test_stormpy_to_stormvogel_and_back_ma():
# print(new_stormpy_ma)

assert sparse_equal(stormpy_ma, new_stormpy_ma)

1 change: 1 addition & 0 deletions tests/test_simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ def scheduler(state: stormvogel.model.State) -> stormvogel.model.Action:

assert partial_model == other_mdp


# TODO Pim could you also finish this test? :)
# def test_simulate_path():
# # we make the nuclear fusion ctmc and run simulate path with it
Expand Down
27 changes: 8 additions & 19 deletions tests/test_visualization.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,15 @@ def test_show(mocker):
debug_output=vis.debug_output,
do_display=False,
do_init_server=vis.do_init_server,
positions= vis.layout.layout["positions"]
positions=vis.layout.layout["positions"],
)
MockNetwork.add_node.assert_any_call(
0, label="init", group="states"
) # type: ignore
MockNetwork.add_node.assert_any_call(
1, label="one", group="states"
) # type: ignore
MockNetwork.add_node.assert_any_call(0, label="init", group="states") # type: ignore
MockNetwork.add_node.assert_any_call(1, label="one", group="states") # type: ignore
assert MockNetwork.add_node.call_count == 2
MockNetwork.add_edge.assert_any_call(0, 1, label="1")
assert MockNetwork.add_edge.call_count == 1


def test_rewards(mocker):
MockNetwork = boilerplate(mocker)
model, one, init = simple_model()
Expand All @@ -61,9 +58,7 @@ def test_rewards(mocker):
model.get_rewards("HIHI").set_state_reward(one, 42)
vis = Visualization(model=model)
vis.show()
MockNetwork.add_node.assert_any_call(
0, label="init", group="states"
) # type: ignore
MockNetwork.add_node.assert_any_call(0, label="init", group="states") # type: ignore
MockNetwork.add_node.assert_any_call(
1, label="one\n\tLOL: 37\tHIHI: 42", group="states"
) # type: ignore
Expand All @@ -80,12 +75,8 @@ def test_results_count(mocker):
vis = Visualization(model=model, result=result)
vis.show()
RES_SYM = vis.layout.layout["state_properties"]["result_symbol"]
MockNetwork.add_node.assert_any_call(
0, label=f"init\n{RES_SYM} 69", group="states"
) # type: ignore
MockNetwork.add_node.assert_any_call(
1, label=f"one\n{RES_SYM} 12", group="states"
) # type: ignore
MockNetwork.add_node.assert_any_call(0, label=f"init\n{RES_SYM} 69", group="states") # type: ignore
MockNetwork.add_node.assert_any_call(1, label=f"one\n{RES_SYM} 12", group="states") # type: ignore

assert result.values == {0: 69, 1: 12}
assert MockNetwork.add_node.call_count == 2
Expand All @@ -105,9 +96,7 @@ def test_results_scheduler(mocker):
result = Result(model, [1, 2], scheduler)
vis = Visualization(model=model, result=result)
vis.show()
MockNetwork.add_node.assert_any_call(
id=10000000001, label="BAD", group="actions"
)
MockNetwork.add_node.assert_any_call(id=10000000001, label="BAD", group="actions")
MockNetwork.add_node.assert_any_call(
id=10000000000, label="GOOD", group="scheduled_actions"
)
Expand Down

0 comments on commit aebe127

Please sign in to comment.