Repository navigation
Fix invalid and lossy output of petab_math_str - #545
Conversation
Make `PetabStrPrinter` produce valid PEtab math that round-trips: * print `&&`, `||`, `!`, `==`, `!=` instead of sympy's `&`, `|`, `~`, `Eq(...)`, `Ne(...)` * parenthesize negative and non-integer rational bases of powers * print n-ary `Min`/`Max` as nested binary `min`/`max` * print `pi` as its double value and `E` as `exp(1)` * print double-precision floats with the shortest exact representation, and integer-valued floats as integers * raise for `Piecewise` without a default condition Use `petab_math_str` instead of `str` in `ConditionTable.to_df` and `MeasurementTable.to_df`. Fixes PEtab-dev#544. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #545 +/- ##
==========================================
+ Coverage 77.58% 77.74% +0.16%
==========================================
Files 67 67
Lines 7673 7702 +29
Branches 1374 1378 +4
==========================================
+ Hits 5953 5988 +35
+ Misses 1231 1226 -5
+ Partials 489 488 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
|
||
| def _print_Pi(self, expr): | ||
| """PEtab has no pi constant; print its double-precision value""" | ||
| return repr(float(expr)) |
There was a problem hiding this comment.
Hard code? No advantage to computing from expr I guess
There was a problem hiding this comment.
I'd rather not introduce our own literal here. I find it easier to verify this way.
|
|
||
|
|
||
| def test_to_df_math_expressions(): | ||
| """Expressions are written in PEtab syntax and without precision loss.""" |
There was a problem hiding this comment.
I am not sure if precision loss is tested here. e.g. there are no long numbers that could be rounded.
There was a problem hiding this comment.
It's tested via 2 / 3, repr(2 / 3), but I'll make that more obvious.
There was a problem hiding this comment.
Ah, I did not realize it would change a fraction to a decimal. Thanks for opening #548
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Fix `test_flatten_timepoint_specific_output_overrides` for the current libpetab-python `main`. Since PEtab-dev/libpetab-python#545, `petab_math_str` prints double-precision floats such that they round-trip, e.g., `1` instead of `1.00000000000000`. The flattened observable IDs are derived from the override values, so they are now `obs1__obsParOverride1_1__noiseParOverride1` instead of `obs1__obsParOverride1_1_00000000000000__noiseParOverride1`. This test fails on `main` since then. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
libpetab now writes all standard columns of v2 tables by default (PEtab-dev/libpetab-python#543), which added an empty `parameterName` column to all parameter tables. Load v2 case modules under `petab.v2.option_context(table_columns="non_empty")` to omit columns that are empty in all rows. Regenerate the v2 cases. Apart from dropped empty columns, the only changes are due to the updated number formatting in math expressions (PEtab-dev/libpetab-python#545), e.g. `0.500000000000000` -> `0.5`. Solution files are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
libpetab now writes all standard columns of v2 tables by default (PEtab-dev/libpetab-python#543), which added an empty `parameterName` column to all parameter tables. Load v2 case modules under `petab.v2.option_context(table_columns="non_empty")` to omit columns that are empty in all rows. Regenerate the v2 cases. Apart from dropped empty columns, the only changes are due to the updated number formatting in math expressions (PEtab-dev/libpetab-python#545), e.g. `0.500000000000000` -> `0.5`. Solution files are unchanged. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Make
petab_math_strproduce valid PEtab math expressions that round-trip, and use it when writing v2 condition and measurement tables.PetabStrPrinternow:&&,||,!,==,!=instead of sympy's&,|,~,Eq(...),Ne(...)(-2) ^ xwas printed as-2.0 ^ x)Min/Maxas nested binarymin/maxpias its double value andEasexp(1)0.6666666666666666instead of0.666666666666667), and integer-valued floats as integers (100*xinstead of100.0*x)Piecewisewithout a default condition instead of dropping the last conditionConditionTable.to_dfandMeasurementTable.to_dfnow usepetab_math_strinstead ofstr, so expressions are written in PEtab syntax and float values are not truncated.Fixes #544.
🤖 Generated with Claude Code