Skip to content
Merged
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
2 changes: 1 addition & 1 deletion src/pymgrid/microgrid/microgrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ def run(self, control, normalized=True):
for module in modules:
if not module.is_sink:
sink_amt = 0.0
elif module.max_consumption < energy_excess: # module cannot dissipate all excess energy
elif module.max_consumption < energy_excess: # module cannot dissipate all excess energy
sink_amt = -1.0*module.max_consumption
else:
sink_amt = -1.0 * energy_excess
Expand Down
10 changes: 4 additions & 6 deletions src/pymgrid/modules/renewable_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class RenewableModule(BaseTimeSeriesMicrogridModule):
If False, actions are clipped to the limit possible.

"""
module_type = ('renewable', 'fixed')
module_type = ('renewable', 'flex')
yaml_tag = u"!RenewableModule"
yaml_loader = yaml.SafeLoader
yaml_dumper = yaml.SafeDumper
Expand Down Expand Up @@ -85,14 +85,12 @@ def __init__(self,

self.name = ('renewable', None)

def _get_bounds(self):
_min_obs, _max_obs, _, _ = super()._get_bounds()
return _min_obs, _max_obs, np.array([]), np.array([])

def update(self, external_energy_change, as_source=False, as_sink=False):
assert as_source, f'Class {self.__class__.__name__} can only be used as a source.'
assert external_energy_change <= self.current_renewable, f'Cannot provide more than {self.current_renewable}'

info = {'provided_energy': self.current_renewable}
info = {'provided_energy': external_energy_change,
'curtailment': self.current_renewable-external_energy_change}

return 0.0, self._done(), info

Expand Down
13 changes: 7 additions & 6 deletions tests/microgrid/test_microgrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,8 +352,10 @@ def test_sample_action(self):

def test_sample_action_with_flex(self):
sampled_action = self.microgrid.sample_action(sample_flex_modules=True)
self.assertEqual(len(sampled_action), 1)
self.assertEqual(len(sampled_action), 2)
self.assertIn('renewable', sampled_action)
self.assertIn('balancing', sampled_action)
self.assertEqual(len(sampled_action['renewable']), self.n_pvs)

def test_state_dict(self):
sd = self.microgrid.state_dict()
Expand Down Expand Up @@ -390,18 +392,16 @@ def check_step(self, microgrid, step_number=0):

obs, reward, done, info = microgrid.run(control)
loss_load = self.load_ts[step_number]-self.pv_ts[step_number]
overgeneration = -1 * loss_load

loss_load_cost = self.microgrid.modules.balancing[0].loss_load_cost * max(loss_load, 0)
overgeneration_cost = self.microgrid.modules.balancing[0].overgeneration_cost * max(overgeneration, 0)

self.assertEqual(loss_load_cost + overgeneration_cost, -1*reward)
self.assertEqual(loss_load_cost, -1*reward)

self.assertEqual(len(microgrid.log), step_number + 1)
self.assertTrue(all(module in microgrid.log for module in microgrid.modules.names()))

load_met = min(self.load_ts[step_number], self.pv_ts[step_number])
loss_load = max(self.load_ts[step_number] - load_met, 0)
pv_curtailment = max(self.pv_ts[step_number]-load_met, 0)

# Checking the log populated correctly.

Expand All @@ -419,13 +419,14 @@ def check_step(self, microgrid, step_number=0):

self.assertEqual(log_entry('renewable', 'renewable_current'), self.pv_ts[step_number])
self.assertEqual(log_entry('renewable', 'renewable_used'), load_met)
self.assertEqual(log_entry('renewable', 'curtailment'), pv_curtailment)

self.assertEqual(log_entry('balancing', 'loss_load'), loss_load)

self.assertEqual(log_entry('balance', 'reward'), -1 * loss_load_cost)
self.assertEqual(log_entry('balance', 'overall_provided_to_microgrid'), self.load_ts[step_number])
self.assertEqual(log_entry('balance', 'overall_absorbed_from_microgrid'), self.load_ts[step_number])
self.assertEqual(log_entry('balance', 'fixed_provided_to_microgrid'), self.pv_ts[step_number])
self.assertEqual(log_entry('balance', 'fixed_provided_to_microgrid'), 0.0)
self.assertEqual(log_entry('balance', 'fixed_absorbed_from_microgrid'), self.load_ts[step_number])
self.assertEqual(log_entry('balance', 'controllable_absorbed_from_microgrid'), 0.0)
self.assertEqual(log_entry('balance', 'controllable_provided_to_microgrid'), 0.0)
Expand Down