On the bngsim SBML backend, a free parameter that feeds a chain of parameter initialAssignments (k2 := 2*k1, k3 := k2 + k1) is refused on the gradient path, although bngsim's own column for it is exact
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 25/100
Research direction
Start with _seed_terms in pybnf/gradient/routing.py, where a seed map entry of None causes the refusal, and check how it treats parameters that bngsim reports as live derived parameters. The reproduction script in the issue (repro.py with nested.xml) shows the refusal and the exact bngsim column to compare against. Done means route_for_model(['k1']) succeeds for the chain k2 := 2*k1, k3 := k2 + k1 while still refusing when a chain member is not live. The issue depends on the unmerged #991, so check that PR first.
Written by the indexing model from the issue text.
Description
_seed_terms (pybnf/gradient/routing.py:570 on main, :598 at #991's head 213e28ae) refuses a free parameter whose seed map entry is None. The SBML seed map gives None when a parameter reaches another entity's initial value through a second initialAssignment. So a plain chain of derived parameters is refused: k2 := 2*k1, k3 := k2 + k1, with k1 fitted and the rate laws reading all three.
That refusal is no longer needed on any supported bngsim. bngsim 0.16.0 and bngsim main both report k2 and k3 as live derived parameters (param_is_expression), and k1's own sensitivity column already carries the whole chain: dS(2)/dk1 = −302.805 from bngsim against a central difference of −302.80502. #991 routes on exactly that report: a seed onto a live derived parameter is dropped and the input's own column is used. A chain whose every member is live needs no seed composition at all.
The refusal's message is also wrong for this case. It says "Condition sets 'k1'", but no condition is involved; k1 is a free parameter. The wording is being fixed in #991. This issue is about refusing a configuration that bngsim differentiates correctly.
Failure scenario
job_type = lbfgs (or any gradient job type) with sbml_backend = bngsim, the model below, and k1 free. The run stops at load with GradientNotSupported. A gradient-free job type fits it, and the gradient bngsim would supply is exact.
Expected: route k1 to its own parameter column when bngsim reports every derived parameter on the chain as live, and refuse only when one is not live, or when a member of the chain also seeds a species the backend does not report seeding (effective_ic_sensitivity).
Reproduction
nested.xml:
<?xml version="1.0" encoding="UTF-8"?>
<sbml xmlns="http://www.sbml.org/sbml/level3/version1/core" level="3" version="1">
<model id="m">
<listOfCompartments><compartment id="c" size="1" constant="true"/></listOfCompartments>
<listOfSpecies>
<species id="S" compartment="c" initialConcentration="100.0" hasOnlySubstanceUnits="false" boundaryCondition="false" constant="false"/>
<species id="T" compartment="c" initialConcentration="50.0" hasOnlySubstanceUnits="false" boundaryCondition="false" constant="false"/>
</listOfSpecies>
<listOfParameters>
<parameter id="k1" value="0.1" constant="true"/>
<parameter id="k2" value="0.0" constant="true"/>
<parameter id="k3" value="0.0" constant="true"/>
</listOfParameters>
<listOfInitialAssignments>
<initialAssignment symbol="k2"><math xmlns="http://www.w3.org/1998/Math/MathML"><apply><times/><cn>2.0</cn><ci>k1</ci></apply></math></initialAssignment>
<initialAssignment symbol="k3"><math xmlns="http://www.w3.org/1998/Math/MathML"><apply><plus/><ci>k2</ci><ci>k1</ci></apply></math></initialAssignment>
</listOfInitialAssignments>
<listOfReactions>
<reaction id="d1" reversible="false" fast="false">
<listOfReactants><speciesReference species="S" stoichiometry="1" constant="true"/></listOfReactants>
<kineticLaw><math xmlns="http://www.w3.org/1998/Math/MathML"><apply><times/><ci>c</ci><ci>k3</ci><ci>S</ci></apply></math></kineticLaw>
</reaction>
<reaction id="d2" reversible="false" fast="false">
<listOfReactants><speciesReference species="T" stoichiometry="1" constant="true"/></listOfReactants>
<kineticLaw><math xmlns="http://www.w3.org/1998/Math/MathML"><apply><divide/><apply><times/><ci>k2</ci><ci>T</ci></apply><apply><plus/><cn>1.0</cn><apply><times/><cn>0.01</cn><ci>T</ci></apply></apply></apply></math></kineticLaw>
</reaction>
<reaction id="d3" reversible="false" fast="false">
<listOfReactants><speciesReference species="T" stoichiometry="1" constant="true"/></listOfReactants>
<listOfProducts><speciesReference species="S" stoichiometry="1" constant="true"/></listOfProducts>
<kineticLaw><math xmlns="http://www.w3.org/1998/Math/MathML"><apply><times/><ci>k1</ci><ci>T</ci></apply></math></kineticLaw>
</reaction>
</listOfReactions>
</model>
</sbml>```
`repro.py` (run as `python repro.py nested.xml`):
```python
"""k1 feeds k2 := 2*k1 and k3 := k2 + k1. bngsim's own k1 column is exact; PyBNF refuses."""
import sys
import numpy as np
import bngsim
import pybnf.bngsim_sbml_model as sb
from pybnf.gradient import route_for_model
from pybnf.pset import FreeParameter, PSet, TimeCourse
path = sys.argv[1] # nested.xml below
def s_at_2(k1, sens=False):
model = bngsim.Model.from_sbml(path)
model.set_param('k1', k1)
kwargs = {'sensitivity_params': ['k1']} if sens else {}
result = bngsim.Simulator(model, method='ode', **kwargs).run(t_span=(0, 2), n_points=3)
if sens:
return np.asarray(result.output_sensitivities(['species:S'], axis='parameter')).ravel()[-1]
return np.asarray(result.species)[-1, list(result.species_names).index('S')]
model = bngsim.Model.from_sbml(path)
live = dict(zip(model.param_names, model.param_is_expression))
print('live derived parameters: k2 %s, k3 %s' % (live['k2'], live['k3']))
h = 1e-6
print('dS(2)/dk1: bngsim column %.8g, central difference %.8g'
% (s_at_2(0.1, sens=True), (s_at_2(0.1 + h) - s_at_2(0.1 - h)) / (2 * h)))
pset = PSet([FreeParameter('k1', 'uniform_var', 1e-6, 1e6, value=0.1)])
pybnf_model = sb.BngsimSbmlModelNoTimeout(path, path, pset=pset,
actions=(TimeCourse({'time': '2', 'step': '1'}),))
try:
route_for_model(pybnf_model, ['k1'])
print('PyBNF routed k1')
except Exception as exc:
print('PyBNF: %s: %s' % (type(exc).__name__, str(exc)[:160]))
Output, identical on bngsim 0.16.0 and bngsim main (c966928), with PyBNF at main (05c16fdb, unchanged in f5ff92bf) and at #991's head (213e28ae):
live derived parameters: k2 True, k3 True
dS(2)/dk1: bngsim column -302.805, central difference -302.80502
PyBNF: GradientNotSupported: Condition sets 'k1', which seeds another entity's initial value through an expression the gradient path cannot differentiate -- ...
- Dominant language
- Python
- Stars
- 25
- Forks
- 25
- Avg merge
- 4h 5m
- Merged PRs (30d)
- 10
Getting set up
- Ships a Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from lanl/PyBNF
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 1 day
-
bug minor
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 1 day
-
bug tech debt
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day
-
bug minor
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
Maintainers usually reply within 1 day
-
bug silent-incorrectness
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 1 day
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
software-mansion-labs/Diplomat#20 ·
Maintainers usually reply within 1 day
-
[Windows] Hidden title bar: a maximized window restored from minimized on a secondary monitor gets the primary monitor's work area as its client areaPossibly taken @lijy91 claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 67/100
libnativeapi/nativeapi#53 · 1 reaction ·
Maintainers usually reply within 1 day
-
View Counts discarded due to field name mismatchPossibly taken @rsiva0400 claimed this today. Opensite-bug triage
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
Model version publishes the new UK firm entity as a personPossibly taken @vahid-ahmadi claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
PolicyEngine/policyengine.py#764 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
spcl/HPCAgent-Bench#264 ·
Maintainers usually reply within 1 day