Skip to content
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

use python random instead numpy #1526

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/gsy_e/models/area/event_dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from gsy_framework.constants_limits import ConstSettings
from gsy_framework.enums import AvailableMarketTypes
from gsy_framework.enums import SpotMarketTypeEnum
from numpy.random import random
import random
from pendulum import DateTime

from gsy_e.events.event_structures import MarketEvent, AreaEvent
Expand Down Expand Up @@ -140,7 +140,7 @@ def _broadcast_notification_to_area_and_child_agents(
if not self.area.events.is_connected:
return

for child in sorted(self.area.children, key=lambda _: random()):
for child in sorted(self.area.children, random.sample(self.children, len(self.children)):
if not child.children:
continue
self._broadcast_notification_to_single_agent(
Expand Down Expand Up @@ -175,7 +175,7 @@ def broadcast_notification(
return

# Broadcast to children in random order to ensure fairness
for child in sorted(self.area.children, key=lambda _: random()):
for child in sorted(self.area.children, random.sample(self.children, len(self.children)):
child.dispatcher.event_listener(event_type, **kwargs)

# TODO: Enable the following block once GSYE-340 is implemented
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def publish_area_event(self, area_uuid, event_type: AreaEvent, **kwargs):
self.redis.publish(dispatch_chanel, json.dumps(send_data))

def broadcast_event_redis(self, event_type: AreaEvent, **kwargs):
for child in sorted(self.area.children, key=lambda _: random()):
for child in sorted(self.area.children, random.sample(self.children, len(self.children)):
self.publish_area_event(child.uuid, event_type, **kwargs)
self.redis.wait()
self.root_dispatcher.market_event_dispatcher.wait_for_futures()
Expand All @@ -44,7 +44,7 @@ def broadcast_event_redis(self, event_type: AreaEvent, **kwargs):

if not self.area.events.is_connected:
break
for area_name in sorted(agents, key=lambda _: random()):
for area_name in sorted(agents, random.sample(self.children, len(self.children)):
agents[area_name].event_listener(event_type, **kwargs)
self.root_dispatcher.market_notify_event_dispatcher.wait_for_futures()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def publish_event(self, area_uuid, event_type: MarketEvent, **kwargs):
self.redis.publish(dispatch_channel, json.dumps(send_data))

def broadcast_event_redis(self, event_type: MarketEvent, **kwargs):
for child in sorted(self.area.children, key=lambda _: random()):
for child in sorted(self.area.children, random.sample(self.children, len(self.children)):
self.publish_event(child.uuid, event_type, **kwargs)
self.child_response_events[event_type.value].wait()
self.child_response_events[event_type.value].clear()
Expand All @@ -76,7 +76,7 @@ def broadcast_event_redis(self, event_type: MarketEvent, **kwargs):

if not self.area.events.is_connected:
break
for area_name in sorted(agents, key=lambda _: random()):
for area_name in sorted(agents, random.sample(self.children, len(self.children)):
agents[area_name].event_listener(event_type, **kwargs)

def publish_response(self, event_type):
Expand Down
2 changes: 1 addition & 1 deletion src/gsy_e/models/market/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from gsy_framework.constants_limits import ConstSettings, GlobalConfig
from gsy_framework.data_classes import Offer, Trade, Bid
from gsy_framework.enums import SpotMarketTypeEnum
from numpy.random import random
import random
from pendulum import DateTime, duration

from gsy_e.constants import FLOATING_POINT_TOLERANCE, DATE_TIME_FORMAT
Expand Down
2 changes: 1 addition & 1 deletion src/gsy_e/models/strategy/load_hours.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
limit_float_precision, find_object_of_same_weekday_and_time,
is_time_slot_in_simulation_duration)
from gsy_framework.validators.load_validator import LoadValidator
from numpy import random
import random
from pendulum import duration

from gsy_e import constants
Expand Down
6 changes: 3 additions & 3 deletions src/gsy_e/models/strategy/market_agents/balancing_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"""
from gsy_framework.constants_limits import ConstSettings
from gsy_framework.data_classes import TraderDetails
from numpy.random import random
import random

from gsy_e.constants import FLOATING_POINT_TOLERANCE
from gsy_e.models.strategy.market_agents.one_sided_agent import OneSidedAgent
Expand Down Expand Up @@ -123,12 +123,12 @@ def _balancing_trade(self, offer, target_energy):
return trade

def event_balancing_trade(self, *, market_id, trade, offer=None):
for engine in sorted(self.engines, key=lambda _: random()):
for engine in random.sample(self.engines, len(self.engines)):
engine.event_offer_traded(trade=trade)

def event_balancing_offer_split(self, *, market_id, original_offer, accepted_offer,
residual_offer):
for engine in sorted(self.engines, key=lambda _: random()):
for engine in random.sample(self.engines, len(self.engines)):
engine.event_offer_split(market_id=market_id,
original_offer=original_offer,
accepted_offer=accepted_offer,
Expand Down
4 changes: 2 additions & 2 deletions src/gsy_e/models/strategy/market_agents/market_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from typing import Optional, TYPE_CHECKING

from gsy_framework.constants_limits import ConstSettings
from numpy.random import random
import random

from gsy_e.constants import TIME_FORMAT
from gsy_e.models.strategy import BaseStrategy, _TradeLookerUpper
Expand Down Expand Up @@ -74,7 +74,7 @@ def area_reconfigure_event(self, *args, **kwargs):
min_offer_age = kwargs["min_offer_age"]
self._validate_constructor_arguments(min_offer_age)
self.min_offer_age = min_offer_age
for engine in sorted(self.engines, key=lambda _: random()):
for engine in random.sample(self.engines, len(self.engines)):
engine.min_offer_age = min_offer_age

@property
Expand Down
10 changes: 5 additions & 5 deletions src/gsy_e/models/strategy/market_agents/one_sided_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"""
from typing import Optional, TYPE_CHECKING

from numpy.random import random
import random

from gsy_e.models.market import MarketBase
from gsy_e.models.strategy.market_agents.market_agent import MarketAgent
Expand Down Expand Up @@ -57,7 +57,7 @@ def get_market_from_market_id(self, market_id: str) -> Optional[MarketBase]:

def event_tick(self):
area = self.owner
for engine in sorted(self.engines, key=lambda _: random()):
for engine in random.sample(self.engines, len(self.engines)):
engine.tick(area=area)

# pylint: disable=unused-argument
Expand All @@ -67,17 +67,17 @@ def event_offer(self, *, market_id: str, offer: "Offer"):

# pylint: disable=unused-argument
def event_offer_traded(self, *, market_id: str, trade: "Trade"):
for engine in sorted(self.engines, key=lambda _: random()):
for engine in random.sample(self.engines, len(self.engines)):
engine.event_offer_traded(trade=trade)

# pylint: disable=unused-argument
def event_offer_deleted(self, *, market_id: str, offer: "Offer"):
for engine in sorted(self.engines, key=lambda _: random()):
for engine in random.sample(self.engines, len(self.engines)):
engine.event_offer_deleted(offer=offer)

def event_offer_split(self, *, market_id: str, original_offer: "Offer",
accepted_offer: "Offer", residual_offer: "Offer"):
for engine in sorted(self.engines, key=lambda _: random()):
for engine in random.sample(self.engines, len(self.engines)):
engine.event_offer_split(market_id=market_id,
original_offer=original_offer,
accepted_offer=accepted_offer,
Expand Down
8 changes: 4 additions & 4 deletions src/gsy_e/models/strategy/market_agents/two_sided_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"""
from typing import TYPE_CHECKING
from gsy_framework.constants_limits import ConstSettings
from numpy.random import random
import random

from gsy_e.models.strategy.market_agents.one_sided_agent import OneSidedAgent
from gsy_e.models.strategy.market_agents.two_sided_engine import TwoSidedEngine
Expand Down Expand Up @@ -62,17 +62,17 @@ def event_bid(self, *, market_id: str, bid: "Bid"):

# pylint: disable=unused-argument
def event_bid_traded(self, *, market_id: str, bid_trade: "Trade"):
for engine in sorted(self.engines, key=lambda _: random()):
for engine in random.sample(self.engines, len(self.engines)):
engine.event_bid_traded(bid_trade=bid_trade)

# pylint: disable=unused-argument
def event_bid_deleted(self, *, market_id: str, bid: "Bid"):
for engine in sorted(self.engines, key=lambda _: random()):
for engine in random.sample(self.engines, len(self.engines)):
engine.event_bid_deleted(bid=bid)

def event_bid_split(self, *, market_id: str, original_bid: "Bid",
accepted_bid: "Bid", residual_bid: "Bid"):
for engine in sorted(self.engines, key=lambda _: random()):
for engine in random.sample(self.engines, len(self.engines)):
engine.event_bid_split(market_id=market_id,
original_bid=original_bid,
accepted_bid=accepted_bid,
Expand Down
2 changes: 1 addition & 1 deletion src/gsy_e/models/strategy/smart_meter.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from gsy_framework.read_user_profile import InputProfileTypes, read_arbitrary_profile
from gsy_framework.utils import find_object_of_same_weekday_and_time, limit_float_precision
from gsy_framework.validators.smart_meter_validator import SmartMeterValidator
from numpy import random
import random
from pendulum import duration

from gsy_e import constants
Expand Down
Loading