Skip to content

Commit

Permalink
feat: separated simulation and pre-processing
Browse files Browse the repository at this point in the history
  • Loading branch information
jonrkarr committed Sep 3, 2021
1 parent b298021 commit c2ec9f5
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 31 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Base OS
FROM python:3.9-slim-buster

ARG VERSION="0.0.5"
ARG VERSION="0.0.6"
ARG SIMULATOR_VERSION=8.0

# metadata
Expand Down
2 changes: 1 addition & 1 deletion biosimulators_xpp/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.0.5'
__version__ = '0.0.6'
70 changes: 41 additions & 29 deletions biosimulators_xpp/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def exec_sed_task(task, variables, preprocessed_task=None, log=None, config=None
Args:
task (:obj:`Task`): task
variables (:obj:`list` of :obj:`Variable`): variables that should be recorded
preprocessed_task (:obj:`object`, optional): preprocessed information about the task, including possible
preprocessed_task (:obj:`dict`, optional): preprocessed information about the task, including possible
model changes and variables. This can be used to avoid repeatedly executing the same initialization
for repeated calls to this method.
log (:obj:`TaskLog`, optional): log for the task
Expand Down Expand Up @@ -127,36 +127,14 @@ def exec_sed_task(task, variables, preprocessed_task=None, log=None, config=None
model = task.model
sim = task.simulation

if config.VALIDATE_SEDML:
raise_errors_warnings(validation.validate_task(task),
error_summary='Task `{}` is invalid.'.format(task.id))
raise_errors_warnings(validation.validate_model_language(model.language, ModelLanguage.XPP),
error_summary='Language for model `{}` is not supported.'.format(model.id))
raise_errors_warnings(validation.validate_model_change_types(model.changes, (ModelAttributeChange, )),
error_summary='Changes for model `{}` are not supported.'.format(model.id))
raise_errors_warnings(*validation.validate_model_changes(model),
error_summary='Changes for model `{}` are invalid.'.format(model.id))
raise_errors_warnings(validation.validate_simulation_type(sim, (UniformTimeCourseSimulation, )),
error_summary='{} `{}` is not supported.'.format(sim.__class__.__name__, sim.id))
raise_errors_warnings(*validation.validate_simulation(sim),
error_summary='Simulation `{}` is invalid.'.format(sim.id))

if config.VALIDATE_SEDML_MODELS:
raise_errors_warnings(*validation.validate_model(model, [], working_dir='.'),
error_summary='Model `{}` is invalid.'.format(model.id),
warning_summary='Model `{}` may be invalid.'.format(model.id))

# read model
_, _, xpp_sim = validate_model(model.source)

# validate observables
validate_variables(xpp_sim, variables)
xpp_sim = preprocessed_task['xpp_simulation']

# model changes
apply_model_changes(xpp_sim, model.changes)

# setup simulation
exec_kisao_id = set_up_simulation(sim, xpp_sim['simulation_method'], config=config)
exec_kisao_id = preprocessed_task['algorithm_kisao_id']

# run simulation
raw_results = exec_xpp_simulation(model.source, xpp_sim)
Expand All @@ -181,12 +159,46 @@ def preprocess_sed_task(task, variables, config=None):
Args:
task (:obj:`Task`): task
variables (:obj:`list` of :obj:`Variable`): variables that should be recorded
preprocessed_task (:obj:`PreprocessedTask`, optional): preprocessed information about the task, including possible
model changes and variables. This can be used to avoid repeatedly executing the same initialization for repeated
calls to this method.
config (:obj:`Config`, optional): BioSimulators common configuration
Returns:
:obj:`object`: preprocessed information about the task
"""
pass
config = config or get_config()

# validate task
model = task.model
sim = task.simulation

if config.VALIDATE_SEDML:
raise_errors_warnings(validation.validate_task(task),
error_summary='Task `{}` is invalid.'.format(task.id))
raise_errors_warnings(validation.validate_model_language(model.language, ModelLanguage.XPP),
error_summary='Language for model `{}` is not supported.'.format(model.id))
raise_errors_warnings(validation.validate_model_change_types(model.changes, (ModelAttributeChange, )),
error_summary='Changes for model `{}` are not supported.'.format(model.id))
raise_errors_warnings(*validation.validate_model_changes(model),
error_summary='Changes for model `{}` are invalid.'.format(model.id))
raise_errors_warnings(validation.validate_simulation_type(sim, (UniformTimeCourseSimulation, )),
error_summary='{} `{}` is not supported.'.format(sim.__class__.__name__, sim.id))
raise_errors_warnings(*validation.validate_simulation(sim),
error_summary='Simulation `{}` is invalid.'.format(sim.id))

if config.VALIDATE_SEDML_MODELS:
raise_errors_warnings(*validation.validate_model(model, [], working_dir='.'),
error_summary='Model `{}` is invalid.'.format(model.id),
warning_summary='Model `{}` may be invalid.'.format(model.id))

# read model
_, _, xpp_sim = validate_model(model.source)

# validate observables
validate_variables(xpp_sim, variables)

# setup simulation
exec_kisao_id = set_up_simulation(sim, xpp_sim['simulation_method'], config=config)

return {
'xpp_simulation': xpp_sim,
'algorithm_kisao_id': exec_kisao_id,
}

0 comments on commit c2ec9f5

Please sign in to comment.