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

Local function support #412

Merged
merged 12 commits into from Sep 25, 2019

Conversation

@alubbock
Copy link
Member

alubbock commented Feb 4, 2019

Local functions are defined are mathematical rate law expressions which are evaluated separately for every molecular instance. This can greatly reduce the number of expressions required in a model.

See Sneddon et al. for further details and a motivating example.

The PR adds a new core construct, pysb.core.Tag and operator @ for adding tags. Here is an example model automatically converted from BioNetGen's localfunc.bngl example:

from pysb import Model, Monomer, Parameter, Expression, Compartment, Rule, Observable, Initial, MatchOnce, Annotation, Tag, ANY, WILD

Model()

Monomer('A', ['b', 'b', 'b'])
Monomer('B', ['a'])
Monomer('C')
Monomer('Trash')

Parameter('kp', 0.5)
Parameter('km', 0.1)
Parameter('k_synthC', 0.5)
Parameter('k_degrC', 0.5)
Parameter('Ab_b_b_0', 1.0)
Parameter('Ba_0', 3.0)
Parameter('C_0', 0.0)
Parameter('_Trash_0', 0.0)

Observable('Atot', A())
Observable('Btot', B())
Observable('Ctot', C())
Observable('AB0', A(b=MultiState(None, None, None)), match='species')
Observable('AB1', A(b=MultiState(1, None, None)) % B(a=1), match='species')
Observable('AB2', A(b=MultiState(1, 2, None)) % B(a=1) % B(a=2), match='species')
Observable('AB3', A(b=MultiState(1, 2, 3)) % B(a=1) % B(a=2) % B(a=3), match='species')
Observable('AB_motif', A(b=1) % B(a=1))

Tag('x')

Expression('f_synth', k_synthC*AB_motif(x)**2)
Expression('_rateLaw1', f_synth(x))

Rule('_R1', A() @ x >> A() @ x + C(), _rateLaw1)
Rule('_R2', A(b=None) + B(a=None) | A(b=1) % B(a=1), kp, km)
Rule('_R3', C() >> Trash(), k_degrC)

Initial(A(b=MultiState(None, None, None)), Ab_b_b_0)
Initial(B(a=None), Ba_0)
Initial(C(), C_0)
Initial(Trash(), _Trash_0, fixed=True)

Note that x has been defined as a tag, and the expression f_synth and rule _R1 are dependent on that tag.

@coveralls

This comment has been minimized.

Copy link

coveralls commented Feb 4, 2019

Coverage Status

Coverage increased (+0.9%) to 79.52% when pulling 3753cdf on alubbock:localfxns into 4f9f4a1 on pysb:master.

Copy link
Member

jmuhlich left a comment

Sorry for the delay in getting to this. Incidentally, the energy-BNG framework introduces derived expressions as well, but I think you handled it better here than I did in my energy branch. Looking forward to getting this merged.

pysb/bng.py Outdated Show resolved Hide resolved
pysb/bng.py Outdated Show resolved Hide resolved
pysb/bng.py Outdated Show resolved Hide resolved
pysb/bng.py Outdated Show resolved Hide resolved
pysb/bng.py Outdated Show resolved Hide resolved
pysb/core.py Show resolved Hide resolved
pysb/importers/bngl.py Outdated Show resolved Hide resolved
pysb/importers/bngl.py Outdated Show resolved Hide resolved
pysb/importers/bngl.py Outdated Show resolved Hide resolved
pysb/importers/bngl.py Show resolved Hide resolved
@codecov-io

This comment has been minimized.

Copy link

codecov-io commented Sep 23, 2019

Codecov Report

Merging #412 into master will increase coverage by 0.21%.
The diff coverage is 89.72%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #412      +/-   ##
==========================================
+ Coverage   79.44%   79.65%   +0.21%     
==========================================
  Files          96       96              
  Lines        9677     9901     +224     
==========================================
+ Hits         7688     7887     +199     
- Misses       1989     2014      +25
Impacted Files Coverage Δ
pysb/__init__.py 76.92% <ø> (ø) ⬆️
pysb/generator/bng.py 96.77% <100%> (+0.14%) ⬆️
pysb/tests/test_bng.py 100% <100%> (ø) ⬆️
pysb/builder.py 88% <100%> (+1.04%) ⬆️
pysb/tests/test_importers.py 97.19% <100%> (+0.72%) ⬆️
pysb/export/pysb_flat.py 92.1% <100%> (+0.21%) ⬆️
pysb/simulator/bng.py 91.07% <100%> (ø) ⬆️
pysb/tests/test_core.py 95.45% <100%> (+0.26%) ⬆️
pysb/simulator/scipyode.py 89.41% <57.14%> (-0.79%) ⬇️
pysb/bng.py 91.94% <80%> (-1.27%) ⬇️
... and 3 more

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 8da0009...fae6906. Read the comment docs.

@jmuhlich

This comment has been minimized.

Copy link
Member

jmuhlich commented Sep 25, 2019

Thanks!

@alubbock alubbock merged commit 9a552c8 into pysb:master Sep 25, 2019
2 checks passed
2 checks passed
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@alubbock alubbock deleted the alubbock:localfxns branch Sep 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.