Skip to content

Commit

Permalink
Small bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
YouGuessedMyName committed Sep 10, 2024
1 parent 4adeaf9 commit c53f5f9
Show file tree
Hide file tree
Showing 4 changed files with 145 additions and 51 deletions.
35 changes: 1 addition & 34 deletions notebooks/layouts/NAME.json
Original file line number Diff line number Diff line change
Expand Up @@ -123,39 +123,6 @@
"save_button": false,
"load_button": false
},
"positions": {
"0": {
"x": 5,
"y": -186
},
"1": {
"x": 98,
"y": 11
},
"2": {
"x": -120,
"y": -7
},
"3": {
"x": 0,
"y": 99
},
"4": {
"x": -24,
"y": 37
},
"5": {
"x": -62,
"y": 182
},
"10000000000": {
"x": 119,
"y": -118
},
"10000000001": {
"x": -122,
"y": -141
}
},
"positions": {},
"physics": true
}
128 changes: 128 additions & 0 deletions notebooks/layouts/nopos.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
{
"__fake_macros": {
"__group_macro": {
"borderWidth": 1,
"color": {
"background": "white",
"border": "black",
"highlight": {
"background": "white",
"border": "red"
}
},
"shape": "ellipse",
"mass": 1,
"font": {
"color": "black",
"size": 14
}
}
},
"groups": {
"states": {
"borderWidth": 1,
"color": {
"background": "white",
"border": "black",
"highlight": {
"background": "white",
"border": "red"
}
},
"shape": "ellipse",
"mass": 1,
"font": {
"color": "black",
"size": 14
}
},
"actions": {
"borderWidth": 1,
"color": {
"background": "lightblue",
"border": "black",
"highlight": {
"background": "white",
"border": "red"
}
},
"shape": "box",
"mass": 1,
"font": {
"color": "black",
"size": 14
}
},
"scheduled_actions": {
"borderWidth": 1,
"color": {
"background": "pink",
"border": "black",
"highlight": {
"background": "white",
"border": "red"
}
},
"shape": "box",
"mass": 1,
"font": {
"color": "black",
"size": 14
},
"schedColor": false
},
"init": {
"borderWidth": 1,
"color": {
"background": "white",
"border": "black",
"highlight": {
"background": "white",
"border": "red"
}
},
"shape": "ellipse",
"mass": 1,
"font": {
"color": "black",
"size": 14
}
}
},
"reload_button": false,
"edges": {
"arrows": "to",
"font": {
"color": "black",
"size": 14
},
"color": {
"color": "black"
}
},
"numbers": {
"fractions": true,
"digits": 5
},
"results_and_rewards": {
"show_results": true,
"resultSymbol": "\u2606",
"show_rewards": true
},
"layout": {
"randomSeed": 5
},
"misc": {
"enable_physics": true,
"width": 800,
"height": 600
},
"saving": {
"relative_path": true,
"filename": "layouts/nopos.json",
"save_button": false,
"load_button": false
},
"positions": {},
"physics": true
}
19 changes: 5 additions & 14 deletions notebooks/study.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "76fc59c81581498a9b74311efed3d67c",
"model_id": "ef13107015784678ba65ec0488f6e259",
"version_major": 2,
"version_minor": 0
},
Expand Down Expand Up @@ -40,22 +40,10 @@
"scrolled": true
},
"outputs": [
{
"data": {
"text/html": [
"<script>fetch('http://127.0.0.1:8080/xfnitbFGTv/MESSAGE/' + 'test message')</script>"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "65e74a3230dd4898bb4eefabff2048bc",
"model_id": "5ae1bd6903c7480a91050c3fd18dd531",
"version_major": 2,
"version_minor": 0
},
Expand All @@ -73,6 +61,9 @@
"from stormvogel.result import Result\n",
"from IPython.display import clear_output\n",
"from stormvogel.show import show\n",
"import stormvogel\n",
"\n",
"stormvogel.communication_server.enable_server = False\n",
"\n",
"mdp = stormvogel.model.new_mdp(\"Monty Hall\")\n",
"\n",
Expand Down
14 changes: 11 additions & 3 deletions stormvogel/communication_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

server_warning: bool = True
request_warning: bool = True
enable_server: bool = True
"""Disable if you don't want to use an internal communication server. Some features might break."""

localhost_address: str = "127.0.0.1"

Expand Down Expand Up @@ -47,7 +49,6 @@ def __init__(self, server_port: int = 8080) -> None:
server_port (int, optional): Defaults to 8080.
"""
self.server_port: int = server_port
global server_running

class InnerServer(http.server.BaseHTTPRequestHandler):
def do_GET(self):
Expand Down Expand Up @@ -100,6 +101,9 @@ def request(self, js: str):
Also waits for server to boot up if it is not finished yet.
Should be thread safe. (I hope).
WHEN SENDING JAVASCRIPT, DO NOT FORGET EXTRA QUOTES AROUND STRINGS."""
if not enable_server:
raise TimeoutError("There is no server running.")

global awaiting, server_running
while not server_running: # Wait for server to start.
sleep(0.2)
Expand Down Expand Up @@ -158,6 +162,8 @@ def initialize_server() -> CommunicationServer | None:
Use the port stored in global variable server_port.
"""
global server, server_port, server_running
if not enable_server:
return None
try:
if server is None:
server = CommunicationServer(server_port=server_port)
Expand All @@ -171,7 +177,8 @@ def initialize_server() -> CommunicationServer | None:
Stormvogel is still usable without this, but a few visualization features might not be available. Set stormvogel.communication_server.request_warning to False to ignore this message.
1) Is the port {localhost_address}:{server_port} (from the machine where jupyterlab runs) available?
If you are working remotely, it might help to forward this port. For example: 'ssh -N -L {server_port}:{localhost_address}{server_port} YOUR_SSH_CONFIG_NAME'.
2) You might also want to consider changing stormvogel.communications_server.localhost_address to the IPv6 loopback address if you are using IPv6.
2) You might also want to consider changing stormvogel.communication_server.localhost_address to the IPv6 loopback address if you are using IPv6.
If you cannot get the server to work, set stormvogel.communication_server.enable_server to false and re-run. This will speed up stormvogel.
Please contact the stormvogel developpers if you keep running into issues.""")
return server
except OSError:
Expand All @@ -183,5 +190,6 @@ def initialize_server() -> CommunicationServer | None:
1) If you already had a stormvogel notebook with a Network or Visualization or show.show in it in this lab session, change the kernel of the current notebook to be the SAME KERNEL (Top right, use kernel for preferred session and look for the name of the PREVIOUS notebook).
You can also simply restart all kernels but it might break again.
2) Port {server_port} might already be used by another process. Try changing stormvogel.communication_server.server_port and running again.
3) You might also want to consider changing stormvogel.communications_server.localhost_address to the IPv6 loopback address if you are using IPv6.
3) You might also want to consider changing stormvogel.communication_server.localhost_address to the IPv6 loopback address if you are using IPv6.
If you cannot get the server to work, set stormvogel.communication_server.enable_server to false and re-run. This will speed up stormvogel.
Please contact the stormvogel developpers if you keep running into issues.""")

0 comments on commit c53f5f9

Please sign in to comment.