diff --git a/basico/model_info.py b/basico/model_info.py index 8f4d4c4..ba66ba8 100644 --- a/basico/model_info.py +++ b/basico/model_info.py @@ -4901,10 +4901,10 @@ def _set_group_from_dict(group, values, dm=None): try: if param_type == COPASI.CCopasiParameter.Type_STRING: current_value = values[key] - # convert list of strings to comma separated string + # convert list of strings to space separated string # converting other data types to string if isinstance(current_value, list): - current_value = ', '.join(map(str, current_value)) + current_value = ' '.join(map(str, current_value)) else: current_value = str(current_value) param.setStringValue(current_value) @@ -5070,6 +5070,12 @@ def set_task_settings(task, settings, **kwargs): problem.setStepNumber(int(settings['problem']['intervals'])) if 'StepNumber' in settings['problem']: problem.setStepNumber(int(settings['problem']['StepNumber'])) + if 'Values' in settings['problem'] and 'Use Values' in settings['problem'] and settings['problem']['Use Values']: + desired_values = problem.getValueString().split() + first_value = desired_values[0] if desired_values else None + if first_value: + # correct start time if needed + problem.setOutputStartTime(float(first_value)) if 'method' in settings: method = task.getMethod() diff --git a/basico/task_timecourse.py b/basico/task_timecourse.py index 2a88d1b..33d6216 100644 --- a/basico/task_timecourse.py +++ b/basico/task_timecourse.py @@ -414,6 +414,12 @@ def _setup_timecourse(args, kwargs): for val in vals: new_vals += ' ' + str(val) vals = new_vals.strip() + + # ensure that the output start time is correct adjusted: + first_value = vals.split(' ')[0] if vals else None + if first_value: + problem.setOutputStartTime(float(first_value)) + problem.setValues(vals) problem.setUseValues(True) if 'use_values' in kwargs: diff --git a/tests/test_timecourse.py b/tests/test_timecourse.py index eb3d68f..0637a71 100644 --- a/tests/test_timecourse.py +++ b/tests/test_timecourse.py @@ -18,7 +18,9 @@ def test_values(self): tc = basico.run_time_course(values=[10, 20, 30]) tc2 = basico.run_time_course(values=[10, 20, 30], start_time=10) self.assertIsNotNone(tc) - self.assertEqual(tc.shape, (4, 1)) + # we decided that both should have the same shape + # see issue #61 + self.assertEqual(tc.shape, (3, 1)) self.assertEqual(tc2.shape, (3, 1)) @@ -94,9 +96,9 @@ def test_issue_61(self): 16, 16.5, 17, 17.5, 18, 18.5, 19, 19.5, 20] problem = { - "AutomaticStepSize": False, - "Duration": 20.0, - "OutputStartTime": 10.0, + "AutomaticStepSize": True, # should be ignored + "Duration": 200.0, # should be ignored + "OutputStartTime": 100.0, # should be ignored "Use Values": True, "Values": desired_values } @@ -122,6 +124,24 @@ def test_issue_61(self): dm.removeInterface(dh) self.assertListEqual(data['Time'].to_list(), desired_values) self.assertListEqual(df2['Time'].to_list(), desired_values) + + + # run some more tests white different values for duration and output start time + # ensuring that the requested values are still returned + desired_values = [ 0, 10, 15, 20] + df1 = basico.run_time_course_with_output(output_elements, values=desired_values, model=dm) + self.assertListEqual(df1['Time'].to_list(), desired_values) + df2 = basico.run_time_course(**{"use_inital_values": True}).reset_index() + self.assertListEqual(df2['Time'].to_list(), desired_values) + + desired_values = [ 15, 20 ] + df1 = basico.run_time_course_with_output(output_elements, values=desired_values, model=dm) + self.assertListEqual(df1['Time'].to_list(), desired_values) + df2 = basico.run_time_course(**{"use_inital_values": True, "values":desired_values}).reset_index() + self.assertListEqual(df2['Time'].to_list(), desired_values) + + + basico.remove_datamodel(dm)