Skip to content

Commit

Permalink
Fixed bug with PointEvaluator (no sign argument in constructor).
Browse files Browse the repository at this point in the history
  • Loading branch information
joseph-hellerstein committed Mar 25, 2024
1 parent eed9a92 commit a8e9787
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 38 deletions.
65 changes: 38 additions & 27 deletions examples/Controlling-Glucose-Metabolis-in-Yeast.ipynb

Large diffs are not rendered by default.

14 changes: 11 additions & 3 deletions src/controlSBML/control_sbml.py
Original file line number Diff line number Diff line change
Expand Up @@ -786,9 +786,17 @@ def setValue(val):
input_name=self.input_name,
output_name=self.output_name,
save_path=self.save_path)
designs = designer.design(kP_spec=kP_spec, kI_spec=kI_spec, kF_spec=kF_spec,
num_restart=num_restart, min_value=min_parameter_value, max_value=max_parameter_value,
num_coordinate=num_coordinate, is_greedy=is_greedy, is_report=is_report, num_process=num_process) # type: ignore
designs = designer.design(
kP_spec=kP_spec,
kI_spec=kI_spec,
kF_spec=kF_spec,
num_restart=num_restart,
min_value=min_parameter_value,
max_value=max_parameter_value,
num_coordinate=num_coordinate,
is_greedy=is_greedy,
is_report=is_report,
num_process=num_process) # type: ignore
if designer.residual_mse is None:
msgs.warn("No design found!")
return DesignResult(timeseries=None, antimony_builder=None, designs=designs)
Expand Down
10 changes: 6 additions & 4 deletions src/controlSBML/point_evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@


##################################################################
# FIXME: Need to specify the sign
class PointEvaluator(Evaluator):
# Evaluates a point in the design space
def __init__(self, sbml_system:SBMLSystem, input_name:str, output_name:str, setpoint:float, times:np.array,
is_greedy:bool=False):
def __init__(self, sbml_system:SBMLSystem, input_name:str, output_name:str, setpoint:float,
sign:float, times:np.array, is_greedy:bool=False):
"""
Args:
sbml_system (SBMLSystem): Should be a copy of the original system so it is light weight
Expand All @@ -28,6 +29,7 @@ def __init__(self, sbml_system:SBMLSystem, input_name:str, output_name:str, setp
self.input_name = input_name
self.output_name = output_name
self.setpoint = setpoint
self.sign = sign
self.times = times
self.siso_evaluator = None
self.is_greedy = is_greedy
Expand Down Expand Up @@ -77,9 +79,9 @@ def _calculateMse(self, **parameter_dct:dict)->Tuple[str, object]:
max_output = SIZE_MARGIN*self.sbml_system._max_value_dct[self.output_name]
min_output = self.sbml_system._min_value_dct[self.output_name]/SIZE_MARGIN
try:
response_ts, _ = self.sbml_system.simulateSISOClosedLoop(setpoint=self.setpoint,
response_ts, builder = self.sbml_system.simulateSISOClosedLoop(setpoint=self.setpoint,
input_name=self.input_name, output_name=self.output_name,
times=self.times,
times=self.times, sign=self.sign,
is_steady_state=self.sbml_system.is_steady_state, inplace=False,
**parameter_dct) # type: ignore
except Exception as error:
Expand Down
6 changes: 2 additions & 4 deletions src/controlSBML/siso_closed_loop_designer.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,16 +296,14 @@ def getValue(val):
else:
return float(val)
#
point_evaluator = PointEvaluator(self.system.copy(), self.input_name, self.output_name,
self.setpoint, self.times, is_greedy=is_greedy)
point_evaluator = PointEvaluator(self.system.copy(), self.input_name, self.output_name,
self.setpoint, self.sign, self.times, is_greedy=is_greedy)
parallel_search = ParallelSearch(point_evaluator, grid.points, num_process=num_process, is_report=is_report) # type: ignore
search_results = []
for _ in range(num_restart):
parallel_search.search()
search_results.append(parallel_search.getSearchResults())
if len(search_results) == 0:
# Why no results?
import pdb; pdb.set_trace()
df = pd.DataFrame([[None, None, None, None, cn.DESIGN_RESULT_CANNOT_SIMULATE]],
columns=[CP_kP, CP_kI, CP_kF, cn.SCORE, cn.REASON])
return DesignResult(dataframe=df)
Expand Down
3 changes: 3 additions & 0 deletions tests/test_control_sbml.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,9 @@ def testBug10(self):
INPUT_NAME = "Mlc"
OUTPUT_NAME = "EI_P"
CTLSB.setSystem(input_name=INPUT_NAME, output_name=OUTPUT_NAME)
result = CTLSB.plotDesign(setpoint=0.0000003, kP_spec=1, kI_spec=1, times=TIMES, num_restart=1, sign=1,
is_plot=IS_PLOT)
self.assertEqual(result.designs.dataframe.loc[0, cn.REASON], cn.DESIGN_RESULT_CANNOT_SIMULATE)
result = CTLSB.plotDesign(setpoint=0.0000003, kP_spec=0.1, times=TIMES, num_restart=1, sign=1,
is_plot=IS_PLOT)
self.assertEqual(result.designs.dataframe.loc[0, cn.REASON], cn.DESIGN_RESULT_CANNOT_SIMULATE)
Expand Down

0 comments on commit a8e9787

Please sign in to comment.