Repository navigation
convert: the simulate actions sbml_to_bngl writes for a model's events name their tolerances (#1830) - #2145
Merged
Conversation
…s name their tolerances (lanl#1830) BNG2.pl runs a simulate that names no atol at 1e-8, above the species of a model in molar units: BIOMD0000000571's actions ran with 57 of 76 species over 1e-4 of their peak off the SBML, under a report that listed nothing lost. Each phase now names rtol 1e-8 and an atol of rtol times the smallest value an integrated species starts from or an event sets it to, floored at 1e-6 of the largest and never above 1e-8. sbml_to_net's note for dropped events names sbml_to_bngl. Signed-off-by: Montana <montana@linux.com>
…cies that all start at 0 take a fixed species' scale A rate constant the loader holds as a species lifted the floor to 1e-6 of itself (atol 1e-8 beside species at 1e-9), and a model whose integrated species all start at 0 beside a boundary stimulus at 1e-9 kept 1e-8. Signed-off-by: Montana <montana@linux.com>
…k, and a catalyst gives no scale pytest.approx's default absolute tolerance of 1e-12 passed any atol under it: three mutants survived. Signed-off-by: Montana <montana@linux.com>
… every species, as Simulator.run does MODEL7743528808's species start at 0 beside fixed species of order 1; the parameter its event sets is the only small scale the model holds. Signed-off-by: Montana <montana@linux.com>
…ves no scale The one mutant left alive: a fixed species counted among those that change. 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 #1830
sbml_to_bnglwrites a model's fixed-time events assimulatephases, and wrote them with no tolerances. BNG2.pl then runs them at its ownatol = 1e-8, which is above the species of a model in molar units. BIOMD0000000571 converts withok=Trueand nothing listed as lost, and BNG2.pl runs the result with 57 of its 76 species over 1e-4 of their peak off the SBML.Each phase now names
rtoland anatoltaken from the scale of the model's species.(BNG2.pl 2.9.3,
t_span=(0, 1000), 201 points, every output time but the event's; bngsim on the SBML atrtol=1e-10, atol=1e-14.)The rule, since BNG2.pl takes one
atolfor every species:atolwrittenrtoltimes the smallest such value, but not under 1e-6 of the largest, and never above1e-08$-fixed ones and the parameters an event sets)1e-08, what BNG2.pl ran it at beforeIt is the floor of the default
Simulator.runderives per species (#1420).rtolis written as1e-08, BNG2.pl's own.Important
This closes the wrong result the issue is titled for, and its third point (
sbml_to_net's note for dropped events named a SED-ML sidecar; it now namessbml_to_bngl). The issue's other two asks are features and are not here: asedml=argument, and an actions block for an event-free model. They need an issue of their own before this one closes.#2139 and #2140 touch the same files (
convert/__init__.py,_net_writer.py,interchange.md) in other hunks: this branch merges clean with each, in either order.The diff (abridged)
python/bngsim/convert/_events.pyThe scale. A species nothing changes gives none: the loader holds a parameter an event sets as such a species, and a rate constant is not a concentration.
Every phase carries them, in the
extraarguments the writer already emits and the reader already keeps.python/bngsim/convert/_net_writer.pyThe note
sbml_to_netgives for the events it drops.python/bngsim/convert/__init__.py(thesbml_to_bngldocstring) anddocs/user-guide/interchange.mdsay what the phases name.Review
One round of a whole-branch
/code-reviewonf689e6f6, at high effort, to the bar in "How much to review". It returned two blocking findings, both the issue's own symptom on inputs the first rule missed. Both are fixed, and I read the fix commits' diff once more and stopped.kon = 1e6beside species at 1e-9 lifted the floor to 1, the phases namedatol=>1e-08, and BNG2.pl ran the three species 0.4 to 3.6 times their peak off. A small one tightened a model of counts.70978152: the scale is taken from species a reaction or a rate rule changes. BNG2.pl on the trigger: under 1e-7.test_a_parameter_an_event_sets_gives_no_scale,test_a_small_parameter_an_event_sets_leaves_a_model_of_counts_alone$-fixed stimulus at 1e-9 keptatol=>1e-08: BNG2.pl ran them 20 to 26% of peak off.70978152and78c56d12: the scale falls back to every species. BNG2.pl on the trigger: under 1e-7.test_species_that_start_at_zero_take_the_scale_of_a_fixed_oneCommits after the round:
70978152(those fixes);3808dd99(tests only:pytest.approxkept its default absolute tolerance of 1e-12, so every expectedatolnear 1e-17 passed whatever the code gave, which three surviving mutants showed; a catalyst case added);ec0140e9(one more test, for the mutant left alive);78c56d12, from my own rerun of the corpus below and not the review: the fallback of70978152read the$-fixed species only and lost MODEL7743528808, whose species start at 0 beside fixed species of order 1.Left alone
Simulator.run's default cannot (AtolScaleWarning). MODEL7743444866 getsatol=>1.66e-09and BNG2.pl runss1953.1e-3 of peak off, as it does with no tolerances (3.0e-3).Myc, whose true value is 0 on an unstable state: BNG2.pl's roundoff grows to 0.02 of the peak with the newatol, 0.0013 without.omex_to_net) are written from the document's own protocol and are not changed here.Testing
python/tests/test_sbml_to_bngl_tolerances.py, new, onec0140e9: 18 tests. With main's code and BNG2.pl: 18 failed. Here: 18 passed with BNG2.pl, 17 passed and 1 skipped without.How this was checked
Full suite on
ec0140e9(main at44e51182), macOS arm64, Python 3.13,uv sync --extra testplus h5py,BNGPATHat BioNetGen 2.9.3: 26671 passed, 548 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).Mutants (
mutate.pyfrom bngsim-preflights) onec0140e9: 15 of 16 killed: no tolerances written, or on the first phase only;atolleft at 1e-8 or let above it; the floor dropped, moved to 1e-3, or replaced by the largest; event values giving no scale, or every event's; every species or a catalyst counted as changing; no fallback, or one to the fixed species alone;rtolnot written; the note keeping the sidecar. The survivor removeschanged -= fixed, and is equivalent for a model the SBML loader builds: it lists no held species among a reaction's reactants or products (test_a_boundary_species_a_reaction_consumes_gives_no_scaleis the case). The line stays for a model built another way.The corpus under BNG2.pl: each of
benchmarks/sbml_events' 116 models that converts with actions, as written here and with the tolerances stripped (main's file), BNG2.pl 2.9.3 on both, against bngsim on the SBML atrtol=1e-10, atol=1e-16, worst species over peak away from the event times. 103 could be compared.The 45 are not a tolerance's: they are equally off with any
atol(an event at the end of the default horizon, which BNG2.pl applies after its last row, among them BIOMD0000000571 at the defaultt_span). No model newly fails under BNG2.pl; BIOMD0000000186, 187 and 193 stopped with an error before and complete now. BNG2.pl's time over the corpus: 49 s here, 46 s without the tolerances.pre-commit run --all-files,ci/changelog.py check,sphinx -W: pass.Linux with BNG2.pl (bngsim-docker,
bngsim_docker.py test --merge-main --kind bionetgen, amd64 under emulation):ec0140e9merged with main44e51182,test_sbml_to_bngl_tolerances.py,test_sbml_to_bngl.pyandtest_sbml_to_bngl_events.py: 155 passed, 34 skipped. All 18 of this PR's tests pass there, the BNG2.pl run of BIOMD0000000571 among them.Pre-PR gate (
prepr_check.pyfrom bngsim-preflights) onec0140e9with this description: 0 failed, 9 warnings, 36 passed. The warnings: convert: a compartment size the SBML model refuses to change is left out or marked, like a frozen parameter (#1992) #2139 on the same files (above); lists of callers and of sites that name the changed functions, to read (read:_build_protocolis the one place events become actions); a writer change wants a corpus comparison (item 3 is it, under BNG2.pl); code changed after the reviewed commit (described under Review); the corpus and mutant logs are older than_net_writer.py's time on disk (agit checkoutof main's code and back, to count the tests that fail there, rewrote the file byte for byte); the Linux run covers the three converter test files, not every file withbnglin its name (CI's legs run them all); claims to recount.Not run:
benchmarks/perf_ab.py(no change undersrc/, the code generator, the loaders or a run's path:sbml_to_bnglgains one pass over the model's reactions).