From 5d9234da47fba3df3213be5356469404966179a1 Mon Sep 17 00:00:00 2001 From: Florian Maurer Date: Mon, 25 Sep 2023 16:23:40 +0200 Subject: [PATCH] allow running simulation without port assignment (#203) This fixes #202 by using the external_connection Container, which does not require a port. run pip install -e . to get the correct version of mango --- assume/world.py | 17 +++++++++++++---- pyproject.toml | 2 +- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/assume/world.py b/assume/world.py index 116d5822..a4ae873f 100644 --- a/assume/world.py +++ b/assume/world.py @@ -39,8 +39,7 @@ class World: def __init__( self, - ifac_addr: str = "0.0.0.0", - port: int = 9099, + addr: tuple[str, int] | str = "world", database_uri: str = "", export_csv_path: str = "", log_level: str = "INFO", @@ -48,7 +47,7 @@ def __init__( ): logging.getLogger("assume").setLevel(log_level) self.logger = logging.getLogger(__name__) - self.addr = (ifac_addr, port) + self.addr = addr self.container = None self.export_csv_path = export_csv_path @@ -127,8 +126,18 @@ async def setup( await self.container.shutdown() # create new container + if self.addr == "world": + connection_type = "external_connection" + elif isinstance(self.addr, tuple): + connection_type = "tcp" + else: + connection_type = "mqtt" + self.container = await create_container( - addr=self.addr, clock=self.clock, codec=mango_codec_factory() + connection_type=connection_type, + codec=mango_codec_factory(), + addr=self.addr, + clock=self.clock, ) await self.setup_learning() await self.setup_output_agent(simulation_id, save_frequency_hours) diff --git a/pyproject.toml b/pyproject.toml index 6ac69088..90fe68d7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -28,7 +28,7 @@ packages = [ [tool.poetry.dependencies] python = "^3.10" paho-mqtt = "^1.5.1" -mango-agents = "^1.1.1" +mango-agents = {git = "https://gitlab.com/maurerle/mango"} tqdm = "^4.64.1" python-dateutil = "^2.8.2" sqlalchemy = "^2.0.9"