Skip to content

Support PEtab SciML problems and enable linting#482

Open
m-philipps wants to merge 22 commits into
mainfrom
sciml_lint
Open

Support PEtab SciML problems and enable linting#482
m-philipps wants to merge 22 commits into
mainfrom
sciml_lint

Conversation

@m-philipps

Copy link
Copy Markdown
Collaborator

WIP

@m-philipps m-philipps changed the title Support a PEtab SciML problem and enable linting Support PEtab SciML problems and enable linting May 26, 2026
@codecov-commenter

codecov-commenter commented Jun 11, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 64.42953% with 53 lines in your changes missing coverage. Please review.
✅ Project coverage is 75.17%. Comparing base (ae4ea94) to head (111658e).

Files with missing lines Patch % Lines
petab/v2/core.py 61.90% 32 Missing and 8 partials ⚠️
petab/v2/lint.py 69.76% 6 Missing and 7 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #482      +/-   ##
==========================================
- Coverage   75.29%   75.17%   -0.12%     
==========================================
  Files          62       62              
  Lines        6946     7086     +140     
  Branches     1229     1254      +25     
==========================================
+ Hits         5230     5327      +97     
- Misses       1245     1277      +32     
- Partials      471      482      +11     

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

@BSnelling BSnelling marked this pull request as ready for review June 16, 2026 10:41
@BSnelling BSnelling requested a review from a team as a code owner June 16, 2026 10:41

@dilpath dilpath 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! Overall it would be good to try to separate as much of the SciML things into separate files or subdirectory if possible. This will help later on when we design a nicer extension interface for libpetab-python, I think. It will also help with maintenance immediately.

Comment thread petab/v2/core.py
#: Nominal value.
nominal_value: Annotated[
float | None, BeforeValidator(_convert_nan_to_none)
float | Literal["array"] | None, BeforeValidator(_convert_nan_to_none)

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.

Maybe add some # PEtab SciML supports arrays comment here, otherwise a non-SciML user/dev might wonder why "array" is permitted

Comment thread petab/v2/core.py
return sum(p.estimate for p in self.parameters)


class Hybridization(BaseModel):

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.

Move SciML-specific things to a separate file or subdirectory e.g. sciml/core.py and import them here? Just for organization; might help to keep SciML things as separate as possible. e.g. do not import petab_sciml here, rather only in the separated file.

Nevermind this if it will lead to circular imports etc.

Comment thread petab/v2/core.py
config: ProblemConfig = None,
):
from ..v2.lint import default_validation_tasks
from ..v2.lint import default_validation_tasks, sciml_validation_tasks

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.

Also this, import from ..v2.sciml.lint for example, for separation.

Comment thread petab/v2/core.py
def add_hybridization(self, target_id: str, target_value: str):
"""Add a SciML hybridization table entry to the problem.

If there are more than one hybridization tables, the hybridization

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.

Suggested change
If there are more than one hybridization tables, the hybridization
If there is more than one hybridization table, the hybridization

Comment thread petab/v2/core.py
"""Add a SciML hybridization table entry to the problem.

If there are more than one hybridization tables, the hybridization
is added to the last one.

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.

Suggested change
is added to the last one.
is added to the last table.

Comment thread petab/v2/lint.py
Comment on lines +937 to +945
for mapping in problem.mappings:
# petabEntityId is not referenced in any model
for model in problem.models:
if model.has_entity_with_id(mapping.petab_id):
messages.append(
f"`{mapping.petab_id}` is used in the mapping "
"table and referenced directly in the model "
f"`{model.model_id}`."
)

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.

The spec currently says that the petabEntityId can be the same as a modelEntityId, hence the petabEntityIds can appear in the model, right? @dweindl what do you think?

The petabEntityId may be the same as the modelEntityId, but it must not be used to alias an entity that already has a valid PEtab identifier. This restriction is to avoid unnecessary complexity in the PEtab problem files.

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.

There is some discussion of this here PEtab-dev/PEtab#669

Comment thread petab/v2/lint.py
if culprits := (hyb_target_vals & nn_input_ids):
messages.append(
"The following neural net inputs were used as target values "
f"in the Hybridization tbale: `{culprits}`. Please simplify."

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.

Suggested change
f"in the Hybridization tbale: `{culprits}`. Please simplify."
f"in the Hybridization table: `{culprits}`."

Comment thread petab/v2/lint.py
Comment on lines +1026 to +1032
# Add petab ids from mapping table if they are used for aliasing
for mapping in problem.mappings:
if mapping.model_id and mapping.model_id in parameter_ids.keys():
if mapping.petab_id not in invalid:
parameter_ids[mapping.petab_id] = None
# An aliased model id is not a valid parameter id
if mapping.model_id and mapping.model_id in parameter_ids:
del parameter_ids[mapping.model_id]

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.

As above, I think it's OK to map a model ID to a PEtab ID in the mapping table as long as it's not an alias, i.e. only in the special case where petabEntityId == modelEntityId. I think the reason for this in the spec is for support use of the mapping table for annotation, i.e. via additional user-defined annotation columns.

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.

4 participants