Skip to content

Commit

Permalink
feat: updated to Biosimulators-utils 0.1.114: organized options, adde…
Browse files Browse the repository at this point in the history
…d option to control logging; added Python package to specs; added fonts to Docker image
  • Loading branch information
jonrkarr committed Sep 1, 2021
1 parent 87f7361 commit 498fe52
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 41 deletions.
10 changes: 9 additions & 1 deletion biosimulators.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
},
"operatingSystemType": "Linux"
},
"pythonApi": {
"package": "biosimulators-libsbmlsim",
"module": "biosimulators_libsbmlsim"
},
"authors": [{
"firstName": "Hiromu",
"lastName": "Takizawa",
Expand Down Expand Up @@ -79,7 +83,11 @@
}
],
"references": {
"identifiers": [],
"identifiers": [{
"namespace": "pypi",
"id": "biosimulators-libsbmlsim",
"url": "https://pypi.org/project/biosimulators-libsbmlsim/"
}],
"citations": [{
"title": "LibSBMLSim: a reference implementation of fully functional SBML simulator",
"authors": "Hiromu Takizawa, Kazushige Nakamura, Akito Tabira, Yoichi Chikahara, Tatsuhiro Matsui, Noriko Hiroi & Akira Funahashi",
Expand Down
7 changes: 6 additions & 1 deletion biosimulators/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.2
ARG VERSION=0.0.3
ARG SIMULATOR_VERSION=1.4.0
ARG LIBSBML_VERSION=5.19.0

Expand Down Expand Up @@ -78,6 +78,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 biosimulators/ /root/biosimulators/
RUN pip install /root/biosimulators \
Expand Down
2 changes: 1 addition & 1 deletion biosimulators/biosimulators_libsbmlsim/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.0.2'
__version__ = '0.0.3'
57 changes: 23 additions & 34 deletions biosimulators/biosimulators_libsbmlsim/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from .data_model import KISAO_ALGORITHMS_MAP, get_integrator
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
Expand All @@ -31,11 +31,7 @@
__all__ = ['exec_sedml_docs_in_combine_archive', 'exec_sed_task']


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:
Expand All @@ -47,12 +43,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`:
Expand All @@ -63,31 +54,28 @@ 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`:
:obj:`VariableResults`: results of variables
:obj:`TaskLog`: log
'''
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
Expand Down Expand Up @@ -121,7 +109,7 @@ def exec_sed_task(task, variables, log=None):
raise NotImplementedError(msg)

# determine the simulation algorithm
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(
sim.algorithm.kisao_id, KISAO_ALGORITHMS_MAP.keys(),
substitution_policy=algorithm_substitution_policy)
Expand Down Expand Up @@ -267,18 +255,19 @@ def exec_sed_task(task, variables, log=None):
raise NotImplementedError(msg)

# log action
log.algorithm = exec_kisao_id
log.simulator_details = {
'method': "simulateSBMLFromFile",
'arguments': {
'sim_time': sim.output_end_time,
'dt': time_step,
'print_interval': print_interval,
'print_amount': print_amount,
'method': integrator,
'use_lazy_method': use_lazy_newton_method,
},
}
if config.LOG:
log.algorithm = exec_kisao_id
log.simulator_details = {
'method': "simulateSBMLFromFile",
'arguments': {
'sim_time': sim.output_end_time,
'dt': time_step,
'print_interval': print_interval,
'print_amount': print_amount,
'method': integrator,
'use_lazy_method': use_lazy_newton_method,
},
}

# return results and log
return variable_results, log
2 changes: 1 addition & 1 deletion biosimulators/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
biosimulators_utils[sbml,logging] >= 0.1.104
biosimulators_utils[sbml,logging] >= 0.1.114
# libsbmlsim
kisao
pandas
11 changes: 8 additions & 3 deletions biosimulators/tests/test_core_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from biosimulators_libsbmlsim.data_model import KISAO_ALGORITHMS_MAP
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.sedml.data_model import (
SedDocument, Model, ModelLanguage, UniformTimeCourseSimulation, Task, Variable, Symbol,
Algorithm, AlgorithmParameterChange,
Expand Down Expand Up @@ -260,9 +261,13 @@ def test_exec_sedml_docs_in_combine_archive(self):
CombineArchiveWriter().run(archive, archive_dirname, archive_filename)

out_dir = os.path.join(self.dirname, 'results')
core.exec_sedml_docs_in_combine_archive(
archive_filename, out_dir,
report_formats=[report_data_model.ReportFormat.h5])

config = get_config()
config.REPORT_FORMATS = [report_data_model.ReportFormat.h5]

_, log = core.exec_sedml_docs_in_combine_archive(archive_filename, out_dir, config=config)
if log.exception:
raise log.exception

results = ReportReader().run(report, out_dir, 'sim.sedml/report', format=report_data_model.ReportFormat.h5)

Expand Down

0 comments on commit 498fe52

Please sign in to comment.