Skip to content

Update petab.v2 #361

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 19 commits into from
Mar 27, 2025
Merged

Update petab.v2 #361

merged 19 commits into from
Mar 27, 2025

Conversation

dweindl
Copy link
Member

@dweindl dweindl commented Mar 17, 2025

  • Adapt petab.v2 to the updated specs draft.

  • Make the new pydantic objects the primary objects and generate the DataFrames only on demand.

Validation is still a bit rough. We'll need nicer error messages and pydantic settings are too lax for validating files.

@codecov-commenter
Copy link

codecov-commenter commented Mar 17, 2025

Codecov Report

Attention: Patch coverage is 66.48148% with 181 lines in your changes missing coverage. Please review.

Project coverage is 74.55%. Comparing base (5b47448) to head (055dc2c).

Files with missing lines Patch % Lines
petab/v2/lint.py 62.31% 46 Missing and 32 partials ⚠️
petab/v2/problem.py 55.38% 52 Missing and 6 partials ⚠️
petab/v2/core.py 75.88% 30 Missing and 11 partials ⚠️
petab/v1/math/sympify.py 66.66% 2 Missing ⚠️
petab/v2/petab1to2.py 87.50% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #361      +/-   ##
===========================================
+ Coverage    74.44%   74.55%   +0.10%     
===========================================
  Files           57       57              
  Lines         5987     6075      +88     
  Branches      1039     1057      +18     
===========================================
+ Hits          4457     4529      +72     
- Misses        1133     1141       +8     
- Partials       397      405       +8     

☔ 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.

@matthiaskoenig
Copy link
Collaborator

@dweindl Is this usable already? I want to implement the timecourses in my tools but would need the updated petab library for that. Is this the right branch and working. If not what is still missing here?

@dweindl
Copy link
Member Author

dweindl commented Mar 21, 2025

@dweindl Is this usable already? I want to implement the timecourses in my tools but would need the updated petab library for that. Is this the right branch and working. If not what is still missing here?

I'd suggest to wait another week. The whole petab.v2 should be considered experimental. There's a lot in motion.

I am currently aligning things with PEtab-dev/PEtab#581 and switching from DataFrame based functions to pydantic-objects-based ones for petab.v2.

@matthiaskoenig
Copy link
Collaborator

Perfect.

@dweindl dweindl force-pushed the v2_misc branch 2 times, most recently from e6db0d1 to 3b8fc54 Compare March 21, 2025 18:00
@dweindl dweindl marked this pull request as ready for review March 25, 2025 08:20
@dweindl dweindl requested a review from a team as a code owner March 25, 2025 08:20
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.

Looks good so far!

@@ -43,6 +49,43 @@
]


def _is_finite_or_neg_inf(v: float, info: ValidationInfo) -> float:
Copy link
Member

Choose a reason for hiding this comment

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

Move these methods to the lint module? I guess they might be used there too, or is all validation intended to take place in the constructor of these pydantic objects?

Copy link
Member Author

Choose a reason for hiding this comment

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

That is still somewhat of an open question. I wouldn't want to duplicate the validation logic. However, the question is, which validations might have to be made optional at some point to work with future extensions. Probably too worry about that though.

So far, I would see everything that concerns the files and the presence of columns, as well as everything that cannot be validated inside a specific pydantic model to be in the lint module.

Another open question related to validation is whether it should still be possible to construct the pydantic objects from an invalid table.

Copy link
Member

Choose a reason for hiding this comment

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

No strong opinion but I guess that could be useful for e.g. loading partial problems into Paul's PEtab GUI

petab/v2/core.py Outdated
Comment on lines 893 to 903
if isinstance(v, int) or isinstance(v, float) and v.is_integer():
if v == 0:
return False
if v == 1:
return True

if isinstance(v, str):
if v == "0":
return False
if v == "1":
return True
Copy link
Member

Choose a reason for hiding this comment

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

Sufficient? Could also add True and False to remove the above code too...

Suggested change
if isinstance(v, int) or isinstance(v, float) and v.is_integer():
if v == 0:
return False
if v == 1:
return True
if isinstance(v, str):
if v == "0":
return False
if v == "1":
return True
if v in [0, 1, "0", "1"]:
return bool(int(v))

Copy link
Member Author

Choose a reason for hiding this comment

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

I think that should work. But meanwhile PEtab-dev/PEtab#614 happened. Needs updating.

Extra whitespace is not allowed, except for math expressions, right?

Copy link
Member

Choose a reason for hiding this comment

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

Extra whitespace is not allowed, except for math expressions, right?

Sounds fine to me. I don't see an issue either way, so whichever is more convenient

Copy link
Member Author

Choose a reason for hiding this comment

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

Same here. To be discussed at https://github.com/PEtab-dev/PEtab/.

if problem.model.has_entity_with_id(x)
}
if disallowed_in_condition:
is_or_are = "is" if len(disallowed_in_condition) == 1 else "are"
Copy link
Member

Choose a reason for hiding this comment

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

🤌

Comment on lines 38 to 40
if problem_id == "Froehlich_CellSystems2018":
# this is mostly about 6M sympifications in the condition table
pytest.skip("Too slow. Re-enable once we are faster.")
Copy link
Member

Choose a reason for hiding this comment

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

Not sure but maybe caching helps, e.g. https://github.com/AMICI-dev/AMICI/pull/1672/files

Copy link
Member Author

Choose a reason for hiding this comment

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

I had the feeling that caching is the problem here (inside sympy), but that needs further investigation.

@dweindl dweindl merged commit 101c79c into PEtab-dev:develop Mar 27, 2025
7 checks passed
@dweindl dweindl deleted the v2_misc branch March 27, 2025 13:26
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.

Use proper object model for petab.v2 v2: handle optional condition table
4 participants