Repository navigation
bngl: a folded_at_load= comment is read off the declaration BNG2.pl reads (#1994) - #2140
Merged
Merged
Conversation
…eads (lanl#1994) Model.from_bngl read each line of the parameters block as one declaration and the first blank-separated word as its name. BNG2.pl joins a line whose code ends in a backslash with the next (get_line), and takes the name as the identifier the declaration starts with (ParamList::readString). So a hand-written comment after `f \` / `k` froze k and left f writable, and one on `f(2.0)`, `f(k+1)`, `f-2.0` or a continued number froze nothing. The .bngl is now read as BNG2.pl reads it. A .net is read one line to a declaration as before, as bngsim's loader reads it.
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 #1994.
Important
Model.from_bnglread afolded_at_load=comment off each physical line of a.bngl's parameters block, and took the first blank-separated word as the parameter's name. BNG2.pl reads the block otherwise: a line whose code ends in\is joined with the next, and the name is the identifier the declaration starts with. So a comment written by hand afterf \/kfrozek, which the file says nothing about, and leftfwritable; and one onf(2.0),f(k+1),f-2.0or a continued number froze nothing. A.bnglis now read as BNG2.pl reads it, so the comment freezes the parameter its declaration declares. A.net, which bngsim's loader reads one line to a declaration, and every filesbml_to_netandsbml_to_bnglwrite, are read as before.The issue's script (BNG2.pl 2.9.3), on main at
44e51182and on this branch ata7981c69:frozen_params,set_paramf / kf 2.0 # folded_at_load=by handf 2.0['f'], refused / taken['f'], refused / takenf \ # folded_at_load=by hand/2.0f 2.0['f'], refused / taken['f'], refused / takenf \/2.0 # folded_at_load=by handf 2.0[], taken / taken['f'], refused / takenf \/k # folded_at_load=by handf k['k'], taken / refused['f'], refused / takenf \/k * 2 # folded_at_load=by handf k*2['k'], taken / refused['f'], refused / takenf(2.0) # folded_at_load=by handf 2.0[], taken / taken['f'], refused / takenf(k+1) # folded_at_load=by handf k+1[], taken / taken['f'], refused / takenf-2.0 # folded_at_load=by handf -2.0[], taken / taken['f'], refused / takenWhat changed
_folded_at_load_in(text, *, bngl=False)(python/bngsim/_model.py): withbngl=Truethe text is read as BNG2.pl 2.9.3 reads it (get_lineandread_block_arrayinBNGModel.pm,ParamList::readString):#; a line whose code ends in\and blanks has those taken off and the next line appended, nothing between (f\/2.0isf2.0, the parameterf2to BNG2.pl). A comment on any of the joined lines is the declaration's; the first mark wins.beginand its name, with or without a blank between them (beginparameterstoo, which main did not read), and closes onendand a blank.\d+\s+) and a label (\w+\s*:\s+, not starting with a digit) are taken off, and the name is the leading[A-Za-z_]\w*, whatever follows it..netreading is the same code as before, moved into_net_text_linesand_net_parameter_name: bngsim's.netloader (net_file_loader.cpp) joins no lines, so neither does the reader.from_bngl(_bngl_loader.py) passesbngl=True;from_netandparse_net_filedo not.Model.frozen_paramssays how a.bngl's comment is read.The diff (abridged)
Testing
python/tests/test_folded_at_load_bngl_lines.py, 24 tests:from_bngl. The test readsf's value from the network BNG2.pl generates and checks it is the value the declaration gives. It then checksfrozen_params == ['f'], that the write tofis refused with the comment's reason, and thatktakes one. With no blank before the backslash,g\/2.0declaresg2in BNG2.pl's network, andg2is the parameter frozen.beginparametersandend parameters; another block's name; what declares nothing (=,2f 1.0,3 4 1.0,other:,: f 2,3abc: f 2); a no-break space after the backslash (not a blank to Perl); a.netread one line at a time.test_convert_frozen_parameters.py: the forms convert: a parameter folded at load is left out or marked, not written free (#1792) #1988 tests read the same withbngl=True.Against main's library code, 8 of the 10 BNG2.pl tests fail, and the 2 that pass are the first two rows, which main read right. The reader tests fail on main at the new argument.
How this was checked
.bnglin the repo, against BNG2.pl. There are 113 files underbenchmarks/,python/testsanddocs/. In each, every line of the parameters block was markedfolded_at_load=x, and the names read were compared with the parameters of the network BNG2.pl 2.9.3 generates from the marked file, leaving out the ones it generates itself (_rateLaw<n>,_R<n>_local<k>,_AEact<n>_<k>).RAFi_ground.bnglcontinue a parameter over several lines, and main takes the continuation's expression for a name. That matters only once those lines are marked; the files carry no mark..bnglfilessbml_to_bnglwrote from the sbml_to_bngl writes a compartment size the SBML model refuses to change (unwritable_compartment_size_params) as a free parameter: set_param('c1', 3) on the converted model is accepted and gives A(2) = 0.049787 for 0.135335 #1992 corpus A/B read the same on main and on this branch..netjoined;.bnglnamed the.netway; a name starting with a digit; the last mark preferred to the first;beginneeding a blank; a label starting with a digit accepted; Unicode blanks; the block never closed. A guard the first round of mutants showed to be dead code was taken out.a7981c69: 27,187 passed, 200 skipped, 153 xfailed, 0 failed.bngl,foldedand load test among them) ona7981c69: in the BioNetGen image, which has BNG2.pl, 882 passed, 51 skipped, 0 failed, all 24 new tests among them; in the Debian image, 813 passed, 120 skipped, 0 failed (the BNG2.pl tests skip: no BNG2.pl there).folded_at_loadin it. On the three largest repo.bnglfiles with every parameter line marked, main against this branch, 7 runs of 20 reads each, median: 0.22 → 0.34 ms, 0.25 → 0.53 ms, 1.53 → 2.23 ms (Dolan2015, 273 KB). The BNG2.pl run that the same load makes takes seconds.--all-filespasses; the docs build withsphinx -W.prepr_check.py), ona7981c69and this description: GATE.With #2139. #2139 (#1992) also changes
python/bngsim/_model.py, in thefrozen_paramsandunwritable_compartment_size_paramsdocstrings. The two merge cleanly in either order (git merge-tree,58838262witha7981c69), and neither reads what the other changes.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; neither runs the new file, and the reader is pure Python, the same on every platform (Linux above).Review
One round of a whole-branch
/code-review, on48cff45e;a7981c69is that code plus its fixes and a rename (the helpers were_net_linesand_bngl_lines, andconvert/_net_writer.pyhas a_net_linesof its own). It found no bug the change introduced; it checked the reader againstget_line,read_block_arrayandreadString, and found three gaps against them, all fixed ina7981c69:beginparameterswas not read; BNG2.pl opens it (s/^begin\s*//). Pre-existing, on main too. Now read, with a test against BNG2.pl.3abc: f 2) gave a name, where BNG2.pl refuses the line. It now gives none. The docstring no longer says every declaration BNG2.pl refuses gives none:lbl:f 2giveslbl, and BNG2.pl refuses that file before the name is read.Not changed:
.netfiles are read one line to a declaration, with convert: a parameter folded at load is left out or marked, not written free (#1792) #1988's name rule, as bngsim's loader reads them. BNG2.pl reads a.netthrough the samereadFileandget_line(BNGModel.pm), so it would join a continued line there, but bngsim's loader does not, and the reader follows the loader that builds the model. No.netBNG2.pl writes has one._refuse_tables_in_parametersreads the.bngl's parameters block line by line, but looks fortfun(on any line of the block, so a continued declaration cannot hide one from it.