Skip to content

v2: speed up loading large condition and measurement tables - #634

Open
dweindl wants to merge 1 commit into
PEtab-dev:mainfrom
dweindl:v2-table-load-perf
Open

dweindl wants to merge 1 commit into
PEtab-dev:mainfrom
dweindl:v2-table-load-perf

Conversation

@dweindl

@dweindl dweindl commented Nov 26, 2026 •

Copy link
Copy Markdown
Member

Speeds up ConditionTable.from_df and MeasurementTable.from_df for large tables. In such tables, many cells share the same values (e.g., target values, noise or observable parameters), and each cell was converted with sympify separately, which dominated the loading time.

  • Each distinct value is sympified once per from_df call. The cache is passed to the field validators through the pydantic validation context, so it only lives for that call. It is keyed by type and value, because 1 and 1.0 hash equal but are sympified to Integer and Float, respectively (sympify_petab returns Integer for Python/numpy integers, but Float for numeric strings #553).
  • Each distinct condition target ID is validated once per from_df call.
  • groupby, iterrows, and to_dict("records") are replaced by plain column lists.

Behavior change: ConditionTable.from_df keeps conditions in the order of their first occurrence in the file, instead of sorting them by ID.

Loading time of the PEtab v2 versions of benchmark problems: Froehlich_CellSystems2018 goes from 18.7 s to 9.7 s, and Beer_MolBioSystems2014 from 2.8 s to 0.4 s. For all other problems of the benchmark collection, the loaded tables are unchanged apart from the condition order.

🤖 Generated with Claude Code

* Sympify each distinct value once per `from_df` call. The cache is
  passed to the field validators via the pydantic validation context,
  keyed by type and value (`1` and `1.0` are sympified differently).
* Validate each distinct condition target ID once per `from_df` call.
* Avoid `groupby`, `iterrows`, and `to_dict("records")`.

`ConditionTable.from_df` now keeps conditions in the order of their
first occurrence, instead of sorting them by ID.

Loading the converted Froehlich_CellSystems2018 problem: 18.7 s ->
9.7 s; Beer_MolBioSystems2014: 2.8 s -> 0.4 s. The loaded tables are
unchanged for all other benchmark problems (apart from condition order).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.23810% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.39%. Comparing base (bacc686) to head (629e64f).

Files with missing lines Patch % Lines
petab/v2/core.py 95.23% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #634      +/-   ##
==========================================
+ Coverage   80.34%   80.39%   +0.05%     
==========================================
  Files          70       70              
  Lines        8505     8538      +33     
  Branches     1561     1565       +4     
==========================================
+ Hits         6833     6864      +31     
- Misses       1180     1182       +2     
  Partials      492      492              

☔ View full report in Codecov by Harness.
📢 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 marked this pull request as ready for review November 26, 2026 14:17
@dweindl
dweindl requested a review from a team as a code owner November 26, 2026 14:17
@dweindl dweindl self-assigned this Nov 26, 2026

This branch has not been deployed

No deployments
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.

2 participants