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 1389ad0 commit 5363379
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 43 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.11"
ARG VERSION="0.1.12"
ARG SIMULATOR_VERSION=0.7.25

# metadata
Expand Down Expand Up @@ -39,6 +39,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_CBMPy
RUN pip install /root/Biosimulators_CBMPy \
Expand Down
4 changes: 4 additions & 0 deletions biosimulators.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
},
"operatingSystemType": "Linux"
},
"pythonApi": {
"package": "biosimulators-cbmpy",
"module": "biosimulators_cbmpy"
},
"authors": [{
"firstName": "Brett",
"middleName": "G.",
Expand Down
2 changes: 1 addition & 1 deletion biosimulators_cbmpy/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.1.11'
__version__ = '0.1.12'
43 changes: 16 additions & 27 deletions biosimulators_cbmpy/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
get_results_of_variables,
get_default_solver_module_function_args)
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 @@ -37,11 +37,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 @@ -53,12 +49,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 @@ -69,21 +60,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 @@ -96,8 +83,9 @@ 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()
log = log or TaskLog()
config = config or get_config()
if config.LOG and not log:
log = TaskLog()

model = task.model
sim = task.simulation
Expand Down Expand Up @@ -139,7 +127,7 @@ def exec_sed_task(task, variables, log=None):
# Set up the algorithm specified by :obj:`task.simulation.algorithm.kisao_id`
simulation = task.simulation
algorithm_kisao_id = simulation.algorithm.kisao_id
alg_substitution_policy = get_algorithm_substitution_policy()
alg_substitution_policy = get_algorithm_substitution_policy(config=config)
exec_kisao_id = get_preferred_substitute_algorithm_by_ids(
algorithm_kisao_id, KISAO_ALGORITHMS_PARAMETERS_MAP.keys(),
substitution_policy=alg_substitution_policy)
Expand Down Expand Up @@ -195,11 +183,12 @@ def exec_sed_task(task, variables, log=None):
variables, model, solution)

# log action
log.algorithm = exec_kisao_id
log.simulator_details = {
'method': simulation_method.__module__ + '.' + simulation_method.__name__,
'arguments': simulation_method_args,
}
if config.LOG:
log.algorithm = exec_kisao_id
log.simulator_details = {
'method': simulation_method.__module__ + '.' + simulation_method.__name__,
'arguments': simulation_method_args,
}

# return the result of each variable 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.104
biosimulators_utils[logging] >= 0.1.114
cbmpy <= 0.7.25
glpk
kisao
Expand Down
35 changes: 22 additions & 13 deletions tests/test_core_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
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.config import get_config
from biosimulators_utils.report import data_model as report_data_model
from biosimulators_utils.report.io import ReportReader
from biosimulators_utils.simulator.exec import exec_sedml_docs_in_archive_with_containerized_simulator
Expand Down Expand Up @@ -313,18 +314,23 @@ def test_exec_sed_task_error_handling_no_solution(self):

_, archive_filename = self._build_combine_archive(model_changes=model_changes)
with self.assertRaisesRegex(CombineArchiveExecutionError, 'could not be found'):
core.exec_sedml_docs_in_combine_archive(archive_filename, self.dirname)
_, log = core.exec_sedml_docs_in_combine_archive(archive_filename, self.dirname)
if log.exception:
raise log.exception

def test_exec_sedml_docs_in_combine_archive_successfully(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,
],
bundle_outputs=True,
keep_individual_outputs=True)

config = get_config()
config.REPORT_FORMATS = [report_data_model.ReportFormat.h5]
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 @@ -604,12 +610,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,
],
bundle_outputs=True,
keep_individual_outputs=True)

config = get_config()
config.REPORT_FORMATS = [report_data_model.ReportFormat.h5]
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

0 comments on commit 5363379

Please sign in to comment.