Repository navigation
convert: a compartment size the SBML model refuses to change is left out or marked, like a frozen parameter (#1992) - #2139
Merged
Conversation
…out or marked, like a frozen parameter (lanl#1992) sbml_to_net and sbml_to_bngl read Model.frozen_params only, and the sizes in Model.unwritable_compartment_size_params are kept out of it on purpose, so the written file held such a size as a free parameter: the model loaded from it took set_param, which moved a rate law that names the size and not the volume the species are divided by. _frozen now hands these sizes to the same rule: left out where nothing in the file reads one, marked folded_at_load= where something does. The structural check's left-out set and the dropped note follow.
This was referenced Dec 3, 2026
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 #1992.
Important
sbml_to_netandsbml_to_bnglwrote a compartment size the SBML model refuses to change (Model.unwritable_compartment_size_params) as a free parameter, and the model loaded from the file tookset_paramon it. The write could move a rate law that names the size and not what the SBML model fixed from it, which the file holds as a number; in the issue's model it did. Such a size is now written as a frozen parameter is (#1792): left out where nothing in the file reads it, and markedfolded_at_load=where something does, so that the model loaded from the file refuses the write as the SBML model does.The issue's model (
c1= 2,c2 = 2*c1by an initialAssignment,A -> Batk*A*c1), throughsbml_to_bngl(sbml_to_netrefuses it, as on main):On main at
44e51182and this branch at58838262:c1line1 c1 2.01 c1 2.0 # folded_at_load=what the SBML model fixed from the size of compartment c1, a size it cannot resolve to a live volume and refuses to change (...)frozen_params[]['c1']set_param("c1", 3)ParameterErrorok=True, no noteok=True,folded_marked=['c1'], abngsim_onlynoteThe SBML model refuses the write, and at
c1= 3 it gives A(2) = 0.135335 (closed formexp(-k t), whateverc1is).What changed
convert/_frozen.py,_reasons: the names the module handles are the model's frozen parameters and, new, its unwritable compartment sizes, each with what it was folded into: "what the SBML model fixed from the size of compartment<c>, a size it cannot resolve to a live volume and refuses to change (Model.unwritable_compartment_size_params of the SBML model)". That text is thefolded_at_load=comment and the reloaded model's refusal. A size already infrozen_paramskeeps its own entry (the SBML loader keeps the two apart; a BNG2.plunit_conversion=one stays written as before)._validate._folded_left_out: the structural check compares parameter counts net of what the writer left out; a size left out is now among them, or L1 would count it missing._frozen.notes: thedroppednote on a size left out names the list it was in,Model.unwritable_compartment_size_params, besideModel.frozen_params. The note on a frozen parameter is unchanged.Model.frozen_params,Model.unwritable_compartment_size_params, the interchange guide, the report field's comment.The diff (abridged)
Testing
python/tests/test_convert_unwritable_compartment_size.py, 14 tests, four models with closed forms. Against main's library code, 11 fail and 3 pass, the 3 by design: the source model's own refusal (2, controls), and the issue's write on the file with its mark taken off, which still gives A(2) = e^-3 where the SBML gives e^-2..bngl):c1marked,frozen_params == ['c1'], the write refused with the size's reason, a write of the value it holds taken, A(2) and B(2) at their closed forms.A -> 0atk*A; the file hask/(c1/_V0_c1)),.netand.bngl: marked and refused; A(2) = exp(-k t / c1). Here a write would have been whole (the file followsc1in the ratio, and nothing readsc2's folded size): it is refused because the SBML model refuses it, not because it would be wrong.A -> 0atk*A*c1, folded into numbers),.netand.bngl: left out, thedroppednote names it and its list, the write fails as a name the model has not, A(2) = exp(-k t).A + B -> Cacrossc1andc2, both size 1; the SBML refuses both),.netand.bngl: both left out, A(2) = B(2) = 1/(1 + k t), C(2) = 1 - A(2).unit_conversion=parameter that is also a size, written as before; the note on a frozen parameter unchanged.How this was checked
writer_ab.py, main at44e51182against58838262), on the 47 models below and the 331 BioModels (361 files): 336 identical; the 25 that differ are each a model with an unwritable size (24.net, 24.bngl). Conversion, reload and run (main atd44b6a33, whoseconvert/differs from44e51182's only in_bng2.py, BNG2.pl's lookup): the 1,823 SBML test-suite cases (highest level each) and 331 BioModels; 239 fail to load on both sides (unsupported constructs). 47 have an unwritable size; the change reads nothing else, so the other 1,868 are the same by construction. On the 47,sbml_to_netandsbml_to_bngl: 94 conversions, 14 refused with the same refusal on both sides, 80 written:ok,lossyand the structural verdict are unchanged in all 80.Model.from_sbml(..., compartment_sizes={size: 1.5 v + 0.5}), the documented way to move one, the converted model after the sameset_paramwas off by 3.7e-3 to 528 times the value (relative, over the species at t = 1), on 18 models; the 19th's reference fails to integrate. That is the corpus, not a rule: the second test model above is a shape where the write would have been whole. The.netand the SBML agree exactly at the loaded size on all 28 checked, so the species line up.unit_conversion=guard dropped).58838262: 27,177 passed, 200 skipped, 153 xfailed, 0 failed..bngltests skip (no BNG2.pl); in the BioNetGen image, which has it, 471 passed, 91 skipped, 0 failed, all 14 new tests among them on58838262..net79 → 96 ms; MODEL2109110001.net75 → 100 ms,.bngl78 → 101 ms; MODEL2012040002.net20 → 26 ms,.bngl17 → 27 ms. +6 to +25 ms a conversion.--all-filespasses; the docs build withsphinx -W.prepr_check.py), on58838262and this description: 37 passed, 0 failed, 6 warnings, each read: the CI legs (above); the conversion A/B's main atd44b6a33(said above, before the rebase); the untouched readers of the changed functions, the changelog's sites, the claim and scope words, each covered by the reviews and the recounts above.CI legs.
python-testsruns the whole ofpython/testson ubuntu, macOS and LAPACK. Python only, nosrc/change, so MIR and Windows KLU do not fire.wheels.ymlandwindows-tail.ymlfire onpython/bngsim/_model.py, where the change is two docstrings; neither runs the new file, and the converters' code is the same on every platform (Linux above).Review
Three rounds, each by a separate reader of the branch.
frozen_params(the protocol runner's held numbers,describe, the OMEX actions note, coupling, digest, record) and the assignment-rule and shared-scalar kinds of size. It found the refusal's "(its Model.unwritable_compartment_size_params)" pointing at a list that is empty on the model refusing, now "of the SBML model"; the docstring and changelog reading as if a size left out were listed infrozen_params, now said apart; and asked for the cost, measured above.c1= 3, asfrom_sbml(..., compartment_sizes={"c1": 3})gives). The claim is now that a write can move a rate law and not what the size was folded into, and that the file refuses it as the SBML model does./code-review;58838262is that code plus its fixes. No blocking bug; seven nits. Fixed: the comment's "computed at load", untrue of a size an assignment rule sets (now "fixed from the size"); aunit_conversion=parameter that is also a size, now written as before as the module says; theexcept AttributeErroraround the size list, which would have read an error inside the property of a real model as "no sizes" (now a check on the type); six docstrings namingfrozen_paramsalone; and a test of the second kind of size, the shared scalar. Two are under "Not changed".Not changed:
_protocol._held_as_numbers, whichomex_to_netandrun_protocolread for a parameter declared by an expression, readsfrozen_paramsonly. A size the SBML model refuses that is also declared by an expression would be followed there; none of the 47 corpus models with such a size has an expression on it (0 of 47 checked)._actions_on_folded's note on an action that sets such a size says it "was folded into a number when the model was loaded", where the source refuses it for its own reason; the note does name the parameter, and the report lists it infolded_left_outorfolded_marked.Pre-existing, on main too:
.bnglas a free parameter where the file holds the volume as a number inbegin compartments: in the issue's model,c2(= 2*c1, writable) takesset_param("c2", 3)in the SBML (B(2) 0.432332 → 0.576443) and in the reloaded.bngl, where it moves nothing. That is not this list, and is left for its own issue.A -> 0atk*A; afterset_param("c1", 3)the SBML gives A(2) = 0.171139 and the.netand.bngl0.256709 (the rate ratio follows, the initial concentration does not). Also left for its own issue.