A setOption written after generate_network is applied by a PyBNF fit but ignored by BNG2.pl, so PyBNF fits a different model from the one in the file

未关闭
#981 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
5/5
预计耗时
一周以上
新手友好度
35/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
活跃
技术栈
python
领域
tooling

调研方向

Start with BNGLModel.__init__ and model_text() in pybnf/pset.py, then compare how the scanner handles setOption with the model text PyBNF generates. The issue lays out three possible behaviors but says a decision is needed, so first resolve that policy with the maintainers. Done means the chosen behavior is consistent between PyBNF and BNG2.pl and the reported ordering case is covered.

由索引模型根据 Issue 内容生成。

描述

bug silent-incorrectness

What the user writes. A BNGL model whose actions call generate_network first and setOption after it:

begin actions
generate_network({overwrite=>1})
setOption("MoleculesObservables","CountUnique")
simulate({method=>"ode",t_end=>4,n_steps=>4,suffix=>"tc"})
end actions

What happens. BNG2.pl applies the option only to a network generated after the setOption call. Run directly with BNG2.pl, this file counts its observables under the default rule (CountAll): the option comes too late and does nothing, and BNG2.pl prints no warning. PyBNF takes every setOption line out of the actions and puts it ahead of the actions block in the model text it simulates. So in a PyBNF fit the option does apply. The same file is two different models, depending on which program runs it, and neither program says so.

Consequence. In the example below the observable differs by a factor of two. A user who fits with PyBNF and then runs the best-fit parameters through BNG2.pl on their own file gets curves that do not match the fit.

What should happen. This needs a decision. The options I see:

  1. Refuse the file at load, in every edition (my recommendation). The message names the line and says that BNG2.pl does not apply a setOption that follows generate_network, and to move it ahead. The user's intent is then unambiguous, and both programs agree.
  2. Keep the user's order in the model text, so PyBNF matches BNG2.pl. Existing jobs written this way would change their results without notice.
  3. Leave the behaviour and document it.

Example

A dimer that decays at rate k = 0.5. Its observable pattern matches each dimer twice, so CountAll reports 100 e^(-kt) and CountUnique reports 50 e^(-kt).

begin model
begin parameters
k 0.5
end parameters
begin molecule types
A(a)
end molecule types
begin seed species
A(a!1).A(a!1) 50
end seed species
begin observables
Molecules D A(a!1).A(a!1)
end observables
begin reaction rules
A(a!1).A(a!1) -> 0 k
end reaction rules
end model

All four rows were run with BNG2.pl 2.9.3:

Model text D at t = 0 D at t = 1
The file as written (setOption after generate_network) 100 60.65
The file with no setOption 100 60.65
The file with setOption moved ahead of generate_network 50 30.33
The text PyBNF writes for the file as written (BNGLModel.model_text(), with k fitted and set to 0.5) 50 30.33

The tail of the text PyBNF writes:

end model
setOption("MoleculesObservables","CountUnique")
begin actions

generate_network({overwrite=>1})
simulate({method=>"ode",t_end=>4,n_steps=>4,suffix=>"tc"})
end actions

Scope

  • Editions. The example is an edition-1 model, with its own simulate. In edition 2, a model with generate_network then setOption and no other action passes the actions check (#969).
  • PEtab export. For that edition-2 model the export also writes the setOption ahead of begin actions. The exported model agrees with the fit, and both disagree with the file.
  • Backends. I ran BNG2.pl on PyBNF's model text. The bngsim backends take their network from BNG2.pl run on the same text, so I expect the same there, but I did not run them.
  • Options. Only MoleculesObservables was tested.

Where

BNGLModel.__init__ in pybnf/pset.py. The scanner keeps the setOption family (setOption, substanceUnits, version) in the model lines wherever they were written, and treats the other lines as actions. model_text() writes the model lines first and its own begin actions block, with generate_network, after them.

Found by the second review of #975. The behaviour is older than that PR.

主要语言
Python
星标
25
派生
25
平均合并
4 小时 5 分钟
30 天内合并 PR
10

环境准备

  • 提供 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

lanl/PyBNF 的其他 Issue

查看 lanl/PyBNF 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。