Skip to content

bngl: warn when a source's first run starts from a state from_bngl drops (#1366) - #1388

Open
Montana wants to merge 2 commits into
lanl:mainfrom
Montana:fix/1366-warn-dropped-state-changes
Open

Montana wants to merge 2 commits into
lanl:mainfrom
Montana:fix/1366-warn-dropped-state-changes

Conversation

@Montana

@Montana Montana commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Addresses #1366, items 1, 3 and 4. Item 2, replaying the protocols in the suites, is a maintainers' call and needs #1364 (#1377) first, so it is not in this PR.

What #1366 asks, and what this does

Model.from_bngl drops a BNGL file's actions after generate_network as the author's experiment (intended, documented). The issue asks whether loading such a file should say so when it matters (3), whether the docs describe it right (4), and whether the benchmark READMEs should say what the suites simulate (1).

3, the warning. A ConversionWarning now names the dropped actions that set a parameter or a concentration the first simulate or parameter_scan starts from, where the loaded model holds another value.

  • The text scan (_bngl_loader.state_changes_before_first_run):
    • starts at the first generate_network, where generation_source cuts;
    • stops at the first run;
    • follows save/resetConcentrations and save/resetParameters as BNG2.pl does.
  • Each change it finds is then judged against the loaded network (dropped_state_changes):
    • a setParameter to the parameter's own value is not named;
    • nor is a setConcentration to the species' own amount, the value evaluated in the model's own arithmetic, so "Ag_tot_1" compares as the number it is;
    • nor is an addConcentration of 0;
    • an effect it cannot read, such as a pattern the network does not name, is named rather than kept quiet.
  • protocol=True returns the actions instead, without the warning.

Why the second step. The text scan alone flags 95 of the repo's 1,068 .bngl files. Of the 94 that load, 53 set everything to what the model already holds: setConcentration("Ag(DNP)","Ag_tot_1") on a species seeded with Ag_tot_1, setParameter("ART",0) on an ART declared 0. A warning on those would be wrong more often than right. The 41 that warn hold 56 actions that change a value by the model's own numbers. Five of them are species written with their components in another order than the network's canonical name (LPS(MD2,TLR4,CD14,LPS) for LPS(CD14,LPS,MD2,TLR4)), which the check matches.

This corrects the issue's table. Two of the six "first simulated state differs" files do not differ:

  • egfr_path declares EGF 0, so its setConcentration("EGF",0) is a no-op. The run that matters is the opposite: it adds EGF_tot only after equilibrating, so the ODE suite's 120 s egfr_path run has no ligand. 3 of its 18 species move (Grb2 and Sos settle); with EGF_tot added, all 18 do.
  • mwc declares coopRT and coopB 0, the values its actions set.
  • egfr_net_red (egf(r) 0 before equilibrating) and wofsy_goldstein (alpha 0.01 → 0.1; its beta is already 0.01) do differ, and warn.

4, the docs. loading-models.md and the from_bngl docstring said only generate_network runs. Actions before it are applied, as BNG2.pl applies them, except runs and file writes. Both now say so, and describe the warning.

1, the benchmark README. A paragraph in benchmarks/README.md's Benchmarking section says the suites run each network from its seed state over the suite's horizon, not the published protocol. It explains why parity and timing still compare like with like, and gives the egfr_path case.

Tests (test_bngl_dropped_state_changes.py, 19)

test what it holds
the scan (9) a change before the first run is found; one before generation is applied, not dropped; one between two generation calls is dropped too; one after the first run is a later phase; save-then-reset changes nothing; a reset undoes a change after the save and keeps one before it; no run, or no generation, is nothing to say
against a network (7, on a hand-written .net, no BNG2.pl) addConcentration of 5 is named; controls, not named: a parameter to its value, a species to its amount, to the expression it was seeded from, with its components in another order, adding 0; only the changing actions are named; an unnamed species counts as a change
through from_bngl (3, need BNG2.pl) a change the model does not hold warns, naming each action and protocol=True; protocol=True does not warn; wofsy_goldstein warns on alpha and not beta, and egfr_path does not warn

Before this PR, from_bngl gave no warning at all, so each test that expects one fails on main (K1 below).

Mutations

mutant fails
K1: no warning 3
K2 / K3: no no-op check for species / parameters 4 / 3
K4: resetConcentrations ignored the reset-undoes test
K5: scan from the last generation call the between-two-calls test
K6: scan every phase, not up to the first run 6
K7: components matched only in source order the other-order control
K8: the save shares the live list the reset-undoes test
K9: addConcentration never named the adding test

Measured

  • The corpus: of the repo's 1,068 .bngl files, the scan flags 95. 94 of those load (one generates no network), and 41 warn. In benchmarks/models/bngl (103 files), 3 warn: both egfr_net_red and wofsy_goldstein.
  • In the suite: the one new warning is test_loads_a_corpus_model_and_simulates loading egfr_net_red.bngl, a true one.
  • Full suite: 16,462 passed, 137 skipped. pre-commit run --all-files (new files staged) and sphinx -W are clean.

…ops (lanl#1366)

The actions after a BNGL file's generate_network are dropped as the author's
experiment. When some of them set a parameter or a concentration the first
simulate or parameter_scan starts from, and the loaded model holds another
value, a ConversionWarning now names them. The scan follows save/reset as
BNG2.pl does; each change is judged in the model's own arithmetic, so a
setConcentration to the species' declared amount is not named. The loading
docs and from_bngl docstring now say which actions before generate_network
apply, and the benchmark README says the suites run each network from its
seed state, not the published protocol.
…d no BNG2.pl (lanl#1366)

On a runner without BioNetGen the twelve network tests skipped, and took the
Ubuntu leg's skip count past its ceiling (227 > 225). The judging needs only a
network: a hand-written .net of the same model serves. The three tests that
go through from_bngl itself still need BNG2.pl.

This branch has not been deployed

No deployments
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.

1 participant