diff --git a/notebooks/layouts/NAME.json b/notebooks/layouts/NAME.json index bf50348..ca9c089 100644 --- a/notebooks/layouts/NAME.json +++ b/notebooks/layouts/NAME.json @@ -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 } diff --git a/notebooks/layouts/nopos.json b/notebooks/layouts/nopos.json new file mode 100644 index 0000000..1a615bf --- /dev/null +++ b/notebooks/layouts/nopos.json @@ -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 +} diff --git a/notebooks/study.ipynb b/notebooks/study.ipynb index 1858e59..b4190ba 100644 --- a/notebooks/study.ipynb +++ b/notebooks/study.ipynb @@ -9,7 +9,7 @@ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "76fc59c81581498a9b74311efed3d67c", + "model_id": "ef13107015784678ba65ec0488f6e259", "version_major": 2, "version_minor": 0 }, @@ -40,22 +40,10 @@ "scrolled": true }, "outputs": [ - { - "data": { - "text/html": [ - "" - ], - "text/plain": [ - "" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "65e74a3230dd4898bb4eefabff2048bc", + "model_id": "5ae1bd6903c7480a91050c3fd18dd531", "version_major": 2, "version_minor": 0 }, @@ -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", diff --git a/stormvogel/communication_server.py b/stormvogel/communication_server.py index 44c147a..0a0bd2e 100644 --- a/stormvogel/communication_server.py +++ b/stormvogel/communication_server.py @@ -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" @@ -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): @@ -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) @@ -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) @@ -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: @@ -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.""")