From 2d386b07b2b27fd58c6e617c1d755d8a011b80cb Mon Sep 17 00:00:00 2001 From: Jonathan Karr Date: Wed, 1 Sep 2021 15:51:13 -0400 Subject: [PATCH] feat: updated to Biosimulators-utils 0.1.114: organized options, added option to control logging; added Python package to specs; added fonts to Docker image --- Dockerfile | 7 +++- biosimulators.json | 4 +++ biosimulators_gillespy2/_version.py | 2 +- biosimulators_gillespy2/core.py | 43 +++++++++-------------- requirements.txt | 2 +- tests/test_core_main.py | 53 ++++++++++++++++------------- 6 files changed, 58 insertions(+), 53 deletions(-) diff --git a/Dockerfile b/Dockerfile index cdbc018..3f7368a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ # Base OS FROM python:3.9-slim-buster -ARG VERSION=0.1.31 +ARG VERSION=0.1.32 ARG SIMULATOR_VERSION="1.6.2" # metadata @@ -35,6 +35,11 @@ RUN apt-get update -y \ && apt-get autoremove -y \ && rm -rf /var/lib/apt/lists/* +# fonts for matplotlib +RUN apt-get update -y \ + && apt-get install -y --no-install-recommends libfreetype6 \ + && rm -rf /var/lib/apt/lists/* + # Copy code for command-line interface into image and install it COPY . /root/Biosimulators_GillesPy2 RUN pip install /root/Biosimulators_GillesPy2 \ diff --git a/biosimulators.json b/biosimulators.json index 422fe70..09a127b 100644 --- a/biosimulators.json +++ b/biosimulators.json @@ -19,6 +19,10 @@ }, "operatingSystemType": "Linux" }, + "pythonApi": { + "package": "biosimulators-gillespy2", + "module": "biosimulators_gillespy2" + }, "authors": [ { "firstName": "Brian", diff --git a/biosimulators_gillespy2/_version.py b/biosimulators_gillespy2/_version.py index f9b925b..8dcfa7d 100644 --- a/biosimulators_gillespy2/_version.py +++ b/biosimulators_gillespy2/_version.py @@ -1 +1 @@ -__version__ = '0.1.31' +__version__ = '0.1.32' diff --git a/biosimulators_gillespy2/core.py b/biosimulators_gillespy2/core.py index cf8e828..593f050 100644 --- a/biosimulators_gillespy2/core.py +++ b/biosimulators_gillespy2/core.py @@ -9,7 +9,7 @@ from .data_model import KISAO_ALGORITHM_MAP from biosimulators_utils.combine.exec import exec_sedml_docs_in_archive -from biosimulators_utils.config import get_config +from biosimulators_utils.config import get_config, Config # noqa: F401 from biosimulators_utils.log.data_model import CombineArchiveLog, TaskLog # noqa: F401 from biosimulators_utils.viz.data_model import VizFormat # noqa: F401 from biosimulators_utils.report.data_model import ReportFormat, VariableResults, SedDocumentResults # noqa: F401 @@ -32,11 +32,7 @@ ] -def exec_sedml_docs_in_combine_archive(archive_filename, out_dir, - return_results=False, - report_formats=None, plot_formats=None, - bundle_outputs=None, keep_individual_outputs=None, - raise_exceptions=True): +def exec_sedml_docs_in_combine_archive(archive_filename, out_dir, config=None): """ Execute the SED tasks defined in a COMBINE/OMEX archive and save the outputs Args: @@ -48,12 +44,7 @@ def exec_sedml_docs_in_combine_archive(archive_filename, out_dir, * HDF5: directory in which to save a single HDF5 file (``{ out_dir }/reports.h5``), with reports at keys ``{ relative-path-to-SED-ML-file-within-archive }/{ report.id }`` within the HDF5 file - return_results (:obj:`bool`, optional): whether to return the result of each output of each SED-ML file - report_formats (:obj:`list` of :obj:`ReportFormat`, optional): report format (e.g., csv or h5) - plot_formats (:obj:`list` of :obj:`VizFormat`, 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 - raise_exceptions (:obj:`bool`, optional): whether to raise exceptions + config (:obj:`Config`, optional): BioSimulators common configuration Returns: :obj:`tuple`: @@ -64,21 +55,17 @@ def exec_sedml_docs_in_combine_archive(archive_filename, out_dir, sed_doc_executer = functools.partial(exec_sed_doc, exec_sed_task) return exec_sedml_docs_in_archive(sed_doc_executer, archive_filename, out_dir, apply_xml_model_changes=True, - return_results=return_results, - report_formats=report_formats, - plot_formats=plot_formats, - bundle_outputs=bundle_outputs, - keep_individual_outputs=keep_individual_outputs, - raise_exceptions=raise_exceptions) + config=config) -def exec_sed_task(task, variables, log=None): +def exec_sed_task(task, variables, log=None, config=None): ''' Execute a task and save its results Args: task (:obj:`Task`): task variables (:obj:`list` of :obj:`Variable`): variables that should be recorded log (:obj:`TaskLog`, optional): log for the task + config (:obj:`Config`, optional): BioSimulators common configuration Returns: :obj:`tuple`: @@ -91,9 +78,10 @@ def exec_sed_task(task, variables, log=None): could not be recorded :obj:`NotImplementedError`: if the task is not of a supported type or involves an unsuported feature ''' - config = get_config() + config = config or get_config() - log = log or TaskLog() + if config.LOG and not log: + log = TaskLog() model = task.model sim = task.simulation @@ -125,7 +113,7 @@ def exec_sed_task(task, variables, log=None): # Load the algorithm specified by `simulation.algorithm` simulation = task.simulation algorithm_kisao_id = simulation.algorithm.kisao_id - algorithm_substitution_policy = get_algorithm_substitution_policy() + algorithm_substitution_policy = get_algorithm_substitution_policy(config=config) exec_kisao_id = get_preferred_substitute_algorithm_by_ids( algorithm_kisao_id, KISAO_ALGORITHM_MAP.keys(), substitution_policy=algorithm_substitution_policy) @@ -237,11 +225,12 @@ def exec_sed_task(task, variables, log=None): variable_results[variable.id] = dynamics[-(simulation.number_of_points + 1):] # log action - log.algorithm = exec_kisao_id - log.simulator_details = { - 'method': solver.__module__ + '.' + solver.__name__, - 'arguments': dict(**algorithm.solver_args, **algorithm_params), - } + if config.LOG: + log.algorithm = exec_kisao_id + log.simulator_details = { + 'method': solver.__module__ + '.' + solver.__name__, + 'arguments': dict(**algorithm.solver_args, **algorithm_params), + } # return results and log return variable_results, log diff --git a/requirements.txt b/requirements.txt index d1ad9a4..c59fc46 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -biosimulators_utils[logging] >= 0.1.107 +biosimulators_utils[logging] >= 0.1.114 gillespy2 >= 1.6.0 kisao lxml # optional dependency of python_libsbml diff --git a/tests/test_core_main.py b/tests/test_core_main.py index f151093..c5924a0 100644 --- a/tests/test_core_main.py +++ b/tests/test_core_main.py @@ -12,6 +12,7 @@ from biosimulators_utils.archive.io import ArchiveReader from biosimulators_utils.combine import data_model as combine_data_model from biosimulators_utils.combine.io import CombineArchiveWriter +from biosimulators_utils.config import get_config from biosimulators_utils.log.data_model import TaskLog from biosimulators_utils.report import data_model as report_data_model from biosimulators_utils.report.io import ReportReader @@ -249,7 +250,7 @@ def test_exec_sed_task_errors(self): core.exec_sed_task(task, variables, TaskLog()) task.model.source = os.path.join(os.path.dirname(__file__), 'fixtures', 'BIOMD0000000297.edited', 'ex1', 'BIOMD0000000297.xml') - with self.assertRaisesRegex(AlgorithmCannotBeSubstitutedException, 'No algorithm can be substituted'): + with self.assertRaisesRegex(AlgorithmCannotBeSubstitutedException, 'Algorithms cannot be substituted'): core.exec_sed_task(task, variables, TaskLog()) task.simulation.algorithm.kisao_id = 'KISAO_0000029' task.simulation.algorithm.changes = [ @@ -383,13 +384,15 @@ def test_exec_sedml_docs_in_combine_archive(self): doc, archive_filename = self._build_combine_archive() out_dir = os.path.join(self.dirname, 'out') - core.exec_sedml_docs_in_combine_archive(archive_filename, out_dir, - report_formats=[ - report_data_model.ReportFormat.h5, - report_data_model.ReportFormat.csv, - ], - bundle_outputs=True, - keep_individual_outputs=True) + + config = get_config() + config.REPORT_FORMATS = [report_data_model.ReportFormat.h5, report_data_model.ReportFormat.csv] + config.BUNDLE_OUTPUTS = True + config.KEEP_INDIVIDUAL_OUTPUTS = True + + _, log = core.exec_sedml_docs_in_combine_archive(archive_filename, out_dir, config=config) + if log.exception: + raise log.exception self._assert_combine_archive_outputs(doc, out_dir) @@ -440,13 +443,15 @@ def test_exec_sedml_docs_in_combine_archive_with_all_algorithms(self): doc, archive_filename = self._build_combine_archive(algorithm=alg) out_dir = os.path.join(self.dirname, alg.kisao_id) - core.exec_sedml_docs_in_combine_archive(archive_filename, out_dir, - report_formats=[ - report_data_model.ReportFormat.h5, - report_data_model.ReportFormat.csv, - ], - bundle_outputs=True, - keep_individual_outputs=True) + + config = get_config() + config.REPORT_FORMATS = [report_data_model.ReportFormat.h5, report_data_model.ReportFormat.csv] + config.BUNDLE_OUTPUTS = True + config.KEEP_INDIVIDUAL_OUTPUTS = True + + _, log = core.exec_sedml_docs_in_combine_archive(archive_filename, out_dir, config=config) + if log.exception: + raise log.exception self._assert_combine_archive_outputs(doc, out_dir) @@ -642,14 +647,16 @@ def test_exec_sedml_docs_in_combine_archive_with_docker_image(self): def test_more_complex_archive(self): archive_filename = os.path.join(os.path.dirname(__file__), 'fixtures', 'BIOMD0000000297.edited.omex') - core.exec_sedml_docs_in_combine_archive(archive_filename, self.dirname, - report_formats=[ - report_data_model.ReportFormat.csv, - report_data_model.ReportFormat.h5, - ], - plot_formats=[], - bundle_outputs=True, - keep_individual_outputs=True) + + config = get_config() + config.REPORT_FORMATS = [report_data_model.ReportFormat.h5, report_data_model.ReportFormat.csv] + config.VIZ_FORMATS = [] + config.BUNDLE_OUTPUTS = True + config.KEEP_INDIVIDUAL_OUTPUTS = True + + _, log = core.exec_sedml_docs_in_combine_archive(archive_filename, self.dirname, config=config) + if log.exception: + raise log.exception self.assertEqual(set(['reports.zip', 'reports.h5', 'ex1', 'ex2']).difference(set(os.listdir(self.dirname))), set()) self.assertEqual(set(os.listdir(os.path.join(self.dirname, 'ex1'))), set(['BIOMD0000000297.sedml']))