Skip to content

Add petab-compatible sympy string-printer #364

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 27, 2025

Conversation

dweindl
Copy link
Member

@dweindl dweindl commented Mar 20, 2025

Add a sympy Printer to stringify sympy expressions in a petab-compatible way. For example, we need to avoid str(sympy.sympify("x^2")) -> 'x**2'.

Closes #362.

@codecov-commenter
Copy link

codecov-commenter commented Mar 20, 2025

Codecov Report

Attention: Patch coverage is 78.26087% with 10 lines in your changes missing coverage. Please review.

Project coverage is 74.57%. Comparing base (81af370) to head (51c96ad).

Files with missing lines Patch % Lines
petab/v1/math/printer.py 75.75% 6 Missing and 2 partials ⚠️
petab/v1/math/sympify.py 77.77% 2 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #364      +/-   ##
===========================================
- Coverage    74.57%   74.57%   -0.01%     
===========================================
  Files           57       58       +1     
  Lines         6080     6119      +39     
  Branches      1058     1062       +4     
===========================================
+ Hits          4534     4563      +29     
- Misses        1141     1149       +8     
- Partials       405      407       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@dweindl dweindl force-pushed the strprinter_gh-362 branch from 5edcd58 to 522e06e Compare March 21, 2025 10:56
@dweindl dweindl marked this pull request as ready for review March 21, 2025 10:56
@dweindl dweindl requested a review from a team as a code owner March 21, 2025 10:56
@dweindl dweindl force-pushed the strprinter_gh-362 branch from 522e06e to cec9253 Compare March 21, 2025 10:58
@dweindl dweindl mentioned this pull request Mar 22, 2025
@dweindl dweindl force-pushed the strprinter_gh-362 branch 2 times, most recently from 1139547 to c15876e Compare March 27, 2025 14:38
Copy link
Member

@dilpath dilpath left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Comment on lines 31 to 37
# non-real symbols are changed to real
# TODO: should we raise an error instead?
assert sympify_petab(sp.Symbol("x", real=False)).is_real
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably raise an error, or does it occur in standard use?

Copy link
Member Author

@dweindl dweindl Mar 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It happens if you pass sympify("x"). Not sure what standard use will be 😅

I think, just stating that the real-assumption is applied to all inputs is sufficient.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, fine for me on the level of symbols. I was thinking of expressions, which I guess is irrelevant here, so nevermind.

@dweindl dweindl force-pushed the strprinter_gh-362 branch from 1583431 to e800abb Compare March 27, 2025 19:04
Add a sympy Printer to stringify sympy expressions in a petab-compatible way.
For example, we need to avoid `str(sympy.sympify("x^2"))` -> `'x**2'`.

Closes PEtab-dev#362.
@dweindl dweindl force-pushed the strprinter_gh-362 branch from e800abb to 51c96ad Compare March 27, 2025 19:07
@dweindl dweindl enabled auto-merge (squash) March 27, 2025 19:19
@dweindl dweindl merged commit 7ab7cd8 into PEtab-dev:develop Mar 27, 2025
7 checks passed
@dweindl dweindl deleted the strprinter_gh-362 branch March 27, 2025 20:07
@dweindl dweindl linked an issue Mar 28, 2025 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add petab-compatible sympy codeprinter
3 participants