-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This includes fixes to running the MQTT container with docker for a distributed simulation. For distributed simulations, one can start `python examples/distributed_world_manager.py` in one terminal and run `python examples/distributed_world_agent.py` in another one. A registry of which agents are available (and must be online before simulation can start) and a central yaml config are still needed. So this is an early fix set, which should not change anything to existing behavior --------- Co-authored-by: Nick Harder <[email protected]>
- Loading branch information
1 parent
606c335
commit e537ad6
Showing
11 changed files
with
191 additions
and
168 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# https://github.com/eclipse/mosquitto/blob/master/mosquitto.conf | ||
listener 1883 | ||
allow_anonymous true | ||
|
||
max_keepalive 3600 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import asyncio | ||
import calendar | ||
import logging | ||
import os | ||
from datetime import datetime, timedelta | ||
|
||
import pandas as pd | ||
from dateutil import rrule as rr | ||
|
||
from assume import World | ||
from assume.common.market_objects import MarketConfig, MarketProduct | ||
|
||
log = logging.getLogger(__name__) | ||
|
||
|
||
db_uri = os.getenv("DB_URI", "postgresql://assume:assume@localhost:5432/assume") | ||
|
||
use_mqtt = False | ||
|
||
if use_mqtt: | ||
manager_addr = "manager" | ||
agent_adress = "agent" | ||
agent_adresses = ["agent"] | ||
market_operator_addr = "manager" | ||
else: | ||
manager_addr = ("0.0.0.0", 9099) | ||
agent_adress = ("0.0.0.0", 9098) | ||
agent_adresses = [("0.0.0.0", 9098)] | ||
market_operator_addr = ("0.0.0.0", 9099) | ||
|
||
market_operator_aid = "market_operator" | ||
broker_addr = os.getenv("MQTT_BROKER", ("0.0.0.0", 1883, 600)) | ||
|
||
start = datetime(2023, 10, 4) | ||
end = datetime(2023, 12, 5) | ||
index = pd.date_range( | ||
start=start, | ||
end=end + timedelta(hours=24), | ||
freq="H", | ||
) | ||
sim_id = "handmade_simulation" | ||
|
||
marketdesign = [ | ||
MarketConfig( | ||
"EOM", | ||
rr.rrule(rr.HOURLY, interval=24, dtstart=start, until=end), | ||
timedelta(hours=1), | ||
"pay_as_clear", | ||
[MarketProduct(timedelta(hours=1), 24, timedelta(hours=1))], | ||
additional_fields=["block_id", "link", "exclusive_id"], | ||
) | ||
] | ||
|
||
|
||
async def worker(world: World, marketdesign: list[MarketConfig], create_worker): | ||
if world.distributed_role: | ||
world.addresses.extend(agent_adresses) | ||
|
||
await world.setup( | ||
start=start, | ||
end=end, | ||
save_frequency_hours=48, | ||
simulation_id=sim_id, | ||
index=index, | ||
manager_address=manager_addr, | ||
broker_addr=broker_addr, | ||
) | ||
|
||
await create_worker(world, marketdesign) | ||
|
||
await asyncio.sleep(0) | ||
|
||
# wait until done if we are a worker agent | ||
if world.distributed_role: | ||
world.logger.info("sleeping 2s") | ||
await asyncio.sleep(2) | ||
world.logger.info("starting simulation") | ||
await world.async_run( | ||
start_ts=calendar.timegm(world.start.utctimetuple()), | ||
end_ts=calendar.timegm(world.end.utctimetuple()), | ||
) | ||
elif world.distributed_role is False: | ||
await world.clock_agent.stopped | ||
await world.container.shutdown() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from config import ( | ||
agent_adress, | ||
db_uri, | ||
index, | ||
market_operator_addr, | ||
market_operator_aid, | ||
marketdesign, | ||
worker, | ||
) | ||
|
||
from assume import MarketConfig, World | ||
from assume.common.forecasts import NaiveForecast | ||
|
||
|
||
async def create_worker(world: World, marketdesign: list[MarketConfig]): | ||
for market_config in marketdesign: | ||
market_config.addr = market_operator_addr | ||
market_config.aid = market_operator_aid | ||
world.markets[f"{market_config.name}"] = market_config | ||
|
||
world.add_unit_operator("my_demand") | ||
world.add_unit( | ||
"demand1", | ||
"demand", | ||
"my_demand", | ||
# the unit_params have no hints | ||
{ | ||
"min_power": 0, | ||
"max_power": 1000, | ||
"bidding_strategies": {"energy": "naive"}, | ||
"technology": "demand", | ||
}, | ||
NaiveForecast(index, demand=100), | ||
) | ||
|
||
|
||
world = World(database_uri=db_uri, addr=agent_adress, distributed_role=False) | ||
world.loop.run_until_complete(worker(world, marketdesign, create_worker)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
from config import ( | ||
agent_adress, | ||
agent_adresses, | ||
db_uri, | ||
index, | ||
manager_addr, | ||
market_operator_addr, | ||
market_operator_aid, | ||
marketdesign, | ||
worker, | ||
) | ||
|
||
from assume import MarketConfig, World | ||
from assume.common.forecasts import NaiveForecast | ||
|
||
|
||
async def create_worker(world: World, marketdesign: list[MarketConfig]): | ||
world.add_market_operator(id=market_operator_aid) | ||
for market_config in marketdesign: | ||
world.add_market(market_operator_aid, market_config) | ||
|
||
world.add_unit_operator("my_operator") | ||
|
||
nuclear_forecast = NaiveForecast(index, availability=1, fuel_price=3, co2_price=0.1) | ||
world.add_unit( | ||
"nuclear1", | ||
"power_plant", | ||
"my_operator", | ||
{ | ||
"min_power": 200, | ||
"max_power": 1000, | ||
"bidding_strategies": {"energy": "naive"}, | ||
"technology": "nuclear", | ||
}, | ||
nuclear_forecast, | ||
) | ||
|
||
|
||
world = World(database_uri=db_uri, addr=manager_addr, distributed_role=True) | ||
world.loop.run_until_complete(worker(world, marketdesign, create_worker)) |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.