Repository navigation
Formulas are parsed without importing the package petab - #389
Merged
Merged
Conversation
compile_formula imported petab.v2.math, which imports the package petab with matplotlib.pyplot and scipy.stats and petab.v2 with its SciML extension and torch: 0.7 to 1.4 s for the first formula of a process and of every worker of a pool. The parser of petab, petab.v1.math, imports only sympy, numpy and the runtime of ANTLR; parse_math imports its directory as the package sbmlsim._petab_math. A process which imported petab already uses it, and a petab whose parser is elsewhere is imported as a whole.
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.
Problem
compile_formulaimportedpetab.v2.mathfor its parsersympify_petab. That import pulls in:petab, with the problems of PEtab v1,matplotlib.pyplotandscipy.stats;petab.v2, with its SciML extension,petab_scimland torch.Every process and every worker of a pool paid this on its first
Formulaobservable orDatafunction: 0.7 s on an idle machine, 1.4 s under load. Measured with the sampling profiler of python 3.15 on a scan with observables.Fix
The parser of petab,
petab.v1.math, is self-contained: it uses relative imports and needs only sympy, numpy and the runtime of ANTLR.parse_math(formula)imports that directory as the packagesbmlsim._petab_math. It is the same code assympify_petab, so PEtab math keeps exactly petab's semantics.petabalready usespetab.v2.math.parse_mathfalls back to importingpetab.v2.mathas before.The first formula now takes 0.04 s instead of 0.67 s, and
torch,petab,matplotlib.pyplotandscipy.statsare no longer imported.Tests
test_compiling_a_formula_does_not_import_petab: in a fresh python, none of these modules is imported. On develop all four are.test_the_parser_is_the_one_of_petab: ten formulas give the same expression assympify_petab. They cover the precedence of^and unary minus, the booleans,piecewise, the logarithms, comparisons, the constants,min/maxand numbers.pytest --skip-slow tests/simulator tests/simulation tests/data tests/uncertainty: 878 passed.tests/test_data*.py tests/test_imports.py tests/fit tests/sciml: 2313 passed.After review
test_the_math_of_petab_v2_is_the_parser_of_petab_v1fails ifpetab.v2.mathstops re-exporting the parser of v1, whichparse_mathreads.