Skip to content

ExperimentsToSbmlConverter: write one flat initial assignment per target - #546

Open
FFroehlich wants to merge 1 commit into
mainfrom
claude/issue-540-fix-3c75eb
Open

FFroehlich wants to merge 1 commit into
mainfrom
claude/issue-540-fix-3c75eb

Conversation

@FFroehlich

@FFroehlich FFroehlich commented Oct 14, 2026 •

Copy link
Copy Markdown
Collaborator

ExperimentsToSbmlConverter built the initial assignments for the first period once per experiment. Each experiment read the current initial assignment back as the default and wrapped it in a new Piecewise, so the expression nested one level deeper per experiment. With a few hundred experiments, reading it back (sbml_math_to_sympy) failed in lxml with Excessive depth in document: 256. This breaks Raimundez_PCB2020 upgraded to v2.

Change

convert() now collects the first-period changes of all experiments and writes them in one go (new _create_initial_assignments): one flat Piecewise per target, with one (value, indicator_e > 0.5) pair per experiment that changes the target, and the original model's initial assignment or initial value as the otherwise branch.

This follows the second fix suggested in the issue rather than flattening while wrapping. It also means the default is always the original model's value, and the growing assignment is no longer serialized and re-parsed once per experiment.

Verification

  • New test test_initial_assignments_many_experiments (300 experiments; a species with an initial value and one with an initial assignment, plus one experiment that changes neither). It checks that the assignment is a flat Piecewise with one pair per experiment and that it evaluates correctly for the first and last experiment and for the default. It fails on main with the lxml error from the issue.
  • The issue's reproducer: the initial assignment of A is 3 levels deep for 5, 50, 300 and 1000 conditions (before: 7, 52, lxml error).
  • Benchmark collection (all models except Froehlich_CellSystems2018, upgraded with petab1to2): for every initial assignment and every experiment (and with all indicators at 0), the old and new converter give the same value. The maximum MathML depth drops, e.g., Alkan_SciSignal2018 75 → 4, Bachmann_MSB2011 38 → 4, Smith_BMCSystBiol2013 37 → 4. Raimundez_PCB2020 (170 experiments) fails with the old converter. With the new one, all 1360 first-period changes match the resulting initial assignments, at depth 4. Conversion takes ~2 s; the old converter took 22 s before failing.
  • pytest tests/v2: 142 passed, 1 skipped (with benchmark_models_petab installed). pre-commit is clean.

Closes #540

🤖 Generated with Claude Code

The first-period changes were turned into initial assignments once per
experiment. Each experiment read the current initial assignment back as
the default and wrapped it in a new Piecewise, so the expression nested
one level deeper per experiment. With a few hundred experiments, reading
it back failed in lxml ("Excessive depth in document: 256"), e.g., for
Raimundez_PCB2020 upgraded to v2.

Now the first-period changes of all experiments are collected and
combined into a single flat Piecewise per target after all experiments
were converted. The default is the initial assignment or initial value
of the original model.

Closes #540

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

codecov-commenter commented Oct 14, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 88.23529% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 77.80%. Comparing base (402393d) to head (4acbb9c).
⚠️ Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
petab/v2/converters.py 88.23% 1 Missing and 3 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #546      +/-   ##
==========================================
+ Coverage   76.77%   77.80%   +1.02%     
==========================================
  Files          67       67              
  Lines        7547     8230     +683     
  Branches     1346     1543     +197     
==========================================
+ Hits         5794     6403     +609     
- Misses       1259     1295      +36     
- Partials      494      532      +38     

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

@FFroehlich
FFroehlich marked this pull request as ready for review October 15, 2026 08:41
@FFroehlich
FFroehlich requested a review from a team as a code owner October 15, 2026 08:41

@dweindl dweindl left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks 👍

@FFroehlich
FFroehlich enabled auto-merge (squash) October 15, 2026 08:51

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.

ExperimentsToSbmlConverter nests initial-assignment Piecewise once per experiment, exceeding lxml's depth limit

3 participants