Skip to content

parse_bngl_protocol drops saveParameters/resetParameters silently, so a ProtocolSpec keeps a setParameter that BNG2.pl reset #1478

Closed

Description

@wshlavacek

What happens

parse_bngl_protocol, and with it Model.from_bngl(..., protocol=True), lists saveParameters and resetParameters among the pure build/IO directives (_BUILD_VERBS, python/bngsim/convert/_protocol.py:110-111). The comment there says none of them "alters the trajectory a consumer would compute". So both are recorded in spec.dropped and otherwise ignored: no warning, nothing in spec.lossy, and strict=True accepts them too.

But resetParameters() puts every constant parameter back to the values saveParameters() saved (BioNetGen 2.9.3, Perl2/BNGModel.pm, resetParameters). A setParameter between the two is undone before the next run, and the spec keeps it.

Repro

begin model
begin parameters
  k 1
end parameters
begin molecule types
  A(b)
end molecule types
begin seed species
  A(b) 100
end seed species
begin observables
  Molecules Atot A()
end observables
begin reaction rules
  A(b) -> 0 k
end reaction rules
end model
generate_network({overwrite=>1})
saveParameters()
setParameter("k",2)
resetParameters()
simulate({method=>"ode",t_end=>1,n_steps=>1})
spec = bngsim.convert.parse_bngl_protocol("m.bngl", strict=False)
spec.steps    # set_parameter k=2.0, then the simulate
spec.dropped  # ('generate_network', 'saveParameters', 'resetParameters')
spec.lossy    # ()

No warning is raised, with or without strict. BNG2.pl, run on the same file, prints Reloaded parameters saved with label 'DEFAULT', writes k 1 into the .net it runs, and reports Atot 36.79 at t=1 (100·e⁻¹). Replaying the spec runs with k=2, which gives 13.53 (100·e⁻²).

In the corpus

18 of the 1,070 tracked .bngl files use saveParameters/resetParameters. In 4 of them, a setParameter falls between a save and a reset that comes before a later run, so the spec is wrong for that run:

  • parity_checks/bng_parity/models/slow/rulehub/Published/Lin2019/TCR_model.bngl
  • parity_checks/bng_parity/models/glacial/rulehub/Published/Lin2019/ERK_model.bngl
  • parity_checks/bng_parity/models/glacial/rulehub/Published/Lin2019/prion_model.bngl
  • parity_checks/bng_parity/models/slow/rulehub/Published/Salazar-Cavazos2019/190127_CHO_EGFR_best-fit.bngl

In TCR_model.bngl, setParameter("lambda",0.1) precedes the std_scaling run, and resetParameters() follows it. The spec runs partial_scaling with lambda 0.1, where BNG2.pl runs it with the declared 1.

None of the 14 models #1366 lists uses either verb, so this does not affect that issue's models.

Who reads the spec

Fix directions

  1. Carry them. Add save_parameters/reset_parameters StateChange kinds with labels, as save_concentrations/reset_concentrations already have (issue Named saved concentration states + reset_conc-to-snapshot scan (parameter_scan/bifurcate after pre-equilibration) #11), and have the consumers apply them.
  2. At least, flag them. Treat them as lossy, so a non-strict parse warns and records them in spec.lossy, and strict=True refuses. Refusing only when a setParameter falls between a save and its reset would leave alone the 14 files where the pair changes nothing.

Related: addConcentration and bifurcate are not carried either, but the parser does warn about them ("unrecognized BNGL action").

Found while reviewing #1388 (issue #1366).

Activity

  1. added
    bugSomething isn't working
    correctness concernProduces plausible-looking wrong results with no error: the failure is silent, not loud
    on Nov 3, 2026
  2. added a commit that references this issue on Nov 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingcorrectness concernProduces plausible-looking wrong results with no error: the failure is silent, not loud

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions