Skip to content

Fix PySBModel.is_state_variable for species with binding sites - #592

Merged
dweindl merged 1 commit into
PEtab-dev:mainfrom
dweindl:fix_pysb_is_state_variable
Nov 16, 2026
Merged

dweindl merged 1 commit into
PEtab-dev:mainfrom
dweindl:fix_pysb_is_state_variable

Conversation

@dweindl

@dweindl dweindl commented Nov 16, 2026

Copy link
Copy Markdown
Member

PySBModel.is_state_variable raised KeyError for any species with a site without states, so PEtab v2 linting crashed for PySB problems that use such species as condition targets. It also didn't recognize (state, bond) tuples, MultiState, lists of bonds, or complex-level compartments ((A(b=1) % B(a=1)) ** c).

pattern_from_string now parses the species name via ast (no eval) and builds the pattern from the model's monomers and compartments. Invalid names raise ValueError that includes the offending string. is_state_variable checks that all sites are specified and all bonds are paired.

pattern_from_string is stricter than before: unknown monomers, sites, states, or compartments now raise ValueError instead of producing a pattern with missing components.

Limitations (documented): compartments are still optional for models with compartments, and it is not checked whether the species is actually generated by the model or whether the monomers of a complex are connected.

Fixes #585.

🤖 Generated with Claude Code

@codecov-commenter

codecov-commenter commented Nov 16, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.30508% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 79.71%. Comparing base (f403be9) to head (0c44294).

Files with missing lines Patch % Lines
petab/v1/models/pysb_model.py 98.30% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #592      +/-   ##
==========================================
+ Coverage   79.52%   79.71%   +0.18%     
==========================================
  Files          70       70              
  Lines        8277     8315      +38     
  Branches     1498     1506       +8     
==========================================
+ Hits         6582     6628      +46     
+ Misses       1204     1198       -6     
+ Partials      491      489       -2     

☔ 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 force-pushed the fix_pysb_is_state_variable branch 2 times, most recently from b77af04 to 68cf525 Compare November 16, 2026 14:55
@dweindl
dweindl marked this pull request as ready for review November 16, 2026 15:03
@dweindl
dweindl requested a review from a team as a code owner November 16, 2026 15:03
`is_state_variable` raised `KeyError` for any species with a site
without states, and didn't recognize `(state, bond)` tuples or
`MultiState`. This broke PEtab v2 linting for PySB problems with such
species as condition targets.

`pattern_from_string` now parses the species name via `ast` and builds
the pattern from the model's monomers and compartments.
`is_state_variable` checks that all sites are specified and all bonds
are paired. Compartments remain optional.

Fixes PEtab-dev#585.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dweindl
dweindl force-pushed the fix_pysb_is_state_variable branch from 68cf525 to 0c44294 Compare November 16, 2026 18:09
@dweindl
dweindl enabled auto-merge (squash) November 16, 2026 18:12
@dweindl
dweindl merged commit 74f089e into PEtab-dev:main Nov 16, 2026
7 checks passed
@dweindl
dweindl deleted the fix_pysb_is_state_variable branch November 16, 2026 18:22
dweindl added a commit to dweindl/libpetab-python that referenced this pull request Nov 17, 2026
Every pull request added its changelog entry at the same place in
`CHANGELOG.md`, so concurrent pull requests conflicted with each other.

Now, each pull request adds its entry as a separate file
`changelog.d/+<name>.<type>.md` (see `changelog.d/README.md`). At release
time, `towncrier build --version X.Y.Z` collects them into `CHANGELOG.md`.

The unreleased 0.11.0 entry is moved to `changelog.d/`, and entries are
added for PEtab-dev#583, PEtab-dev#584, PEtab-dev#588, PEtab-dev#590, PEtab-dev#592 and PEtab-dev#595, which did not add one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
dweindl added a commit to dweindl/libpetab-python that referenced this pull request Nov 17, 2026
Every pull request added its changelog entry at the same place in
`CHANGELOG.md`, so concurrent pull requests conflicted with each other.

Now, each pull request adds its entry as a separate file
`changelog.d/+<name>.<type>.md` (see `changelog.d/README.md`). At release
time, `towncrier build --version X.Y.Z` collects them into `CHANGELOG.md`.

The unreleased 0.11.0 entry is moved to `changelog.d/`, and entries are
added for PEtab-dev#583, PEtab-dev#584, PEtab-dev#588, PEtab-dev#590, PEtab-dev#592 and PEtab-dev#595, which did not add one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
dweindl added a commit to dweindl/libpetab-python that referenced this pull request Nov 17, 2026
Every pull request added its changelog entry at the same place in
`CHANGELOG.md`, so concurrent pull requests conflicted with each other.

Now, each pull request adds its entry as a separate file
`changelog.d/+<name>.<type>.md` (see `changelog.d/README.md`). At release
time, `towncrier build --version X.Y.Z` collects them into `CHANGELOG.md`.

The unreleased 0.11.0 entry is moved to `changelog.d/`, and entries are
added for PEtab-dev#583, PEtab-dev#584, PEtab-dev#588, PEtab-dev#590, PEtab-dev#592 and PEtab-dev#595, which did not add one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
dweindl added a commit to dweindl/libpetab-python that referenced this pull request Nov 17, 2026
…v#600)

Every pull request added its changelog entry at the same place in
`CHANGELOG.md`, so concurrent pull requests conflicted with each other.

Now, each pull request adds its changelog entry as a separate file
`changelog.d/+<name>.<type>.md` (see `changelog.d/README.md`). At
release time, `towncrier build --version X.Y.Z` collects them into
`CHANGELOG.md` and removes the fragments. The template in
`changelog.d/template.md.j2` reproduces the existing format (`**Fixes**`
etc., `* ` bullets with 2-space continuation lines). Entries are sorted
alphabetically within each category; grouping them (e.g., by PEtab
version or module) is done when compiling the release notes. The
configuration is in `pyproject.toml`, and towncrier is added to the
`test` dependency group. The release process in `doc/development.rst` is
updated accordingly.

Entries now link to the pull request only, without "by @user";
contributors can be credited in the release notes.

The unreleased 0.11.0 entry (PEtab-dev#578) is moved to `changelog.d/`, and
entries are added for PEtab-dev#583, PEtab-dev#584, PEtab-dev#588, PEtab-dev#590, PEtab-dev#592 and PEtab-dev#595, which did
not add one. The behaviour changes from PEtab-dev#584 (top-level Boolean
expressions are returned as `Piecewise`) and PEtab-dev#592 (stricter
`PySBModel.pattern_from_string`) are listed as breaking changes.

Open pull requests that edit `CHANGELOG.md` will need to move their
entry to a fragment file.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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.

PySBModel.is_state_variable raises KeyError for species with binding sites

3 participants