Skip to content

Commit

Permalink
Updated for renaming 'biosimulators_utils.exec_status' to 'biosimulat…
Browse files Browse the repository at this point in the history
…ors_utils.log'

Set 'VERBOSE' environment variable in Dockerfile
Added log argument to 'exec_sed_task'
Added simulation method, argument info to log
  • Loading branch information
jonrkarr committed Jan 13, 2021
1 parent d77bf14 commit 4cba5af
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
max-line-length = 150
exclude =
tests/*
docs/*
docs-src/*
5 changes: 3 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Base OS
FROM continuumio/miniconda3:4.9.2

ARG VERSION=0.1.5
ARG VERSION=0.1.6
ARG SIMULATOR_VERSION="0.9.9"
ARG PYTHON_VERSION=3.7

Expand Down Expand Up @@ -68,7 +68,8 @@ RUN pip install /root/Biosimulators_PySCeS \
&& rm -rf /root/Biosimulators_PySCeS

# supported environment variables
ENV ALGORITHM_SUBSTITUTION_POLICY=SIMILAR_VARIABLES
ENV ALGORITHM_SUBSTITUTION_POLICY=SIMILAR_VARIABLES \
VERBOSE=0

# Entrypoint
ENTRYPOINT ["pysces"]
Expand Down
2 changes: 1 addition & 1 deletion biosimulators_pysces/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.1.5'
__version__ = '0.1.6'
47 changes: 37 additions & 10 deletions biosimulators_pysces/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from .data_model import KISAO_ALGORITHM_MAP
from biosimulators_utils.combine.exec import exec_sedml_docs_in_archive
from biosimulators_utils.log.data_model import CombineArchiveLog, TaskLog # noqa: F401
from biosimulators_utils.plot.data_model import PlotFormat # noqa: F401
from biosimulators_utils.report.data_model import ReportFormat, DataGeneratorVariableResults # noqa: F401
from biosimulators_utils.sedml.data_model import (Task, ModelLanguage, UniformTimeCourseSimulation, # noqa: F401
Expand Down Expand Up @@ -50,26 +51,35 @@ def exec_sedml_docs_in_combine_archive(archive_filename, out_dir,
plot_formats (:obj:`list` of :obj:`PlotFormat`, optional): report format (e.g., pdf)
bundle_outputs (:obj:`bool`, optional): if :obj:`True`, bundle outputs into archives for reports and plots
keep_individual_outputs (:obj:`bool`, optional): if :obj:`True`, keep individual output files
Returns:
:obj:`CombineArchiveLog`: log
"""
sed_doc_executer = functools.partial(exec_sed_doc, exec_sed_task)
exec_sedml_docs_in_archive(sed_doc_executer, archive_filename, out_dir,
apply_xml_model_changes=True,
report_formats=report_formats,
plot_formats=plot_formats,
bundle_outputs=bundle_outputs,
keep_individual_outputs=keep_individual_outputs)
return exec_sedml_docs_in_archive(sed_doc_executer, archive_filename, out_dir,
apply_xml_model_changes=True,
report_formats=report_formats,
plot_formats=plot_formats,
bundle_outputs=bundle_outputs,
keep_individual_outputs=keep_individual_outputs)


def exec_sed_task(task, variables):
def exec_sed_task(task, variables, log=None):
''' Execute a task and save its results
Args:
task (:obj:`Task`): task
variables (:obj:`list` of :obj:`DataGeneratorVariable`): variables that should be recorded
log (:obj:`TaskLog`, optional): log for the task
Returns:
:obj:`DataGeneratorVariableResults`: results of variables
:obj:`tuple`:
:obj:`DataGeneratorVariableResults`: results of variables
:obj:`TaskLog`: log
'''
log = log or TaskLog()

validation.validate_task(task)
validation.validate_model_language(task.model.language, ModelLanguage.SBML)
validation.validate_model_change_types(task.model.changes, ())
Expand Down Expand Up @@ -208,5 +218,22 @@ def exec_sed_task(task, variables):
# restore working directory
os.chdir(cwd)

# return results
return variable_results
# log action
log.algorithm = 'KISAO_0000019' if model.mode_integrator == 'CVODE' else 'KISAO_0000088'

arguments = {}
for key, val in model.__settings__.items():
if model.mode_integrator == 'CVODE':
if key.startswith('cvode_'):
arguments[key] = val
else:
if key.startswith('lsoda_'):
arguments[key] = val

log.simulator_details = {
'method': model.Simulate.__module__ + '.' + model.Simulate.__name__,
'arguments': arguments,
}

# return results and log
return variable_results, log
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
biosimulators_utils >= 0.1.30
biosimulators_utils >= 0.1.32
numpy
pysces
7 changes: 4 additions & 3 deletions tests/test_core_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from biosimulators_pysces import __main__
from biosimulators_pysces import core
from biosimulators_utils.combine import data_model as combine_data_model
from biosimulators_utils.combine.exceptions import CombineArchiveExecutionError
from biosimulators_utils.combine.io import CombineArchiveWriter
from biosimulators_utils.report import data_model as report_data_model
from biosimulators_utils.report.io import ReportReader
Expand Down Expand Up @@ -71,7 +72,7 @@ def test_exec_sed_task_successfully(self):
sedml_data_model.DataGeneratorVariable(id='IL', target="/sbml:sbml/sbml:model/sbml:listOfSpecies/sbml:species[@id='IL']"),
]

variable_results = core.exec_sed_task(task, variables)
variable_results, _ = core.exec_sed_task(task, variables)

self.assertTrue(sorted(variable_results.keys()), sorted([var.id for var in variables]))
self.assertEqual(variable_results[variables[0].id].shape, (task.simulation.number_of_points + 1,))
Expand Down Expand Up @@ -343,7 +344,7 @@ def pysces_model(filename):

with mock.patch.dict(os.environ, env):
with mock.patch('pysces.model', side_effect=pysces_model):
with self.assertRaises(AlgorithmDoesNotSupportModelFeatureException):
with self.assertRaises(CombineArchiveExecutionError):
core.exec_sedml_docs_in_combine_archive(archive_filename, out_dir,
report_formats=[
report_data_model.ReportFormat.h5,
Expand All @@ -357,7 +358,7 @@ def pysces_model(filename):
with mock.patch.dict(os.environ, env):
with mock.patch('pysces.model', side_effect=pysces_model):
with mock.patch.object(pysces.PyscesModel.PysMod, 'Simulate', side_effect=Exception('Stop')):
with self.assertRaisesRegex(Exception, '^Stop$'):
with self.assertRaisesRegex(CombineArchiveExecutionError, 'Stop$'):
with self.assertWarns(AlgorithmSubstitutedWarning):
core.exec_sedml_docs_in_combine_archive(archive_filename, out_dir,
report_formats=[
Expand Down

0 comments on commit 4cba5af

Please sign in to comment.