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 65a9b62 commit 2d386b0
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 53 deletions.
7 changes: 6 additions & 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.1.31
ARG VERSION=0.1.32
ARG SIMULATOR_VERSION="1.6.2"

# metadata
Expand Down Expand Up @@ -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 \
Expand Down
4 changes: 4 additions & 0 deletions biosimulators.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
},
"operatingSystemType": "Linux"
},
"pythonApi": {
"package": "biosimulators-gillespy2",
"module": "biosimulators_gillespy2"
},
"authors": [
{
"firstName": "Brian",
Expand Down
2 changes: 1 addition & 1 deletion biosimulators_gillespy2/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.1.31'
__version__ = '0.1.32'
43 changes: 16 additions & 27 deletions biosimulators_gillespy2/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -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`:
Expand All @@ -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`:
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
53 changes: 30 additions & 23 deletions tests/test_core_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 = [
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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']))
Expand Down

0 comments on commit 2d386b0

Please sign in to comment.