-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mqtt fixes #222
Merged
Merged
Mqtt fixes #222
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9bb502f
fixes for MQTT
maurerle 6836ff4
use same configuration for agent and manager
maurerle 8145ec7
Merge branch 'main' into mqtt_fixes
nick-harder 872c1bd
fix using distributed clock manager
maurerle 2fc1497
move distributed simulation into subfolder
maurerle 7482680
fix unset reward
maurerle File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we please stick to one format for strings? In the whole code we are using f"{}" format. it would be confusing to have it different in some places.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had this view too for quite a while.
But unfortunately, formatting with f-strings is evaluated every time - even if the logger is set to warning (so the price is formatted even if the line is not printed).
Using it with the % notation does only execute the formatting when loglevel is set to debug.
But I would not like to switch to the %s notation on all other places.. 🤷
So I think we can't really do anything but to use the %s format in logger situations and format strings everywhere else
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm, good to know, let's keep it this way