Skip to content

Commit

Permalink
Updated for renaming 'biosimulators_utils.exec_status' to 'biosimulat…
Browse files Browse the repository at this point in the history
…ors_utils.log'

Set 'VERBOSE' environment variable in Dockerfile
Added log argument to 'exec_sed_task'
Added simulation method, argument info to log
  • Loading branch information
jonrkarr committed Jan 13, 2021
1 parent 51e87c4 commit 7c8f855
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
max-line-length = 150
exclude =
tests/*
docs/*
docs-src/*
5 changes: 3 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

FROM python:3.7.9-slim-buster

ARG VERSION="0.1.0"
ARG VERSION="0.1.1"
ARG SIMULATOR_VERSION=2.5.2

# metadata
Expand Down Expand Up @@ -74,7 +74,8 @@ ENV PATH=${PATH}:/opt/BioNetGen-${SIMULATOR_VERSION}/
COPY . /root/Biosimulators_BioNetGen
RUN pip install /root/Biosimulators_BioNetGen \
&& rm -rf /root/Biosimulators_BioNetGen
ENV MPLBACKEND=PDF
ENV VERBOSE=0 \
MPLBACKEND=PDF

# setup entry point
ENTRYPOINT ["bionetgen"]
Expand Down
2 changes: 1 addition & 1 deletion biosimulators_bionetgen/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.1.0'
__version__ = '0.1.1'
38 changes: 27 additions & 11 deletions biosimulators_bionetgen/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
get_variables_results_from_observable_results, add_variables_to_model)
from .warnings import IgnoredBnglFileContentWarning
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 import validation
Expand Down Expand Up @@ -42,25 +43,32 @@ 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=False,
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=False,
report_formats=report_formats,
plot_formats=plot_formats,
bundle_outputs=bundle_outputs,
keep_individual_outputs=keep_individual_outputs)


def exec_sed_task(sed_task, variables):
def exec_sed_task(sed_task, variables, log=None):
""" Execute a task and save its results
Args:
sed_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
"""
""" Validate task
Expand All @@ -84,7 +92,9 @@ def exec_sed_task(sed_task, variables):
* :obj:`add_variables_to_task`
* BioNetGen
* :obj:`get_variables_results_from_observable_results`
"""
"""
log = log or TaskLog()

validation.validate_task(sed_task)
validation.validate_model_language(sed_task.model.language, ModelLanguage.BNGL)
validation.validate_model_change_types(sed_task.model.changes, (ModelAttributeChange, ))
Expand Down Expand Up @@ -116,5 +126,11 @@ def exec_sed_task(sed_task, variables):
for key in variable_results.keys():
variable_results[key] = variable_results[key][-(sed_task.simulation.number_of_points + 1):]

# return the values of the variables
return variable_results
# log action
log.algorithm = sed_task.simulation.algorithm.kisao_id
log.simulator_details = {
'actions': bionetgen_task.actions,
}

# return the values of the variables and log
return variable_results, log
2 changes: 1 addition & 1 deletion biosimulators_bionetgen/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def add_model_attribute_change_to_task(task, change):
'function arguments and expression': function_args_expression_match,
}
msg = '`{}` is not a valid target. The following patterns of targets are supported:\n - {}'.format(
target, '\n - {}'.join('{}: `{}`'.format(key, target_patterns[key]) for key in sorted(target_patterns.keys())))
target, '\n - '.join('{}: `{}`'.format(key, target_patterns[key]) for key in sorted(target_patterns.keys())))
raise NotImplementedError(msg)


Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
biosimulators_utils >= 0.1.31
biosimulators_utils >= 0.1.32
pandas
12 changes: 6 additions & 6 deletions tests/test_core_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def test_exec_sed_task(self):
doc.models[0].source = os.path.join(os.path.dirname(__file__), 'fixtures', 'test.bngl')

variables = [data_gen.variables[0] for data_gen in doc.data_generators]
variable_results = exec_sed_task(doc.tasks[0], variables)
variable_results, _ = exec_sed_task(doc.tasks[0], variables)

self.assertEqual(set(variable_results.keys()), set([var.id for var in variables]))
for var in variables:
Expand All @@ -58,7 +58,7 @@ def test_exec_sed_task_non_zero_initial_time(self):
doc.simulations[0].initial_time = 0.1

variables = [data_gen.variables[0] for data_gen in doc.data_generators]
variable_results = exec_sed_task(doc.tasks[0], variables)
variable_results, _ = exec_sed_task(doc.tasks[0], variables)

self.assertEqual(set(variable_results.keys()), set([var.id for var in variables]))
for var in variables:
Expand Down Expand Up @@ -166,10 +166,10 @@ def _build_sed_doc(self, algorithm=None):
source='model_1.bngl',
language=sedml_data_model.ModelLanguage.BNGL.value,
changes=[
sedml_data_model.ModelAttributeChange('functions.gfunc.expression', '0.5*Atot^2/(10 + Atot^2)'),
sedml_data_model.ModelAttributeChange('functions.gfunc().expression', '0.5*Atot^2/(10 + Atot^2)'),
sedml_data_model.ModelAttributeChange('species.A().initialCount', '5'),
sedml_data_model.ModelAttributeChange('parameters.g1.value', '16.0'),
sedml_data_model.ModelAttributeChange(target='functions.gfunc.expression', new_value='0.5*Atot^2/(10 + Atot^2)'),
sedml_data_model.ModelAttributeChange(target='functions.gfunc().expression', new_value='0.5*Atot^2/(10 + Atot^2)'),
sedml_data_model.ModelAttributeChange(target='species.A().initialCount', new_value='5'),
sedml_data_model.ModelAttributeChange(target='parameters.g1.value', new_value='16.0'),
],
))
doc.simulations.append(sedml_data_model.UniformTimeCourseSimulation(
Expand Down

0 comments on commit 7c8f855

Please sign in to comment.