Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend function support in BNGL import and pysb export #518

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

FFroehlich
Copy link
Contributor

@FFroehlich FFroehlich commented Sep 24, 2020

This adds support of all BNGL supported functions during import of BNGL models. For export of pysb models to file, all supported functions are always imported from sympy such that model evaluation does not fail in case any of these functions is used in an pysb.Expression.

@codecov-io
Copy link

codecov-io commented Dec 31, 2020

Codecov Report

Merging #518 (2dfc357) into master (cc94061) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #518   +/-   ##
=======================================
  Coverage   80.27%   80.27%           
=======================================
  Files         101      101           
  Lines       10664    10668    +4     
=======================================
+ Hits         8560     8564    +4     
  Misses       2104     2104           
Impacted Files Coverage Δ
pysb/export/pysb_flat.py 92.68% <100.00%> (+0.57%) ⬆️
pysb/importers/bngl.py 93.01% <100.00%> (+0.02%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update cc94061...2dfc357. Read the comment docs.

@@ -42,7 +70,7 @@ def __init__(self, filename, force=False, cleanup=True):

self.model.name = os.path.splitext(os.path.basename(filename))[0]
self._force = force
self._model_env = {}
self._model_env = BNGL_FUNCTIONS
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is enumerating the functions like this necessary? It seems to work on current master branch already. Here's a test program:

from pysb.importers.bngl import model_from_bngl
import tempfile

bngl_test = """
begin seed species
  A 100
  B 100
end seed species

begin reaction rules
  A() + B() <-> C() 0.01, 1
end reaction rules

# not used in model, only for import tests
begin functions
  f1() = exp(10)
  f2() = atanh(10)
  f3() = sqrt(log2(50))
end functions
"""

with tempfile.NamedTemporaryFile('w', suffix='.bngl', encoding='utf8') as tf:
    tf.write(bngl_test)
    tf.flush()
    model = model_from_bngl(tf.name)

print(model)

for expr in model.expressions:
    print(f'{expr.name}: {expr.expr.evalf()}')

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's been a while since I wrote that code, so I am not sure. I am surprised that log2 actually works, since this definitely used to require the mapping. This might be due to recent changes by @jmuhlich or sympy added log10 and log2 functions function.

@codecov-commenter
Copy link

Codecov Report

Merging #518 (1d18513) into master (85b6c8a) will increase coverage by 0.08%.
The diff coverage is 100.00%.

❗ Current head 1d18513 differs from pull request most recent head dd4b5d4. Consider uploading reports for the commit dd4b5d4 to get more accurate results

@@            Coverage Diff             @@
##           master     #518      +/-   ##
==========================================
+ Coverage   80.16%   80.25%   +0.08%     
==========================================
  Files         100      101       +1     
  Lines       10650    10717      +67     
==========================================
+ Hits         8538     8601      +63     
- Misses       2112     2116       +4     
Impacted Files Coverage Δ
pysb/export/pysb_flat.py 92.10% <100.00%> (+0.92%) ⬆️
pysb/importers/bngl.py 93.01% <100.00%> (+0.05%) ⬆️
pysb/core.py 88.72% <0.00%> (ø)
pysb/export/__init__.py 96.00% <0.00%> (ø)
pysb/tools/render_reactions.py 16.84% <0.00%> (ø)
pysb/export/python.py 93.22% <0.00%> (ø)
pysb/tests/test_exporters.py 94.50% <0.00%> (+0.12%) ⬆️

📣 Codecov can now indicate which changes are the most critical in Pull Requests. Learn more

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants