Repository navigation
checkConsistency of a comp document is linear in its model definitions (#505) - #507
Open
matthiaskoenig wants to merge 3 commits into
Open
matthiaskoenig wants to merge 3 commits into
matthiaskoenig wants to merge 3 commits into
Conversation
CompSBMLDocumentPlugin::checkConsistency set mCheckingDummyDoc and mFlattenAndCheck on the plugin of the document it checks, to make the dummy documents it copies from it skip their model definitions and their flat model. mCheckingDummyDoc was never reset, and mFlattenAndCheck not after an error in a model definition, so a second check of the document and a copy of it skipped the model definitions, and after such an error also the flat model. The flags are now set on the dummy document only. Refs sbmlteam#505.
Every modelDefinition was checked in a copy of the whole document, so a document of N modelDefinitions was copied N times and the check was quadratic in N, also with every check category disabled. One dummy document is copied now and used for all modelDefinitions: its model is swapped for the modelDefinition under check, which is held out of its modelDefinitions during the check and put back afterwards, and the model of the document is added to its modelDefinitions once. The dummy also keeps the documents of the externalModelDefinitions it resolved, which every copy read again. Refs sbmlteam#505.
This branch has not been deployed
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.
Part of #505: the check of a comp document is linear in the number of model definitions instead of quadratic.
Builds on #506, whose commit is the first one of this branch. Please merge #506 first; after that, this pull request shows only its own commit.
Cause
CompSBMLDocumentPlugin::checkConsistencychecked every model definition as the model of a dummy document. The dummy was a copy of the whole document, made once per model definition. A document of N model definitions was therefore copied (and destroyed) N times. That is quadratic in N, and it happened even with every check category disabled. A callgrind profile of the issue's example with no checks put 55 % of the instructions intoSBMLDocument::SBMLDocument(const SBMLDocument&)and 19 % into its destructor.Change
The validation itself is unchanged; only the setup of the dummy document changes:
setModelcopies only that model definition). The dummy's own copy of that model definition is held out of its list during the check and put back at the same position afterwards. During each check the dummy therefore holds the same model and the same model definitions, in the same order, as the per-definition copy did before.UnrequiredPackagePresent/RequiredPackagePresententries are logged again, as the fresh copy had them.On suggestion 2 of the issue: the comp validators of a document check only its model and its external model definitions, not the content of its model definitions. In the dummy they check the comp constructs (submodels, ports, replacements) of the model definition under check, so they are not redundant and still run.
Timing
The issue's reproduction in C++: one submodel for each of n model definitions with 200 parameters each,
setOverrideCompFlattening(true). Built with RelWithDebInfo, single runs.developmentdevelopmentWhat remains with all checks is the core validation of each model definition. Its instruction count (callgrind) grows by 2.14x from 32 to 64 model definitions, against 2.0x for reading the document. The rest of the wall-clock growth comes from the 77k modeling-practice warnings of this artificial document.
Two physiologically based pharmacokinetic (PBPK) models built from many model definitions, checked with the default settings (flattening check included):
Tests
test_comp_fail_nested_moddef: three model definitions that reference each other (md2->md1->md0), with an error insidemd1. The test checks that the error is reported exactly once, that the submodel ofmd1resolves (noCompSubmodelMustReferenceModel), and that the check leaves the model and the order of the model definitions of the document unchanged.TestCheckConsistency.cpp(all 7 tests) was compiled against a minimal stand-in forcheck.hand passes.test_comp_validatorpasses all cases (280, 14 and 22 checks), built with comp, fbc and layout. It reports no memory errors under valgrind, andTestCheckConsistency.cpphas no leaks.