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

Offen
#993 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Anfängerfreundlichkeit
25/100
Issue-Typ
Bug
Klarheit
Größtenteils klar
Aktivitätsstatus
Aktiv
Tech-Stack
python
Bereich
backend

Rechercherichtung

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.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

_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 -- ...
Vorherrschende Sprache
Python
Sterne
25
Forks
25
Ø Merge
4 Std. 5 Min.
Gemergte PRs (30 T.)
10

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus lanl/PyBNF

Alle Issues in lanl/PyBNF

Ähnliche Issues

Weitere Issues zu Python

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.