Repository navigation
net loader: a value that is a declared parameter's name is that parameter, also where the name reads as a number (#1856) - #2143
Merged
Conversation
…eter, also where the name reads as a number (lanl#1856) BNG2.pl takes a parameter named inf, nan or Infinity and writes the name for a parameter or a seed species set to it alone. The loader tried the text as a number first, and strtod reads those words as infinity or NaN: k2 and B(0) were infinite where BNG2.pl holds 5, and k4 = 1/k2 a silent 0. Both sites read a declared parameter's name as the parameter. Signed-off-by: Montana <montana@linux.com>
…ue, and in the check of a .net against its .bngl
k2 -inf stayed -infinity; setParameter("k2","inf") set infinity under
run_bngl; net_to_omex(bngl=) refused BNG2.pl's own network for k2 nan.
Signed-off-by: Montana <montana@linux.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1856
BNG2.pl accepts a parameter named
inf,nanorInfinity, and writes the name into the.netfor a parameter or a seed species set to it alone (k2 inf,2 B() inf). The loader tried the text as a number before it tried it as a name, andstrtodreads those words, in any case, as infinity or NaN. So k2 and B(0) were infinite where BNG2.pl holds the parameter's 5, andk4 1/k2was 0 with nothing said.A value that is a declared parameter's name is now read as that parameter.
The issue's model (
inf 5,k2 inf,k3 2*inf,k4 1/k2,B() inf,A() -> B() k4from A = 100), throughModel.from_neton BNG2.pl 2.9.3's.net:infnanInfinitytrue,qThe word beside no parameter of that name is still the number it was (
k2 infwith no parameterinfis infinity), and so is one in another case than the parameter's (INFbesideinf), since BNGL names are case-sensitive.Important
#2139 and #2140 touch
convert/__init__.pyand_bngl_loader.pyin other hunks: this branch merges clean with each, in either order.The diff (abridged)
src/net_file_loader.cppParameters: after the whole block is read, since the name may be declared further down. A value that is another parameter's name, bare or under one sign, is an expression, as
k2 qalways was.Seed species: a declared name is looked up before the text is tried as a number. Under a sign it goes the way an expression-valued concentration already does.
python/bngsim/convert/_protocol.pyAn action's quoted value:
setParameter("k2","inf")keeps the text, which the model evaluates.python/bngsim/_bngl_loader.pyWhere the model has no parameter of that name, the text is the number it was read as before.
python/bngsim/convert/__init__.pyThe check that a
.netis the network its.bnglgenerates, at its threefloat(declared_text)reads.Review
One round of a whole-branch
/code-reviewonbbfe233e, at high effort, to the bar in "How much to review". The change as written came back clean; the round found the same reading in three neighbouring paths, each reproduced against BNG2.pl. All three are fixed in1f310f98, and I read that commit's diff once more and stopped.k2 -inf,k3 +inf,k5 -nan; the loader gave -inf, inf, nan for BNG2.pl's -5, 5, -3, andk4 -1/k2was 0.test_a_signed_name_is_the_parameter_toosetParameter("k2","inf")andsetConcentration("B()","inf")beside a parameterinfset infinity underrun_bngl(Atot, Btot = 100, inf for BNG2.pl's 81.873, 23.127).test_an_action_that_sets_such_a_word_keeps_it_as_text,test_run_bngl_sets_the_parameters_valuenet_to_omex(net, out, bngl=...)refused BNG2.pl's own network fork2 nan("parameter k2 is 5 there, nan as declared").test_net_to_omex_takes_the_network_its_bngl_generatesThe round also ran a model with the parameter named
inf,nan,Infinity,NaNorINFagainst the same model namedq: values, right-hand side, Jacobian, ODE with and without codegen, forward sensitivities (also against finite differences),set_paramwithclone, SSA, and NFsim and RuleMonkey on the BNG-XML all agree.Left alone
inf nanandnan inf, is now refused as a reference cycle, where it loaded as infinity and NaN. BNG2.pl refuses the pair too ("Parameter nan has a dependency cycle nan->inf->nan").setParameter("k2","inf")with no parameter namedinfsets infinity, as it did.Testing
python/tests/test_net_number_word_names.py, new, on1f310f98: 53 cases. Without BNG2.pl 38 run and 15 skip. On main's build with BNG2.pl: 28 failed, 25 passed. Here: 53 passed. The 25 that pass on main are the controls: names that are not such words (true,q), the word with no parameter of that name, numbers, and an action that sets a number.How this was checked
1f310f98(main at44e51182), macOS arm64, Python 3.13,uv sync --extra testplus h5py,BNGPATHat BioNetGen 2.9.3: 26707 passed, 547 skipped, 151 xfailed, 1 failed. The failure istest_run_tests_sh.py::test_the_script_itself_runs_walk_up_dependent_tests_green, which fails the same way on main in this environment (it counts skips for jax, diffrax, roadrunner and vivarium, which thetestextra does not install).mutate.pyfrom bngsim-preflights) on1f310f98: 8 of 8 killed: 5 that rebuild the extension (a parameter's value not checked against the names, its own name read as a reference, a species' name tried as a number first, either sign not stripped) and 3 in Python (an action's word read as a float, no fallback to the number, the.bnglcheck reading a name as a float). The test file is green on the rebuilt original.Model.from_netonbenchmarks/models/net/ode/fceri_gamma.net(62,061 lines), medians of 7 loads, five runs a side, sides alternated: main 121 to 138 ms, here 122 to 134 ms. The change is one hash lookup per parameter and per seed species.pre-commit run --all-files,ci/changelog.py check: pass.bngsim_docker.py test --merge-main --kind bionetgen, amd64 under emulation, which builds the C++ there):1f310f98merged with main44e51182,test_net_number_word_names.py,test_bngl_protocol.pyandtest_protocol_run.py: 159 passed. All 53 of this PR's cases pass there..bnglthe repository tracks, its actions parsed by main's package and by this one (writer_ab.py): 978 of 978 protocols identical, as written back to BNGL, as network actions and as SED-ML (851 of 851). No tracked file sets such a word in an action.prepr_check.pyfrom bngsim-preflights) on1f310f98with this description: 0 failed, 8 warnings, 37 passed. The warnings: convert: a compartment size the SBML model refuses to change is left out or marked, like a frozen parameter (#1992) #2139 and bngl: a folded_at_load= comment is read off the declaration BNG2.pl reads (#1994) #2140 on the same files (above); the CI legs that fire; lists of callers and of sites that name the changed functions, to read (read:_valuereturns something new only for a text that is one of these words and does not evaluate in the model, where it returned None); code changed after the reviewed commit (described under Review); the Linux run covers this PR's file and the two protocol files, not every file withnamesornumberin its name (CI's legs run them all); claims to recount.benchmarks/perf_ab.py(it times runs; the loader's cost is measured above).