Skip to content

Commit

Permalink
Merge pull request #13 from biosimulators/implement-set-get-reset
Browse files Browse the repository at this point in the history
Tie into 'implement-set-get-reset' branch of biosimulators_utils
  • Loading branch information
luciansmith committed Jul 24, 2023
2 parents fa9f2b8 + 31fb8e7 commit 84baede
Show file tree
Hide file tree
Showing 9 changed files with 290 additions and 149 deletions.
2 changes: 1 addition & 1 deletion biosimulators_tellurium/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.1.33'
__version__ = '0.1.34'
340 changes: 212 additions & 128 deletions biosimulators_tellurium/core.py

Large diffs are not rendered by default.

29 changes: 15 additions & 14 deletions biosimulators_tellurium/data_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
import collections
import dataclasses
import enum
import roadrunner
import typing
# import roadrunner
# import typing

__all__ = [
'SedmlInterpreter',
Expand Down Expand Up @@ -280,16 +280,17 @@ class PreprocesssedTask(object):
""" Processed information about a SED task
Attributes:
road_runner (:obj:`roadrunner.RoadRunner`): Road Runner instance with model
solver (:obj:`roadrunner.Integrator` or :obj:`roadrunner.SteadyStateSolver`): solver
model_change_target_tellurium_id_map (:obj:`dict`): dictionary that maps the targets of
changes to their corresponding tellurium identifiers (tuples of their type and index within their type)
algorithm_kisao_id (:obj:`str`): KiSAO id of algorithm to execute
variable_target_tellurium_observable_map (:obj:`dict`): dictionary that maps tuples of variable targets and
symbols to their corresponding tellurium observable identifiers
road_runners (:obj:`roadrunner.RoadRunner`): Road Runner instances with model, per task
solver (:obj:`roadrunner.Integrator` or :obj:`roadrunner.SteadyStateSolver`): solver, per task
model_change_target_tellurium_id_map (:obj:`dict`): dictionaries that map the targets of
changes to their corresponding tellurium identifiers (tuples of their type and index within their type), per task
algorithm_kisao_id (:obj:`str`): dictionaries of KiSAO id of algorithm to execute, per task
variable_target_tellurium_observable_maps (:obj:`dict`): dictionary of dictionaries that map tuples of variable targets and
symbols to their corresponding tellurium observable identifiers, per task
"""
road_runner: roadrunner.RoadRunner
solver: typing.Union[roadrunner.Integrator, roadrunner.SteadyStateSolver]
model_change_target_tellurium_id_map: dict
algorithm_kisao_id: str
variable_target_tellurium_observable_map: dict
road_runners: dict
# solvers is dict of this type: typing.Union[roadrunner.Integrator, roadrunner.SteadyStateSolver]
solvers: dict
model_change_target_tellurium_id_maps: dict
algorithm_kisao_ids: dict
variable_target_tellurium_observable_maps: dict
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
biosimulators_utils[logging] >= 0.1.180
biosimulators_utils[logging] >= 0.1.183
kisao >= 2.33
libroadrunner >= 2.4.0
lxml
Expand Down
Binary file added tests/fixtures/change_initial_assignment.omex
Binary file not shown.
Binary file added tests/fixtures/repeat_basic.omex
Binary file not shown.
Binary file added tests/fixtures/repeat_initial_assignment.omex
Binary file not shown.
Binary file added tests/fixtures/repeat_no_reset.omex
Binary file not shown.
66 changes: 61 additions & 5 deletions tests/test_core_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,9 @@ def test_exec_sed_task_error_handling_with_biosimulators(self):
def test_exec_sed_task_with_preprocesssed_task(self):
# configure simulation
task = sedml_data_model.Task(
id="task1",
model=sedml_data_model.Model(
id="model1",
source=self.EXAMPLE_MODEL_FILENAME,
language=sedml_data_model.ModelLanguage.SBML.value,
changes=[
Expand Down Expand Up @@ -522,9 +524,9 @@ def test_exec_sed_task_with_preprocesssed_task(self):
variable_results, log = core.exec_sed_task(task, variables, preprocessed_task=preprocessed_task)
with self.assertRaises(AssertionError):
numpy.testing.assert_allclose(variable_results['C'][-1], end_c)
mid_c = preprocessed_task.road_runner['C']
mid_m = preprocessed_task.road_runner['M']
mid_x = preprocessed_task.road_runner['X']
mid_c = preprocessed_task.road_runners[task.id]['C']
mid_m = preprocessed_task.road_runners[task.id]['M']
mid_x = preprocessed_task.road_runners[task.id]['X']
self.assertIsInstance(mid_c, float)

variable_results, log = core.exec_sed_task(task, variables, preprocessed_task=preprocessed_task)
Expand All @@ -547,6 +549,8 @@ def test_exec_sed_task_with_preprocesssed_task(self):
new_value=mid_x,
),
]
for change in task.model.changes:
change.model = task.model.id
preprocessed_task = core.preprocess_sed_task(task, variables)
variable_results, log = core.exec_sed_task(task, variables, preprocessed_task=preprocessed_task)
numpy.testing.assert_allclose(variable_results['C'][-1], end_c)
Expand Down Expand Up @@ -581,6 +585,9 @@ def test_exec_sed_task_with_preprocesssed_task(self):
new_value=str(mid_x),
),
]
for change in task.model.changes:
change.model = task.model.id
preprocessed_task = core.preprocess_sed_task(task, variables)
variable_results, log = core.exec_sed_task(task, variables, preprocessed_task=preprocessed_task)
numpy.testing.assert_allclose(variable_results['C'][-1], end_c)

Expand Down Expand Up @@ -751,8 +758,6 @@ def test_exec_sedml_docs_in_combine_archive(self):
if log.exception:
raise log.exception

self._assert_curated_combine_archive_outputs(dirname, reports=True, plots=True)

def test_exec_sedml_docs_in_combine_archive_with_all_algorithms(self):
for sedml_interpreter in SedmlInterpreter.__members__.values():
for alg in gen_algorithms_from_specs(self.SPECIFICATIONS_FILENAME).values():
Expand Down Expand Up @@ -824,6 +829,57 @@ def test_sim_with_docker_image(self):

self._assert_curated_combine_archive_outputs(self.dirname, reports=True, plots=True)

def test_repeated_task_with_change(self):
for sedml_interpreter in SedmlInterpreter.__members__.values():
simulator_config = SimulatorConfig()
simulator_config.sedml_interpreter = sedml_interpreter

archive_filename = 'tests/fixtures/repeat_basic.omex'

dirname = os.path.join(self.dirname, sedml_interpreter.name, 'reports')
_, log = core.exec_sedml_docs_in_combine_archive(archive_filename, dirname, simulator_config=simulator_config)
if log.exception:
raise log.exception


def test_repeated_task_with_change_and_no_reset(self):
for sedml_interpreter in SedmlInterpreter.__members__.values():
simulator_config = SimulatorConfig()
simulator_config.sedml_interpreter = sedml_interpreter

archive_filename = 'tests/fixtures/repeat_no_reset.omex'

dirname = os.path.join(self.dirname, sedml_interpreter.name, 'reports')
_, log = core.exec_sedml_docs_in_combine_archive(archive_filename, dirname, simulator_config=simulator_config)
if log.exception:
raise log.exception


def test_repeated_task_with_change_to_initial_assignment(self):
for sedml_interpreter in SedmlInterpreter.__members__.values():
simulator_config = SimulatorConfig()
simulator_config.sedml_interpreter = sedml_interpreter

archive_filename = 'tests/fixtures/repeat_initial_assignment.omex'

dirname = os.path.join(self.dirname, sedml_interpreter.name, 'reports')
_, log = core.exec_sedml_docs_in_combine_archive(archive_filename, dirname, simulator_config=simulator_config)
if log.exception:
raise log.exception


def test_change_to_initial_assignment(self):
for sedml_interpreter in SedmlInterpreter.__members__.values():
simulator_config = SimulatorConfig()
simulator_config.sedml_interpreter = sedml_interpreter

archive_filename = 'tests/fixtures/change_initial_assignment.omex'

dirname = os.path.join(self.dirname, sedml_interpreter.name, 'reports')
_, log = core.exec_sedml_docs_in_combine_archive(archive_filename, dirname, simulator_config=simulator_config)
if log.exception:
raise log.exception

# helper methods
def _get_combine_archive_exec_env(self):
return {
Expand Down

0 comments on commit 84baede

Please sign in to comment.