Skip to content

Commit

Permalink
fix: fixed results of simulations with initial time != 0
Browse files Browse the repository at this point in the history
  • Loading branch information
jonrkarr committed Aug 9, 2021
1 parent bbda8c3 commit 77f7b50
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
3 changes: 3 additions & 0 deletions biosimulators_copasi/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,9 @@ def exec_sed_task(task, variables, log=None):
for i_step in range(number_of_recorded_points):
step_values = copasi_data_handler.getNthRow(i_step)
for variable, value in zip(variables, step_values):
if variable.symbol == Symbol.time.value:
value += sim.initial_time

variable_results[variable.id][i_step] = value

if sim.output_end_time == sim.output_start_time and sim.output_start_time == sim.initial_time:
Expand Down
45 changes: 45 additions & 0 deletions tests/test_core_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,29 +212,74 @@ def test_exec_sed_task_correct_time_course_attrs(self):
task.simulation.output_end_time = 20.
task.simulation.number_of_points = 20
full_variable_results, _ = exec_sed_task(task, variables)
numpy.testing.assert_allclose(
full_variable_results['time'],
numpy.linspace(task.simulation.output_start_time, task.simulation.output_end_time, task.simulation.number_of_points + 1),
rtol=1e-4)

task.simulation.initial_time = 0.
task.simulation.output_start_time = 10.
task.simulation.output_end_time = 20.
task.simulation.number_of_points = 10
second_half_variable_results, _ = exec_sed_task(task, variables)
numpy.testing.assert_allclose(
second_half_variable_results['time'],
numpy.linspace(task.simulation.output_start_time, task.simulation.output_end_time, task.simulation.number_of_points + 1),
rtol=1e-4)
numpy.testing.assert_allclose(second_half_variable_results['A'], full_variable_results['A'][10:], rtol=1e-4)

task.simulation.initial_time = 5.
task.simulation.output_start_time = 5.
task.simulation.output_end_time = 25.
task.simulation.number_of_points = 20
offset_full_variable_results, _ = exec_sed_task(task, variables)
numpy.testing.assert_allclose(
offset_full_variable_results['time'],
numpy.linspace(task.simulation.output_start_time, task.simulation.output_end_time, task.simulation.number_of_points + 1),
rtol=1e-4)
numpy.testing.assert_allclose(offset_full_variable_results['A'], full_variable_results['A'], rtol=1e-4)

task.simulation.initial_time = 5.
task.simulation.output_start_time = 15.
task.simulation.output_end_time = 25.
task.simulation.number_of_points = 10
offset_second_half_variable_results, _ = exec_sed_task(task, variables)
numpy.testing.assert_allclose(
offset_second_half_variable_results['time'],
numpy.linspace(task.simulation.output_start_time, task.simulation.output_end_time, task.simulation.number_of_points + 1),
rtol=1e-4)
numpy.testing.assert_allclose(offset_second_half_variable_results['A'], offset_full_variable_results['A'][10:], rtol=1e-4)
numpy.testing.assert_allclose(offset_second_half_variable_results['A'], second_half_variable_results['A'], rtol=1e-4)

def test_exec_sed_task_correct_time_course_attrs_2(self):
# test that initial time, output start time, output end time, number of points are correctly interpreted
task = sedml_data_model.Task(
model=sedml_data_model.Model(
source=os.path.join('tests', 'fixtures', 'model.xml'),
language=sedml_data_model.ModelLanguage.SBML.value,
),
simulation=sedml_data_model.UniformTimeCourseSimulation(
algorithm=sedml_data_model.Algorithm(
kisao_id='KISAO_0000560',
),
initial_time=0.4,
output_start_time=0.4,
output_end_time=0.8,
number_of_points=5,
),
)

variables = [
sedml_data_model.Variable(
id='time',
symbol=sedml_data_model.Symbol.time,
task=task),
]

results, _ = exec_sed_task(task, variables)

numpy.testing.assert_allclose(results['time'], numpy.linspace(0.4, 0.8, 5 + 1))

def test_hybrid_rk45_partitioning(self):
task = sedml_data_model.Task(
model=sedml_data_model.Model(
Expand Down

0 comments on commit 77f7b50

Please sign in to comment.