Skip to content

Commit

Permalink
ControlSignal: Do not recalculate costs on Port._update
Browse files Browse the repository at this point in the history
The function (TransferWithCosts) calculates costs during execution.

Partly closes: PrincetonUniversity#2721

Signed-off-by: Jan Vesely <jan.vesely@rutgers.edu>
  • Loading branch information
jvesely committed Jul 7, 2023
1 parent 8d5573c commit 8773789
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1077,15 +1077,6 @@ def _parse_port_specific_specs(self, owner, port_dict, port_specific_spec):

return port_spec, params_dict

def _update(self, params=None, context=None):
"""Update value (intensity) and costs
"""
super()._update(params=params, context=context)

if self.parameters.cost_options._get(context):
intensity = self.parameters.value._get(context)
self.parameters.cost._set(self.compute_costs(intensity, context), context)

def compute_costs(self, intensity, context=None):
"""Compute costs based on self.value (`intensity <ControlSignal.intensity>`)."""
# FIX 8/30/19: NEED TO DEAL WITH DURATION_COST AS STATEFUL: DON'T WANT TO MESS UP MAIN VALUE
Expand Down
2 changes: 1 addition & 1 deletion tests/composition/test_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -2402,7 +2402,7 @@ def test_add_node_with_controller_spec_and_control_mech_but_not_a_controller(sel
(pnl.CostFunctions.INTENSITY, 3, [0.2817181715409549, -3.3890560989306495, -15.085536923187664, -48.59815003314423, -141.41315910257657]),
(pnl.CostFunctions.ADJUSTMENT, 3, [3, 3, 3, 3, 3] ),
(pnl.CostFunctions.INTENSITY | pnl.CostFunctions.ADJUSTMENT, 3, [0.2817181715409549, -4.389056098930649, -17.085536923187664, -51.59815003314423, -145.41315910257657]),
(pnl.CostFunctions.DURATION, 3, [-17, -20, -23, -26, -29]),
(pnl.CostFunctions.DURATION, 3, [-7, -8, -9, -10, -11]),
# FIXME: combinations with DURATION are broken
# (pnl.CostFunctions.DURATION | pnl.CostFunctions.ADJUSTMENT, ,),
# (pnl.CostFunctions.ALL, ,),
Expand Down

0 comments on commit 8773789

Please sign in to comment.