diff --git a/.flake8 b/.flake8 index 4dda4d6..af7960a 100644 --- a/.flake8 +++ b/.flake8 @@ -2,4 +2,4 @@ max-line-length = 150 exclude = tests/* - docs/* + docs-src/* diff --git a/Dockerfile b/Dockerfile index b4d047d..d160c2d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 @@ -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"] diff --git a/biosimulators_pysces/_version.py b/biosimulators_pysces/_version.py index 66a87bb..2fb2513 100644 --- a/biosimulators_pysces/_version.py +++ b/biosimulators_pysces/_version.py @@ -1 +1 @@ -__version__ = '0.1.5' +__version__ = '0.1.6' diff --git a/biosimulators_pysces/core.py b/biosimulators_pysces/core.py index 98de3cf..058d95a 100644 --- a/biosimulators_pysces/core.py +++ b/biosimulators_pysces/core.py @@ -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 @@ -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, ()) @@ -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 diff --git a/requirements.txt b/requirements.txt index 157b82c..b225c69 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,3 @@ -biosimulators_utils >= 0.1.30 +biosimulators_utils >= 0.1.32 numpy pysces diff --git a/tests/test_core_main.py b/tests/test_core_main.py index 7d25d26..47d4cc3 100644 --- a/tests/test_core_main.py +++ b/tests/test_core_main.py @@ -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 @@ -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,)) @@ -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, @@ -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=[