From c60c6a84445dff4e49bae29a446592e28e12610a Mon Sep 17 00:00:00 2001 From: Nick Harder Date: Fri, 29 Sep 2023 15:50:15 +0200 Subject: [PATCH] several changes for release -switch back to non git mango agents release -as PyPi doesn't allow git dependencies -change to simple port change check -to enable parallel runs --- assume/world.py | 24 +++++++++++------------- pyproject.toml | 4 ++-- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/assume/world.py b/assume/world.py index d4df257e..a5340a33 100644 --- a/assume/world.py +++ b/assume/world.py @@ -1,6 +1,7 @@ import asyncio import calendar import logging +import socket import sys import time from datetime import datetime @@ -38,7 +39,8 @@ class World: def __init__( self, - addr: tuple[str, int] | str = "world", + ifac_addr: str = "0.0.0.0", + port: int = 9099, database_uri: str = "", export_csv_path: str = "", log_level: str = "INFO", @@ -46,7 +48,7 @@ def __init__( ): logging.getLogger("assume").setLevel(log_level) self.logger = logging.getLogger(__name__) - self.addr = addr + self.addr = (ifac_addr, port) self.container = None self.export_csv_path = export_csv_path @@ -124,20 +126,16 @@ async def setup( if isinstance(self.container, Container) and self.container.running: 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" + # check if self.addr is already in use and increase port by one if true + while ( + socket.socket(socket.AF_INET, socket.SOCK_STREAM).connect_ex(self.addr) == 0 + ): + self.addr = (self.addr[0], self.addr[1] + 1) self.container = await create_container( - connection_type=connection_type, - codec=mango_codec_factory(), - addr=self.addr, - clock=self.clock, + addr=self.addr, clock=self.clock, codec=mango_codec_factory() ) + await self.setup_learning() await self.setup_output_agent(simulation_id, save_frequency_hours) diff --git a/pyproject.toml b/pyproject.toml index 90fe68d7..e2dd9d76 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "assume-framework" -version = "0.1.0" +version = "0.1.1" description = "ASSUME - Agent-Based Electricity Markets Simulation Toolbox" authors = ["ASSUME Developers "] license = "LICENSE" @@ -28,7 +28,7 @@ packages = [ [tool.poetry.dependencies] python = "^3.10" paho-mqtt = "^1.5.1" -mango-agents = {git = "https://gitlab.com/maurerle/mango"} +mango-agents = "^1.1.1" tqdm = "^4.64.1" python-dateutil = "^2.8.2" sqlalchemy = "^2.0.9"